-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Do not assert in op_to_const. #117441
Merged
Merged
Do not assert in op_to_const. #117441
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c2f49e9
Do not assert in op_to_const.
cjgillot a2e151c
Make ui into mir-opt test.
cjgillot 3a55c28
Rename hook.
cjgillot 0f8f77f
Rebase fallout.
cjgillot 224e290
Specify diagnostic path.
cjgillot f512f91
Comment `for_diagnostics` flag.
cjgillot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
123 changes: 123 additions & 0 deletions
123
...s/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff
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,123 @@ | ||
- // MIR for `main` before GVN | ||
+ // MIR for `main` after GVN | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: std::alloc::Layout; | ||
let mut _2: std::option::Option<std::alloc::Layout>; | ||
let mut _3: *mut u8; | ||
let mut _4: *mut [u8]; | ||
let mut _5: std::ptr::NonNull<[u8]>; | ||
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>; | ||
let mut _7: &std::alloc::Global; | ||
let mut _8: std::alloc::Layout; | ||
scope 1 { | ||
debug layout => _1; | ||
let mut _9: &std::alloc::Global; | ||
scope 2 { | ||
debug ptr => _3; | ||
} | ||
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) { | ||
debug self => _9; | ||
debug layout => _1; | ||
} | ||
scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) { | ||
debug self => _6; | ||
let mut _12: isize; | ||
let _13: std::alloc::AllocError; | ||
let mut _14: !; | ||
let _15: &str; | ||
let mut _16: &dyn std::fmt::Debug; | ||
let mut _17: &std::alloc::AllocError; | ||
scope 7 { | ||
debug t => _5; | ||
} | ||
scope 8 { | ||
debug e => const std::alloc::AllocError; | ||
} | ||
} | ||
scope 9 (inlined NonNull::<[u8]>::as_ptr) { | ||
debug self => _5; | ||
let mut _18: *const [u8]; | ||
} | ||
} | ||
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) { | ||
debug self => _2; | ||
let mut _10: isize; | ||
let mut _11: !; | ||
scope 4 { | ||
debug val => _1; | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = Option::<Layout>::None; | ||
+ _2 = const Option::<Layout>::None; | ||
StorageLive(_10); | ||
_10 = const 0_isize; | ||
switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable; | ||
} | ||
|
||
bb2: { | ||
unreachable; | ||
} | ||
|
||
bb3: { | ||
- _1 = move ((_2 as Some).0: std::alloc::Layout); | ||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oli-obk this is what we were ICEing on. This is a fancy way of having an uninit byte range in a MIR constant. This bb is unreachable, so this does not matter if we output such degenerate constant. |
||
StorageDead(_10); | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
_9 = const _; | ||
- _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable]; | ||
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb4, unwind unreachable]; | ||
} | ||
|
||
bb4: { | ||
StorageLive(_12); | ||
StorageLive(_15); | ||
_12 = discriminant(_6); | ||
switchInt(move _12) -> [0: bb6, 1: bb5, otherwise: bb2]; | ||
} | ||
|
||
bb5: { | ||
_15 = const "called `Result::unwrap()` on an `Err` value"; | ||
StorageLive(_16); | ||
StorageLive(_17); | ||
_17 = &_13; | ||
_16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize)); | ||
StorageDead(_17); | ||
_14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable; | ||
} | ||
|
||
bb6: { | ||
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>); | ||
StorageDead(_15); | ||
StorageDead(_12); | ||
StorageDead(_6); | ||
StorageLive(_18); | ||
_18 = (_5.0: *const [u8]); | ||
_4 = move _18 as *mut [u8] (PtrToPtr); | ||
StorageDead(_18); | ||
StorageDead(_5); | ||
_3 = move _4 as *mut u8 (PtrToPtr); | ||
StorageDead(_4); | ||
StorageDead(_3); | ||
return; | ||
} | ||
} | ||
+ | ||
+ ALLOC0 (size: 8, align: 4) { | ||
+ 00 00 00 00 __ __ __ __ │ ....░░░░ | ||
+ } | ||
+ | ||
+ ALLOC1 (size: 0, align: 1) {} | ||
|
92 changes: 92 additions & 0 deletions
92
.../mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff
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,92 @@ | ||
- // MIR for `main` before GVN | ||
+ // MIR for `main` after GVN | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: std::alloc::Layout; | ||
let mut _2: std::option::Option<std::alloc::Layout>; | ||
let mut _3: *mut u8; | ||
let mut _4: *mut [u8]; | ||
let mut _5: std::ptr::NonNull<[u8]>; | ||
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>; | ||
let mut _7: &std::alloc::Global; | ||
let mut _8: std::alloc::Layout; | ||
scope 1 { | ||
debug layout => _1; | ||
let mut _9: &std::alloc::Global; | ||
scope 2 { | ||
debug ptr => _3; | ||
} | ||
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) { | ||
debug self => _9; | ||
debug layout => _1; | ||
} | ||
scope 6 (inlined NonNull::<[u8]>::as_ptr) { | ||
debug self => _5; | ||
let mut _12: *const [u8]; | ||
} | ||
} | ||
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) { | ||
debug self => _2; | ||
let mut _10: isize; | ||
let mut _11: !; | ||
scope 4 { | ||
debug val => _1; | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = Option::<Layout>::None; | ||
+ _2 = const Option::<Layout>::None; | ||
StorageLive(_10); | ||
_10 = const 0_isize; | ||
switchInt(const 0_isize) -> [0: bb2, 1: bb4, otherwise: bb3]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_6); | ||
StorageLive(_12); | ||
_12 = (_5.0: *const [u8]); | ||
_4 = move _12 as *mut [u8] (PtrToPtr); | ||
StorageDead(_12); | ||
StorageDead(_5); | ||
_3 = move _4 as *mut u8 (PtrToPtr); | ||
StorageDead(_4); | ||
StorageDead(_3); | ||
return; | ||
} | ||
|
||
bb2: { | ||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue; | ||
} | ||
|
||
bb3: { | ||
unreachable; | ||
} | ||
|
||
bb4: { | ||
- _1 = move ((_2 as Some).0: std::alloc::Layout); | ||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}; | ||
StorageDead(_10); | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
_9 = const _; | ||
- _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb5, unwind continue]; | ||
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb5, unwind continue]; | ||
} | ||
|
||
bb5: { | ||
_5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue]; | ||
} | ||
} | ||
+ | ||
+ ALLOC0 (size: 8, align: 4) { | ||
+ 00 00 00 00 __ __ __ __ │ ....░░░░ | ||
+ } | ||
+ | ||
+ ALLOC1 (size: 0, align: 1) {} | ||
|
123 changes: 123 additions & 0 deletions
123
...s/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff
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,123 @@ | ||
- // MIR for `main` before GVN | ||
+ // MIR for `main` after GVN | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: std::alloc::Layout; | ||
let mut _2: std::option::Option<std::alloc::Layout>; | ||
let mut _3: *mut u8; | ||
let mut _4: *mut [u8]; | ||
let mut _5: std::ptr::NonNull<[u8]>; | ||
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>; | ||
let mut _7: &std::alloc::Global; | ||
let mut _8: std::alloc::Layout; | ||
scope 1 { | ||
debug layout => _1; | ||
let mut _9: &std::alloc::Global; | ||
scope 2 { | ||
debug ptr => _3; | ||
} | ||
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) { | ||
debug self => _9; | ||
debug layout => _1; | ||
} | ||
scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) { | ||
debug self => _6; | ||
let mut _12: isize; | ||
let _13: std::alloc::AllocError; | ||
let mut _14: !; | ||
let _15: &str; | ||
let mut _16: &dyn std::fmt::Debug; | ||
let mut _17: &std::alloc::AllocError; | ||
scope 7 { | ||
debug t => _5; | ||
} | ||
scope 8 { | ||
debug e => const std::alloc::AllocError; | ||
} | ||
} | ||
scope 9 (inlined NonNull::<[u8]>::as_ptr) { | ||
debug self => _5; | ||
let mut _18: *const [u8]; | ||
} | ||
} | ||
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) { | ||
debug self => _2; | ||
let mut _10: isize; | ||
let mut _11: !; | ||
scope 4 { | ||
debug val => _1; | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = Option::<Layout>::None; | ||
+ _2 = const Option::<Layout>::None; | ||
StorageLive(_10); | ||
_10 = const 0_isize; | ||
switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable; | ||
} | ||
|
||
bb2: { | ||
unreachable; | ||
} | ||
|
||
bb3: { | ||
- _1 = move ((_2 as Some).0: std::alloc::Layout); | ||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}; | ||
StorageDead(_10); | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
_9 = const _; | ||
- _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable]; | ||
+ _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb4, unwind unreachable]; | ||
} | ||
|
||
bb4: { | ||
StorageLive(_12); | ||
StorageLive(_15); | ||
_12 = discriminant(_6); | ||
switchInt(move _12) -> [0: bb6, 1: bb5, otherwise: bb2]; | ||
} | ||
|
||
bb5: { | ||
_15 = const "called `Result::unwrap()` on an `Err` value"; | ||
StorageLive(_16); | ||
StorageLive(_17); | ||
_17 = &_13; | ||
_16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize)); | ||
StorageDead(_17); | ||
_14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable; | ||
} | ||
|
||
bb6: { | ||
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>); | ||
StorageDead(_15); | ||
StorageDead(_12); | ||
StorageDead(_6); | ||
StorageLive(_18); | ||
_18 = (_5.0: *const [u8]); | ||
_4 = move _18 as *mut [u8] (PtrToPtr); | ||
StorageDead(_18); | ||
StorageDead(_5); | ||
_3 = move _4 as *mut u8 (PtrToPtr); | ||
StorageDead(_4); | ||
StorageDead(_3); | ||
return; | ||
} | ||
} | ||
+ | ||
+ ALLOC0 (size: 16, align: 8) { | ||
+ 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░ | ||
+ } | ||
+ | ||
+ ALLOC1 (size: 0, align: 1) {} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is "catching" an interpreter error, and this codepath is used for regular consts, not just for diagnostics. That's fragile, I don't think we should do this.
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.
IIUC, this code path is mostly an optimization. Nothing would break if we were to set
force_as_immediate
as false: we do not need to represent scalars as aConstValue::Scalar
, it's just more efficient.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.
That's wrong; many parts of the compiler rely on
try_to_scalar
to work for integer types, and will ICE if we don't use the "immediate" code path here.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.
There's a comment just a few lines above explaining that:
Please suggest how we could word that more clearly to avoid such misunderstandings in the future.