-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[const-prop] Fix ICE calculating enum discriminant #66960
Conversation
6e5138f
to
25da0fb
Compare
I've pushed changes which I believe addresses all of the feedback so far. This is ready for review. |
This comment has been minimized.
This comment has been minimized.
25da0fb
to
03460b3
Compare
@bors r+ |
📌 Commit 03460b3d7ecd3ab7ff0d52bf38d6663f5b77f3a6 has been approved by |
Let's fix those typos before landing. @bors r- |
03460b3
to
414f84d
Compare
src/librustc_mir/interpret/place.rs
Outdated
// Layout computation excludes uninhabited variants from consideration | ||
// so this checks that the `variant_index` is valid. |
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.
The key point is that there's no alternative: there's no way to represent those variants in the given layout.
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 feel like there's been a lot of muddying the waters on "variant_index
validity".
It's always valid, it's always in range, it's impossible for it to not be a variant (despite what has been said wrt the comments lower down).
Also, for Multiple
, the variants
vec always includes all variants declared in the enum
.
What needs to be handled here is "the variant is uninhabited" i.e. unrepresented.
This means two things, not just one (another source of confusion):
- there is no tag/niche allocated for it, so the best you could do is write undef over the tag/niche
- fully initializing (which is what
SetDiscriminant
means) an uninhabited variant should never be reachable, as another uninhabitedOperand
must've been evaluated for at least one of the fields, so this should be some sort of error (I think @RalfJung is right that this is technically an "invalid program" situation)
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.
(of course the PR was updated while I was trying to post that comment, heh)
I think the new form of the comment seems fine, but I'd wait until @RalfJung also agrees, to proceed.
414f84d
to
0be80f2
Compare
@bors r=oli-obk,RalfJung |
📌 Commit 0be80f2 has been approved by |
…obk,RalfJung [const-prop] Fix ICE calculating enum discriminant Fixes rust-lang#66787 Different approach than rust-lang#66857 r? @oli-obk cc @RalfJung @eddyb
…obk,RalfJung [const-prop] Fix ICE calculating enum discriminant Fixes rust-lang#66787 Different approach than rust-lang#66857 r? @oli-obk cc @RalfJung @eddyb
Rollup of 7 pull requests Successful merges: - #66750 (Update the `wasi` crate for `wasm32-wasi`) - #66878 (Move Sessions into (new) librustc_session) - #66903 (parse_enum_item -> parse_enum_variant) - #66951 (miri: add throw_machine_stop macro) - #66957 (Change Linker for x86_64-fortanix-unknown-sgx target to rust-lld) - #66960 ([const-prop] Fix ICE calculating enum discriminant) - #66973 (Update the minimum external LLVM to 7) Failed merges: r? @ghost
…le, r=oli-obk codegen "unreachable" for invalid SetDiscriminant Follow-up from rust-lang#66960. I also realized I don't understand our policy for using `abort` vs `unreachable`. AFAIK `abort` is safe to call and just aborts the process, while `unreachable` is UB. But sometimes we use both, like here https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_codegen_ssa/mir/block.rs#L827-L828 and here https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_codegen_ssa/mir/block.rs#L264-L265 The second case is even more confusing because that looks like an unreachable `return` to me, so why would we codegen a safe abort there? r? @eddyb Cc @oli-obk
Fixes #66787
Different approach than #66857
r? @oli-obk
cc @RalfJung @eddyb