Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid later diagnostics and ice from typeck for recovered struct variants #127502

Closed

Conversation

chenyukang
Copy link
Member

Fixes #126744
Fixes #126344, a more general fix compared with #127426

r? @oli-obk

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2024

Some changes occurred in compiler/rustc_sanitizers

cc @rust-lang/project-exploit-mitigations, @rcvalle

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 9, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a really invasive change, and there's basically no information about why this needs to be so complicated. Especially because I don't see why we need to change almost 100 files in the compiler to fix two UI tests.

For example, why don't we just fail parsing instead of recovering a struct and tainting all of its fields? I'd rather we not have to handle all of this all the way through type checking, imo.

@@ -81,7 +81,7 @@ impl Attrs {
let krate = loc.parent.lookup(db).container.krate;
let item_tree = loc.id.item_tree(db);
let variant = &item_tree[loc.id.value];
(variant.fields.clone(), item_tree, krate)
(variant.fields().clone(), item_tree, krate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a find-replace mistake? Rust analyzer shouldn't be changed here lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes.


pub fn fields_checked(&self) -> Result<&IndexVec<FieldIdx, FieldDef>, ErrorGuaranteed> {
self.fields.as_ref().map_err(|e| *e)
}
Copy link
Member

@compiler-errors compiler-errors Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we do decide that we should go ahead with this strategy, we should still keep fields as public on VariantDef and expose some other way for hir_typeck to detect that the ADT/Variant has been tainted.

An idea:

  1. Store tainted: Option<ErrorGuaranteed> in the ADT, revert the changes to the fields list
  2. Expose VariantDef::has_errors() -> Result<(), ErrorGuaranteed>
  3. Make the TyCtxt::type_of query return TyKind::Error for ADTs that have recovered.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#12 [ 5/11] RUN npm install es-check@6.1.1 eslint@8.6.0 -g
#12 5.193 npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
#12 5.247 npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
#12 5.253 npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
#12 5.280 npm WARN deprecated @humanwhocodes/config-array@0.9.5: Use @eslint/config-array instead
#12 5.332 npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
#12 5.332 npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
#12 5.339 npm WARN deprecated @humanwhocodes/object-schema@1.2.1: Use @eslint/object-schema instead
#12 6.264 added 205 packages in 6s
#12 6.264 
#12 6.264 20 packages are looking for funding
#12 6.264   run `npm fund` for details
---
#16 6.575 Building wheels for collected packages: reuse
#16 6.576   Building wheel for reuse (pyproject.toml): started
#16 6.905   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 6.906   Created wheel for reuse: filename=reuse-1.1.0-cp310-cp310-manylinux_2_35_x86_64.whl size=181117 sha256=f5f58750481f69515c2c0d1d503daf565e2565c370d07fc6aeb95fe3498b4269
#16 6.906   Stored in directory: /tmp/pip-ephem-wheel-cache-9imwzhw5/wheels/c2/3c/b9/1120c2ab4bd82694f7e6f0537dc5b9a085c13e2c69a8d0c76d
#16 6.909 Installing collected packages: boolean-py, binaryornot, setuptools, reuse, python-debian, markupsafe, license-expression, jinja2, chardet
#16 6.933   Attempting uninstall: setuptools
#16 6.934     Found existing installation: setuptools 59.6.0
#16 6.935     Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr

@chenyukang
Copy link
Member Author

This seems like a really invasive change, and there's basically no information about why this needs to be so complicated. Especially because I don't see why we need to change almost 100 files in the compiler to fix two UI tests.

For example, why don't we just fail parsing instead of recovering a struct and tainting all of its fields? I'd rather we not have to handle all of this all the way through type checking, imo.

yes, maybe we should not recover from this, since the struct fields would be empty, and it's nonsense to continue. I will have a try on this way.

@chenyukang chenyukang closed this Jul 10, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 10, 2024
…ice, r=<try>

Avoid no field error and ice no recovered struct variant

Fixes rust-lang#126744
Fixes rust-lang#126344, a more general fix compared with rust-lang#127426

r? `@oli-obk`

From `@compiler-errors` 's comment rust-lang#127502 (comment)
Seems most of the ADTs don't have taint, so maybe it's not proper to change `TyCtxt::type_of` query.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 11, 2024
…ice, r=compiler-errors

Avoid "no field" error and ICE on recovered ADT variant

Fixes rust-lang#126744
Fixes rust-lang#126344, a more general fix compared with rust-lang#127426

r? `@oli-obk`

From `@compiler-errors` 's comment rust-lang#127502 (comment)
Seems most of the ADTs don't have taint, so maybe it's not proper to change `TyCtxt::type_of` query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
5 participants