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

pretty/mir: const value enums with no variants #73442

Conversation

davidtwco
Copy link
Member

Fixes #72181.

This PR modifies the pretty printer and const eval in the MIR so that destructure_const (used in pretty_print_const_value) can handle enums with no variants (or types containing enums with no variants).

I'm not convinced that this is the correct approach, folks more familiar with destructure_const would be able to say - happy to adjust the PR. Looking through destructure_const and the functions that it invokes, it didn't seem like it was written to handle zero-variant-enums - I assume that case is handled earlier in some way so destructure_const doesn't need to under normal circumstances. It didn't seem like it would be straightforward to make destructure_const handle this case in a first-class-feeling way (e.g. adding a Variants::None variant), so this PR makes some minimal changes to avoid ICEs.

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2020
@jonas-schievink
Copy link
Contributor

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned eddyb Jun 17, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Jun 18, 2020

I'm not convinced that this is the correct approach, folks more familiar with destructure_const would be able to say - happy to adjust the PR. Looking through destructure_const and the functions that it invokes, it didn't seem like it was written to handle zero-variant-enums - I assume that case is handled earlier in some way so destructure_const doesn't need to under normal circumstances. It didn't seem like it would be straightforward to make destructure_const handle this case in a first-class-feeling way (e.g. adding a Variants::None variant), so this PR makes some minimal changes to avoid ICEs.

The changes from indexing to get, while correct, have one problem: they don't help us catch actually wrong VariantIdxes. There are multiple pre-existing similar situations, and the solution there was (as you also did in one case), to check def.variants.is_empty() first, and if that is true, do the empty enum processing and if it's false, do the regular code.

@davidtwco davidtwco force-pushed the issue-72181-pretty-print-const-val-enum-no-variants branch 2 times, most recently from db77648 to 8ca3c74 Compare June 18, 2020 10:04
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-8 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.
##[section]Starting: Linux x86_64-gnu-llvm-8
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 5'
Agent machine name: 'fv-az578'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200614.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200614.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/39bf4f3d-7436-414a-bd27-d4cbe01ef712.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73442/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[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/73442/merge:refs/remotes/pull/73442/merge
---
 ---> 31fea614d2f3
Step 5/8 : ENV RUST_CONFIGURE_ARGS       --build=x86_64-unknown-linux-gnu       --llvm-root=/usr/lib/llvm-8       --enable-llvm-link-shared       --set rust.thin-lto-import-instr-limit=10
 ---> Using cache
 ---> 4195cadf126d
Step 6/8 : ENV SCRIPT python2.7 ../x.py test --exclude src/tools/tidy &&            python2.7 ../x.py test src/test/mir-opt --pass=build                                   --target=armv5te-unknown-linux-gnueabi &&            python2.7 ../x.py test src/tools/tidy
 ---> 4e90f6b48f05
Step 7/8 : ENV NO_DEBUG_ASSERTIONS=1
 ---> Using cache
 ---> dfa0a356d899
---
   Compiling rustc_parse_format v0.0.0 (/checkout/src/librustc_parse_format)
   Compiling chalk-rust-ir v0.10.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-solve v0.10.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
   Compiling rustc_parse_format v0.0.0 (/checkout/src/librustc_parse_format)
   Compiling chalk-rust-ir v0.10.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-solve v0.10.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
.................................................................................................... 1900/10320
.................................................................................................... 2000/10320
...............i..i................................................................................. 2100/10320
.................................................................................................... 2200/10320
.....iiiii.......................................................................................... 2300/10320
.................................................................................................... 2500/10320
.................................................................................................... 2600/10320
.................................................................................................... 2700/10320
.................................................................................................... 2800/10320
---
.................................................................................................... 6000/10320
.......ii.....................................i..................................................... 6100/10320
.................................................................................................... 6200/10320
.................................................................................................... 6300/10320
......................................................................ii...i..ii...........i........ 6400/10320
.................................................................................................... 6600/10320
.................................................................................................... 6700/10320
.................................................................................................... 6800/10320
.................................................................................................... 6800/10320
....i..ii........................................................................................... 6900/10320
.................................................................................................... 7100/10320
...........................................................i........................................ 7200/10320
.................................................................................................... 7300/10320
.................................................................................................... 7400/10320
---
.................................................................................................... 8200/10320
.................................................................................................... 8300/10320
.................................................................................................... 8400/10320
.i.................................................................................................. 8500/10320
.......................................................iiiiii.iiiiii.i.............................. 8600/10320
............i....................................................................................... 8800/10320
.................................................................................................... 8900/10320
.................................................................................................... 9000/10320
.................................................................................................... 9100/10320
---
---- [mir-opt] mir-opt/issue-72181.rs stdout ----
1 // MIR for `main` 0 mir_map
2 
3 | User Type Annotations
- | 0: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6169 ~ core[2a38]::fmt[0]::{{impl}}[2]::new_v1[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0))], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6167 ~ core[2a38]::fmt[0]::{{impl}}[2]), self_ty: std::fmt::Arguments<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
- | 1: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Ty(General(U0)) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6162 ~ core[2a38]::fmt[0]::{{impl}}[1]::new[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0)), ^1], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6160 ~ core[2a38]::fmt[0]::{{impl}}[1]), self_ty: std::fmt::ArgumentV1<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
- | 2: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6169 ~ core[2a38]::fmt[0]::{{impl}}[2]::new_v1[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0))], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6167 ~ core[2a38]::fmt[0]::{{impl}}[2]), self_ty: std::fmt::Arguments<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
- | 3: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Ty(General(U0)) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6162 ~ core[2a38]::fmt[0]::{{impl}}[1]::new[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0)), ^1], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6160 ~ core[2a38]::fmt[0]::{{impl}}[1]), self_ty: std::fmt::ArgumentV1<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
+ | 0: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6169 ~ core[a39f]::fmt[0]::{{impl}}[2]::new_v1[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0))], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6167 ~ core[a39f]::fmt[0]::{{impl}}[2]), self_ty: std::fmt::Arguments<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
+ | 1: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Ty(General(U0)) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6162 ~ core[a39f]::fmt[0]::{{impl}}[1]::new[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0)), ^1], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6160 ~ core[a39f]::fmt[0]::{{impl}}[1]), self_ty: std::fmt::ArgumentV1<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
+ | 2: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6169 ~ core[a39f]::fmt[0]::{{impl}}[2]::new_v1[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0))], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6167 ~ core[a39f]::fmt[0]::{{impl}}[2]), self_ty: std::fmt::Arguments<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
+ | 3: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Ty(General(U0)) }, CanonicalVarInfo { kind: Region(U0) }], value: TypeOf(DefId(2:6162 ~ core[a39f]::fmt[0]::{{impl}}[1]::new[0]), UserSubsts { substs: [ReLateBound(DebruijnIndex(0), BrAnon(0)), ^1], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:6160 ~ core[a39f]::fmt[0]::{{impl}}[1]), self_ty: std::fmt::ArgumentV1<'_> }) }) } at $SRC_DIR/libstd/macros.rs:LL:COL
9 fn main() -> () {
10     let mut _0: ();                      // return place in scope 0 at $DIR/issue-72181.rs:21:11: 21:11


thread '[mir-opt] mir-opt/issue-72181.rs' panicked at 'Actual MIR output differs from expected MIR output /checkout/src/test/mir-opt/issue-72181/rustc.main.mir_map.0.mir', src/tools/compiletest/src/runtest.rs:3194:25


failures:
    [mir-opt] mir-opt/issue-72181.rs
    [mir-opt] mir-opt/issue-72181.rs

test result: FAILED. 107 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:348:22


command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/mir-opt" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/mir-opt" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "mir-opt" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-8/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "8.0.0" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --exclude src/tools/tidy
Build completed unsuccessfully in 1:06:39
Build completed unsuccessfully in 1:06:39
== clock drift check ==
  local time: Thu Jun 18 11:16:45 UTC 2020
  network time: Thu, 18 Jun 2020 11:16:46 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73442/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73442/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3560) (python)
##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@davidtwco
Copy link
Member Author

I'm not able to reproduce this locally after rebasing on master, any ideas @oli-obk?

@oli-obk
Copy link
Contributor

oli-obk commented Jun 19, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2020

📌 Commit 750efc6e1d60df527f541f01b561747813c4585b has been approved by oli-obk

@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 Jun 19, 2020
@rust-highfive

This comment has been minimized.

This commit modifies the pretty printer and const eval in the MIR so
that `destructure_const` (used in `pretty_print_const_value`) can handle
enums with no variants (or types containing enums with no variants).

Signed-off-by: David Wood <david@davidtw.co>
@davidtwco davidtwco force-pushed the issue-72181-pretty-print-const-val-enum-no-variants branch from 750efc6 to 6fa7dc6 Compare June 19, 2020 13:46
@oli-obk
Copy link
Contributor

oli-obk commented Jun 19, 2020

r=me with CI passing

@davidtwco
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Jun 19, 2020

📌 Commit 6fa7dc6 has been approved by oli-obk

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2020
…arth

Rollup of 16 pull requests

Successful merges:

 - rust-lang#71420 (Specialization is unsound)
 - rust-lang#71899 (Refactor `try_find` a little)
 - rust-lang#72689 (add str to common types)
 - rust-lang#72791 (update coerce docs and unify relevant tests)
 - rust-lang#72934 (forbid mutable references in all constant contexts except for const-fns)
 - rust-lang#73027 (Make `need_type_info_err` more conservative)
 - rust-lang#73347 (Diagnose use of incompatible sanitizers)
 - rust-lang#73359 (shim.rs: avoid creating `Call` terminators calling `Self`)
 - rust-lang#73399 (Clean up E0668 explanation)
 - rust-lang#73436 (Clean up E0670 explanation)
 - rust-lang#73440 (Add src/librustdoc as an alias for src/tools/rustdoc)
 - rust-lang#73442 (pretty/mir: const value enums with no variants)
 - rust-lang#73452 (Unify region variables when projecting associated types)
 - rust-lang#73458 (Use alloc::Layout in DroplessArena API)
 - rust-lang#73484 (Update the doc for std::prelude to the correct behavior)
 - rust-lang#73506 (Bump Rustfmt and RLS)

Failed merges:

r? @ghost
@bors bors merged commit db7203d into rust-lang:master Jun 20, 2020
@davidtwco davidtwco deleted the issue-72181-pretty-print-const-val-enum-no-variants branch June 20, 2020 11:09
Comment on lines +1180 to +1182
ty::Adt(def, substs) if def.variants.is_empty() => {
p!(print_value_path(def.did, substs));
}
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 this should ever be reached? This sort of thing should be an evaluation error, surely?

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 don’t know about an evaluation error, but this definitely gets reached.

Copy link
Contributor

Choose a reason for hiding this comment

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

we use the pretty printer from within the miri engine and the const evaluator does not validate that every local is always valid, only miri does this.

@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: 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.

ICE: index out of bounds: the len is 0 but the index is 0' with --emit mir and mir-opt-level >1
7 participants