-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Do not project to uninhabited variant in JumpThreading
+ const printing + GVN
#120350
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
Do not project to uninhabited variant in JumpThreading
+ const printing + GVN
#120350
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@bors r+ Thank you! |
@bors p=50 |
Why is this so high priority to fix? |
#120337 (comment) |
Well sorry, but the test isn't even accurate. Nightly will have to wait. @bors r- |
dc38470
to
4315b72
Compare
Less confident about the GVN change. cc @cjgillot |
@@ -577,7 +577,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { | |||
return None; | |||
} | |||
} | |||
ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index), | |||
ProjectionElem::Downcast(name, index) => { | |||
if let Some(ct) = self.eval_to_const(value) |
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 bail on the None
case since GVN runs on polymorphic MIR. Is there a better uninhabited method for possibly polymorphic types?
JumpThreading
+ const printingJumpThreading
+ const printing + GVN
@@ -89,6 +89,9 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>( | |||
} | |||
ty::Adt(def, _) => { | |||
let variant = ecx.read_discriminant(&op).ok()?; | |||
if op.layout.for_variant(&ecx, variant).abi.is_uninhabited() { | |||
return None; | |||
} |
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 don't think we should have such checks everywhere. That's too fragile. We should just remove the assertion: #120367.
the assert got removed in #120367 (thank you Ralf!) |
Implements this check: #120347 (comment)
Interestingly, we also had to do this same check in
try_destructure_mir_constant_for_user_output
. I guess it's because we're trying to print an uninhabited variant in the MIR opt output?Fixes #120337
r? oli-obk