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

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

Merged
merged 1 commit into from Dec 3, 2019

Conversation

@wesleywiser
Copy link
Member

wesleywiser commented Dec 2, 2019

Fixes #66787

Different approach than #66857

r? @oli-obk
cc @RalfJung @eddyb

@wesleywiser wesleywiser force-pushed the wesleywiser:fix_66787_take2 branch from 6e5138f to 25da0fb Dec 2, 2019
@wesleywiser

This comment has been minimized.

Copy link
Member Author

wesleywiser commented Dec 2, 2019

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

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 3, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-12-02T23:56:49.3410637Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-02T23:56:49.3603957Z ##[command]git config gc.auto 0
2019-12-02T23:56:49.3695024Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-02T23:56:49.3739473Z ##[command]git config --get-all http.proxy
2019-12-02T23:56:50.1537611Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66960/merge:refs/remotes/pull/66960/merge
---
2019-12-03T00:14:01.7985493Z    Compiling rustc_mir v0.0.0 (/checkout/src/librustc_mir)
2019-12-03T00:14:10.5887142Z error[E0282]: type annotations needed
2019-12-03T00:14:10.5888140Z     --> src/librustc_mir/interpret/place.rs:1068:13
2019-12-03T00:14:10.5889180Z      |
2019-12-03T00:14:10.5890045Z 1068 |         let variant_scalar = Scalar::from_u32(variant_index.as_u32()).into();
2019-12-03T00:14:10.5890776Z      |             ^^^^^^^^^^^^^^ consider giving `variant_scalar` a type
2019-12-03T00:14:12.7653976Z error: aborting due to previous error
2019-12-03T00:14:12.7659003Z 
2019-12-03T00:14:12.7665836Z For more information about this error, try `rustc --explain E0282`.
2019-12-03T00:14:12.8465273Z error: could not compile `rustc_mir`.
---
2019-12-03T00:16:13.1053440Z   local time: Tue Dec  3 00:16:13 UTC 2019
2019-12-03T00:16:13.3876274Z   network time: Tue, 03 Dec 2019 00:16:13 GMT
2019-12-03T00:16:13.3876400Z == end clock drift check ==
2019-12-03T00:16:16.1459937Z 
2019-12-03T00:16:16.1584685Z ##[error]Bash exited with code '1'.
2019-12-03T00:16:16.1624346Z ##[section]Starting: Checkout
2019-12-03T00:16:16.1626089Z ==============================================================================
2019-12-03T00:16:16.1626280Z Task         : Get sources
2019-12-03T00:16:16.1626344Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@wesleywiser wesleywiser force-pushed the wesleywiser:fix_66787_take2 branch from 25da0fb to 03460b3 Dec 3, 2019
@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 3, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 3, 2019

📌 Commit 03460b3 has been approved by oli-obk

@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Dec 3, 2019

Let's fix those typos before landing.

@bors r-

@wesleywiser wesleywiser force-pushed the wesleywiser:fix_66787_take2 branch from 03460b3 to 414f84d Dec 3, 2019
// Layout computation excludes uninhabited variants from consideration
// so this checks that the `variant_index` is valid.
Comment on lines 1042 to 1043

This comment has been minimized.

Copy link
@RalfJung

RalfJung Dec 3, 2019

Member

The key point is that there's no alternative: there's no way to represent those variants in the given layout.

This comment has been minimized.

Copy link
@eddyb

eddyb Dec 3, 2019

Member

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 Operand 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)

This comment has been minimized.

Copy link
@eddyb

eddyb Dec 3, 2019

Member

(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.

@wesleywiser wesleywiser force-pushed the wesleywiser:fix_66787_take2 branch from 414f84d to 0be80f2 Dec 3, 2019
@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Dec 3, 2019

@bors r=oli-obk,RalfJung

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 3, 2019

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

Centril added a commit to Centril/rust that referenced this pull request Dec 3, 2019
…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
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`)
 - #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)
 - #66979 (Add long error for E0631 and update ui tests.)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this pull request Dec 3, 2019
…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
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:master Dec 3, 2019
4 checks passed
4 checks passed
pr #20191203.31 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.