-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
try to get rid of mir::Const::normalize #130990
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@@ -703,8 +703,7 @@ impl<'tcx> Cx<'tcx> { | |||
tcx, | |||
anon_const.def_id.to_def_id(), | |||
) | |||
.instantiate_identity() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah I just found 82f23d5. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cc @Amanieu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have such a pass for const items, but those are (currently) always monomorphic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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