try to get rid of mir::Const::normalize#130990
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
| tcx, | ||
| anon_const.def_id.to_def_id(), | ||
| ) | ||
| .instantiate_identity() |
There was a problem hiding this comment.
This will break tests/ui/asm/const-error.rs, for the record.
I don't care, though, and I also think we should not be obligated to eagerly raise an error for that test, because it's inconsistent with other and only works b/c the const isn't TooGeneric.
//@ only-x86_64
//@ needs-asm-support
// Test to make sure that we emit const errors eagerly for inline asm
use std::arch::asm;
fn test<T>() {
unsafe {
asm!("/* {} */", const 1 / 0);
//~^ ERROR evaluation of
}
}
fn main() {}
There was a problem hiding this comment.
c.f.
//@ only-x86_64
//@ needs-asm-support
// Test to make sure that we emit const errors eagerly for inline asm
use std::arch::asm;
fn test<T>() {
unsafe {
asm!("/* {} */", const 1 / std::mem::size_of::<T>());
}
}
Which obviously only fails if we mono something like test::<Zst>().
There was a problem hiding this comment.
We don't emit const errors eagerly for inline const blocks. So if inline asm behave like those (inheriting the generics from the surrounding function), IMO we should not error eagerly for them either.
There was a problem hiding this comment.
So right, this brings up a bigger question of "should we try to eagerly eval possibly unreachable but otherwise monomorphic consts"?
From a technical perspective, this seems like something that could be done by a MIR pass if we wanted to do so, though, which calls const_eval_resolve on all unevaluated mir::Const::Unevaluated and swallows any TooGeneric, rather than doing it ad-hoc and within mir build just for these consts.
There was a problem hiding this comment.
We do have such a pass for const items, but those are (currently) always monomorphic.
There was a problem hiding this comment.
I have adjusted the test, which should make this PR ready to land.
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#123932 (restate GlobalAlloc method safety preconditions in terms of what the caller has to do for greater clarity) - rust-lang#129003 (Improve Ord docs) - rust-lang#130972 (stabilize const_cell_into_inner) - rust-lang#130990 (try to get rid of mir::Const::normalize) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130990 - RalfJung:mir-const-normalize, r=compiler-errors try to get rid of mir::Const::normalize It was easy to make this compile, let's see if anything breaks... r? `@compiler-errors`
It was easy to make this compile, let's see if anything breaks...
r? @compiler-errors