-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #73442 - davidtwco:issue-72181-pretty-print-const-val…
…-enum-no-variants, r=oli-obk pretty/mir: const value enums with no variants 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.
- Loading branch information
Showing
21 changed files
with
654 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// compile-flags: -Z mir-opt-level=1 | ||
// Regression test for #72181, this ICE requires `-Z mir-opt-level=1` flags. | ||
|
||
#![feature(never_type)] | ||
#![allow(unused, invalid_value)] | ||
|
||
enum Void {} | ||
|
||
// EMIT_MIR rustc.f.mir_map.0.mir | ||
fn f(v: Void) -> ! { | ||
match v {} | ||
} | ||
|
||
// EMIT_MIR rustc.main.mir_map.0.mir | ||
fn main() { | ||
let v: Void = unsafe { | ||
std::mem::transmute::<(), Void>(()) | ||
}; | ||
|
||
f(v); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// MIR for `f` 0 mir_map | ||
|
||
fn f(_1: Void) -> ! { | ||
debug v => _1; // in scope 0 at $DIR/issue-72181-1.rs:10:6: 10:7 | ||
let mut _0: !; // return place in scope 0 at $DIR/issue-72181-1.rs:10:18: 10:19 | ||
let mut _2: !; // in scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
let mut _3: !; // in scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
StorageLive(_3); // scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
FakeRead(ForMatchedPlace, _1); // scope 0 at $DIR/issue-72181-1.rs:11:11: 11:12 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:11:11: 11:12 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181-1.rs:10:1: 12:2 | ||
} | ||
|
||
bb2: { | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
} | ||
|
||
bb3: { | ||
StorageDead(_3); // scope 0 at $DIR/issue-72181-1.rs:11:14: 11:15 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
} | ||
|
||
bb4: { | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181-1.rs:12:1: 12:2 | ||
goto -> bb5; // scope 0 at $DIR/issue-72181-1.rs:12:2: 12:2 | ||
} | ||
|
||
bb5: { | ||
return; // scope 0 at $DIR/issue-72181-1.rs:12:2: 12:2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// MIR for `main` 0 mir_map | ||
|
||
| User Type Annotations | ||
| 0: Canonical { max_universe: U0, variables: [], value: Ty(Void) } at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
| 1: Canonical { max_universe: U0, variables: [], value: Ty(Void) } at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
| | ||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/issue-72181-1.rs:15:11: 15:11 | ||
let mut _1: !; // in scope 0 at $DIR/issue-72181-1.rs:15:11: 21:2 | ||
let _2: Void as UserTypeProjection { base: UserType(0), projs: [] }; // in scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
let mut _3: (); // in scope 0 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
let _4: !; // in scope 0 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
let mut _5: Void; // in scope 0 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
scope 1 { | ||
debug v => _2; // in scope 1 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
StorageLive(_3); // scope 2 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
_3 = (); // scope 2 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
_2 = const std::intrinsics::transmute::<(), Void>(move _3) -> [return: bb2, unwind: bb1]; // scope 2 at $DIR/issue-72181-1.rs:17:9: 17:44 | ||
// ty::Const | ||
// + ty: unsafe extern "rust-intrinsic" fn(()) -> Void {std::intrinsics::transmute::<(), Void>} | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181-1.rs:17:9: 17:40 | ||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(()) -> Void {std::intrinsics::transmute::<(), Void>}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181-1.rs:15:1: 21:2 | ||
} | ||
|
||
bb2: { | ||
StorageDead(_3); // scope 2 at $DIR/issue-72181-1.rs:17:43: 17:44 | ||
FakeRead(ForLet, _2); // scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
AscribeUserType(_2, o, UserTypeProjection { base: UserType(1), projs: [] }); // scope 0 at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
StorageLive(_4); // scope 1 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
StorageLive(_5); // scope 1 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
_5 = move _2; // scope 1 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
const f(move _5) -> bb1; // scope 1 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
// ty::Const | ||
// + ty: fn(Void) -> ! {f} | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181-1.rs:20:5: 20:6 | ||
// + literal: Const { ty: fn(Void) -> ! {f}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb3: { | ||
StorageDead(_5); // scope 1 at $DIR/issue-72181-1.rs:20:8: 20:9 | ||
StorageDead(_4); // scope 1 at $DIR/issue-72181-1.rs:20:9: 20:10 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181-1.rs:21:1: 21:2 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:15:11: 21:2 | ||
} | ||
|
||
bb4: { | ||
goto -> bb5; // scope 0 at $DIR/issue-72181-1.rs:21:2: 21:2 | ||
} | ||
|
||
bb5: { | ||
return; // scope 0 at $DIR/issue-72181-1.rs:21:2: 21:2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// compile-flags: -Z mir-opt-level=1 | ||
// Regression test for #72181, this ICE requires `-Z mir-opt-level=1` flags. | ||
|
||
use std::mem; | ||
|
||
#[derive(Copy, Clone)] | ||
enum Never {} | ||
|
||
union Foo { | ||
a: u64, | ||
b: Never | ||
} | ||
|
||
// EMIT_MIR_FOR_EACH_BIT_WIDTH | ||
// EMIT_MIR rustc.foo.mir_map.0.mir | ||
fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 } | ||
|
||
// EMIT_MIR rustc.bar.mir_map.0.mir | ||
fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x } | ||
|
||
// EMIT_MIR_FOR_EACH_BIT_WIDTH | ||
// EMIT_MIR rustc.main.mir_map.0.mir | ||
fn main() { | ||
let _ = mem::size_of::<Foo>(); | ||
|
||
let f = [Foo { a: 42 }, Foo { a: 10 }]; | ||
let _ = unsafe { f[0].a }; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/mir-opt/issue-72181/32bit/rustc.bar.mir_map.0.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// MIR for `bar` 0 mir_map | ||
|
||
fn bar(_1: [(Never, u32); 1]) -> u32 { | ||
let mut _0: u32; // return place in scope 0 at $DIR/issue-72181.rs:19:40: 19:43 | ||
let _2: u32; // in scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/issue-72181.rs:19:13: 19:14 | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
_2 = (_1[0 of 1].1: u32); // scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
_0 = _2; // scope 1 at $DIR/issue-72181.rs:19:46: 19:47 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181.rs:19:48: 19:49 | ||
goto -> bb2; // scope 0 at $DIR/issue-72181.rs:19:49: 19:49 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181.rs:19:1: 19:49 | ||
} | ||
|
||
bb2: { | ||
return; // scope 0 at $DIR/issue-72181.rs:19:49: 19:49 | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/mir-opt/issue-72181/32bit/rustc.foo.mir_map.0.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// MIR for `foo` 0 mir_map | ||
|
||
fn foo(_1: [(Never, u32); 1]) -> u32 { | ||
debug xs => _1; // in scope 0 at $DIR/issue-72181.rs:16:8: 16:10 | ||
let mut _0: u32; // return place in scope 0 at $DIR/issue-72181.rs:16:34: 16:37 | ||
let _2: usize; // in scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
let mut _3: usize; // in scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
let mut _4: bool; // in scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
_2 = const 0usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
// ty::Const | ||
// + ty: usize | ||
// + val: Value(Scalar(0x00000000)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181.rs:16:43: 16:44 | ||
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) } | ||
_3 = Len(_1); // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
_4 = Lt(_2, _3); // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
assert(move _4, "index out of bounds: the len is {} but the index is {}", move _3, _2) -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181.rs:16:1: 16:49 | ||
} | ||
|
||
bb2: { | ||
_0 = (_1[_2].1: u32); // scope 0 at $DIR/issue-72181.rs:16:40: 16:47 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181.rs:16:48: 16:49 | ||
goto -> bb3; // scope 0 at $DIR/issue-72181.rs:16:49: 16:49 | ||
} | ||
|
||
bb3: { | ||
return; // scope 0 at $DIR/issue-72181.rs:16:49: 16:49 | ||
} | ||
} |
Oops, something went wrong.