Skip to content
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

interpret: project_downcast: do not ICE for uninhabited variants #120367

Merged
merged 2 commits into from Jan 26, 2024

Conversation

RalfJung
Copy link
Member

Fixes #120337

This assertion was already under discussion for a bit; I think the example @tmiasko found is the final nail in the coffin. One could argue maybe MIR building should read the discriminant before projecting, but even then MIR optimizations should be allowed to remove that read, so the downcast should still not ICE. Maybe the downcast should be UB, but in this example UB already arises earlier when a value of type E is constructed.

r? @oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

The Miri subtree was changed

cc @rust-lang/miri

@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 26, 2024
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the project_downcast_uninhabited branch 3 times, most recently from 7799a86 to 70b9165 Compare January 26, 2024 07:58
@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2024

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

@@ -956,8 +956,7 @@ pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
/// element:
///
/// - [`Downcast`](ProjectionElem::Downcast): This projection sets the place's variant index to the
/// given one, and makes no other changes. A `Downcast` projection on a place with its variant
/// index already set is not well-formed.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken the liberty to remove it. I am not even sure what "not well-formed" means. Is it UB or invalid MIR? The MIR validator does not seem to be checking anything like this.

Looks like this was added in dae5c84.
Cc @JakobDegen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait I think this just means the place has to be an enum, not an enum variant.

@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2024

@bors r+ p=10 fixes an ICE that breaks stable code

@bors
Copy link
Contributor

bors commented Jan 26, 2024

📌 Commit 64cd13f 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 26, 2024
// If the field is uninhabited, we can forget the data (can happen in ConstProp).
// `enum S { A(!), B, C }` is an example of an enum with Scalar layout that
// has an `Uninhabited` variant, which means this case is possible.
_ if layout.abi.is_uninhabited() => Immediate::Uninit,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here is a bit unfortunate, but enum layouts are weird...

@bors
Copy link
Contributor

bors commented Jan 26, 2024

⌛ Testing commit 64cd13f with merge cdd4ff8...

@bors
Copy link
Contributor

bors commented Jan 26, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing cdd4ff8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 26, 2024
@bors bors merged commit cdd4ff8 into rust-lang:master Jan 26, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 26, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cdd4ff8): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 663.074s -> 663.841s (0.12%)
Artifact size: 308.14 MiB -> 308.14 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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()
6 participants