mgca: Register ConstArgHasType when normalizing projection consts#154853
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
b93677c to
672dfb8
Compare
This comment has been minimized.
This comment has been minimized.
| assoc_term_own_obligations(selcx, obligation, &mut nested); | ||
| Progress { term: term.instantiate(tcx, args), obligations: nested } | ||
| let instantiated_term: Term<'tcx> = term.instantiate(tcx, args); | ||
| if let Some(ct) = instantiated_term.as_const() { |
There was a problem hiding this comment.
Boxy and I discussed the fix approach and settled on registering a nested goal when normalizing type consts to verify that the normalized term has the type of the type const item. However, this implementation applies the same nested goal to all associated consts, not just type consts. This better expresses the invariant that the normalized result of a const should match its declared type (I think only type consts currently go through this path, but this also guards against future changes).
This comment has been minimized.
This comment has been minimized.
672dfb8 to
90e8301
Compare
|
can you add an equivalent test for free type consts, e.g: type const N: usize = "this isn't a usize";
fn f() -> [u8; const { N }] {}actuall;y it seems like this doesn't even ICE on nightly rn 🤔 can you look into why this doesn't ICE but the other stuff does. would like to properly understand why we need this for projections but not free type consts.
the type const has no associated const body. so i think what's happening here is that we normalize everything in a MIR body and then do MIR validation on it afterwards, rather than normalization causing validation to happen 🤔 |
4af1458 to
7dc2ef4
Compare
This comment has been minimized.
This comment has been minimized.
Ah, I didn't consider that. Indeed, in such cases, it seems ICE doesn't occur. IIUC, the key is the ordering of For trait/inherent impl type consts, the impl block's |
This comment has been minimized.
This comment has been minimized.
7dc2ef4 to
c89665d
Compare
This comment has been minimized.
This comment has been minimized.
c89665d to
3d241ce
Compare
oooh okay I think I get it. this test case relies on evaluating the anon const during wfcheck of free items and results in an ICE. does this PR fix this variant: ? //@ compile-flags: -Zvalidate-mir
#![feature(min_generic_const_args)]
type const X: usize = const { N };
type const N: usize = "this isn't a usize"; |
|
wrt your PR description it's a bit wrong right now:
it's not that normalizing a usage of the type const triggers CTFE. rather that when running CTFE on a MIR body we may wind up normalizing a type const in the body, which can change the type of the value causing the MIR to become illformed. can you update the description |
| tcx.const_of_item(alias_term.def_id).instantiate(tcx, args).into() | ||
| }; | ||
|
|
||
| if let Some(ct) = term.as_const() { |
There was a problem hiding this comment.
same for the old solver's normalization routine
|
thanks for working on this ✨ |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
I tested this variant and adding edit: Of course, even if this PR doesn't address such cases, it would be possible for me to handle them later. |
|
@rustbot ready |
e565d65 to
e777ac3
Compare
|
@rustbot ready |
70dc83f to
277dccc
Compare
|
@bors r+ thanks ashley & reddy for the reviews :3 thanks lapla for working on this for so long despite my inconsistent and long review times 😅 |
…const, r=BoxyUwU mgca: Register `ConstArgHasType` when normalizing projection consts Fixes rust-lang#152962 Fixes rust-lang#154748 Fixes rust-lang#154750 When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a `span_bug!`. The existing `ConstArgHasType` check in `wfcheck::check_type_const` does catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run. Fix this by registering a `ConstArgHasType(ct, expected_ty)` obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs. The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see rust-lang#152962 (comment)). r? BoxyUwU
…const, r=BoxyUwU mgca: Register `ConstArgHasType` when normalizing projection consts Fixes rust-lang#152962 Fixes rust-lang#154748 Fixes rust-lang#154750 When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a `span_bug!`. The existing `ConstArgHasType` check in `wfcheck::check_type_const` does catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run. Fix this by registering a `ConstArgHasType(ct, expected_ty)` obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs. The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see rust-lang#152962 (comment)). r? BoxyUwU
…const, r=BoxyUwU mgca: Register `ConstArgHasType` when normalizing projection consts Fixes rust-lang#152962 Fixes rust-lang#154748 Fixes rust-lang#154750 When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a `span_bug!`. The existing `ConstArgHasType` check in `wfcheck::check_type_const` does catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run. Fix this by registering a `ConstArgHasType(ct, expected_ty)` obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs. The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see rust-lang#152962 (comment)). r? BoxyUwU
…const, r=BoxyUwU mgca: Register `ConstArgHasType` when normalizing projection consts Fixes rust-lang#152962 Fixes rust-lang#154748 Fixes rust-lang#154750 When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a `span_bug!`. The existing `ConstArgHasType` check in `wfcheck::check_type_const` does catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run. Fix this by registering a `ConstArgHasType(ct, expected_ty)` obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs. The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see rust-lang#152962 (comment)). r? BoxyUwU
Rollup of 31 pull requests Successful merges: - #141030 (Expand free alias types during variance computation) - #154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - #155527 (Replace printables table with `unicode_data.rs` tables) - #156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - #157282 (Fix post-monomorphization error note race in the parallel frontend) - #157352 (Make the retained dep graph deterministic under the parallel frontend) - #157601 (Emit error for unused target expression in glob and list delegations) - #157611 (Update `browser-ui-test` version to `0.24.0`) - #157620 (Add a strategy FnMut to inject behavior into the flush cycle) - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - #157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - #157647 (Start using comptime for reflection intrinsics and their wrapper functions) - #157719 (resolve: Partially revert "Remove a special case for dummy imports") - #155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - #155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - #155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - #156497 (fix-155516: Don't suggest wrong unwrap expect) - #156583 (Support defaults for static EIIs) - #157013 (Ensure inferred let pattern types are well-formed) - #157196 (Only suggest reborrowing a moved value where the reborrow is valid) - #157230 (borrowck: avoid ICE describing fields on generic params) - #157288 (platform support: add SNaN erratum to MIPS targets) - #157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - #157691 (Move symbol hiding code to a new file) - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - #157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - #157699 (Arg splat experiment - hir FnDecl impl)
Rollup merge of #154853 - lapla-cogito:normlize_projecttion_const, r=BoxyUwU mgca: Register `ConstArgHasType` when normalizing projection consts Fixes #152962 Fixes #154748 Fixes #154750 When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a `span_bug!`. The existing `ConstArgHasType` check in `wfcheck::check_type_const` does catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run. Fix this by registering a `ConstArgHasType(ct, expected_ty)` obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs. The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see #152962 (comment)). r? BoxyUwU
Rollup of 31 pull requests Successful merges: - rust-lang#141030 (Expand free alias types during variance computation) - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables) - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend) - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend) - rust-lang#157601 (Emit error for unused target expression in glob and list delegations) - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`) - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle) - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions) - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports") - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect) - rust-lang#156583 (Support defaults for static EIIs) - rust-lang#157013 (Ensure inferred let pattern types are well-formed) - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid) - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params) - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets) - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - rust-lang#157691 (Move symbol hiding code to a new file) - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
Rollup of 31 pull requests Successful merges: - rust-lang#141030 (Expand free alias types during variance computation) - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables) - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend) - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend) - rust-lang#157601 (Emit error for unused target expression in glob and list delegations) - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`) - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle) - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions) - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports") - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect) - rust-lang#156583 (Support defaults for static EIIs) - rust-lang#157013 (Ensure inferred let pattern types are well-formed) - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid) - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params) - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets) - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - rust-lang#157691 (Move symbol hiding code to a new file) - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
View all comments
Fixes #152962
Fixes #154748
Fixes #154750
When running CTFE on a MIR body, normalizing a type const within that body can change the type of the resulting value, causing the MIR to become ill-formed. Since no prior error has been reported at that point, MIR validation fires a
span_bug!. The existingConstArgHasTypecheck inwfcheck::check_type_constdoes catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run.Fix this by registering a
ConstArgHasType(ct, expected_ty)obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs.The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see #152962 (comment)).
r? BoxyUwU