Skip to content

[const-prop] Fix ICE calculating enum discriminant - #66960

Merged
bors merged 1 commit into
rust-lang:masterfrom
wesleywiser:fix_66787_take2
Dec 3, 2019
Merged

[const-prop] Fix ICE calculating enum discriminant#66960
bors merged 1 commit into
rust-lang:masterfrom
wesleywiser:fix_66787_take2

Conversation

@wesleywiser

Copy link
Copy Markdown
Member

Fixes#66787

Different approach than #66857

r? @oli-obk
cc @RalfJung@eddyb

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 2, 2019
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
@wesleywiser

Copy link
Copy Markdown
MemberAuthor

I've pushed changes which I believe addresses all of the feedback so far. This is ready for review.

@rust-highfive

This comment has been minimized.

@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 3, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 03460b3d7ecd3ab7ff0d52bf38d6663f5b77f3a6 has been approved by oli-obk

@borsbors 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 Dec 3, 2019
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

Let's fix those typos before landing.

@bors r-

@borsbors 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 Dec 3, 2019
Comment threadsrc/librustc_mir/interpret/place.rs Outdated
Comment on lines 1042 to 1043

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor

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 uninhabited Operandmust'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)

Copy link
Copy Markdown
Contributor

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.

@RalfJung

Copy link
Copy Markdown
Member

@bors r=oli-obk,RalfJung

@bors

bors commented Dec 3, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 0be80f2 has been approved by oli-obk,RalfJung

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 3, 2019
Centril added a commit to Centril/rust that referenced this pull request Dec 3, 2019
…obk,RalfJung
[const-prop] Fix ICE calculating enum discriminant
Fixesrust-lang#66787
Different approach than rust-lang#66857
r? @oli-obk
cc @RalfJung@eddyb
@CentrilCentril mentioned this pull request Dec 3, 2019
Centril added a commit to Centril/rust that referenced this pull request Dec 3, 2019
…obk,RalfJung
[const-prop] Fix ICE calculating enum discriminant
Fixesrust-lang#66787
Different approach than rust-lang#66857
r? @oli-obk
cc @RalfJung@eddyb
@CentrilCentril mentioned this pull request Dec 3, 2019
bors added a commit that referenced this pull request Dec 3, 2019
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
@bors
bors merged commit 0be80f2 into rust-lang:masterDec 3, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Dec 6, 2019
…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
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler panic while building crate with tokio, rocket, and snafu

6 participants

@wesleywiser@rust-highfive@oli-obk@bors@RalfJung@eddyb