Skip to content

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

Conversation

compiler-errors
Copy link
Member

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

@rustbot rustbot added 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. labels Jan 25, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk
Copy link
Contributor

oli-obk commented Jan 25, 2024

@bors r+ Thank you!

@bors
Copy link
Collaborator

bors commented Jan 25, 2024

📌 Commit dc38470 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2024
@matthiaskrgr
Copy link
Member

@bors p=50
maybe we can squeeze this in before nightly :3

@oli-obk
Copy link
Contributor

oli-obk commented Jan 25, 2024

Why is this so high priority to fix?

@matthiaskrgr
Copy link
Member

#120337 (comment)
I suspect that this breaks peoples CIs or crates.

@compiler-errors
Copy link
Member Author

Well sorry, but the test isn't even accurate. Nightly will have to wait.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 25, 2024
@rust-cloud-vms rust-cloud-vms bot force-pushed the const-prop-skip-uninhabited-variant branch from dc38470 to 4315b72 Compare January 25, 2024 21:19
@compiler-errors
Copy link
Member Author

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)
Copy link
Member Author

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?

@compiler-errors compiler-errors changed the title Do not project to uninhabited variant in JumpThreading + const printing Do not project to uninhabited variant in JumpThreading + const printing + GVN Jan 25, 2024
@cjgillot cjgillot self-assigned this Jan 26, 2024
@@ -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;
}
Copy link
Member

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.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2024

the assert got removed in #120367 (thank you Ralf!)

@oli-obk oli-obk closed this Jan 26, 2024
@compiler-errors compiler-errors deleted the const-prop-skip-uninhabited-variant branch January 26, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ice: !layout.abi.is_uninhabited()
8 participants