about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-05-04 00:17:27 +0530
committerGitHub <noreply@github.com>2023-05-04 00:17:27 +0530
commite87fcf979fc5ff36386c642d779f2c071cf30fe8 (patch)
tree10c28bb928677239f9ed65d2ef54785fe39bc51e /src/tools
parent887dffc44795f30c32e8776a9a1850f82da81942 (diff)
parent7bc6d598f94744751a249ed18885592a6f077bcd (diff)
downloadrust-e87fcf979fc5ff36386c642d779f2c071cf30fe8.tar.gz
rust-e87fcf979fc5ff36386c642d779f2c071cf30fe8.zip
Rollup merge of #111097 - oli-obk:🚲_layout, r=compiler-errors
Avoid ICEing miri on layout query cycles

Miri has special logic for catching panics during interpretation. Raising a fatal error in rustc uses unwinding to abort compilation. Thus miri ends up catching that fatal error and thinks it saw an ICE. While we should probably change that to ignore `Fatal` payloads, I think it's also neat to continue compilation after a layout query cycle 😆

Query cycles now (in addition to reporting an error just like before), return `Err(Cycle)` instead of raising a fatal error. This allows the interpreter to wind down via the regular error paths.

r? `@RalfJung` for a first round, feel free to reroll for the compiler team once the miri side looks good
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/tests/fail/layout_cycle.rs28
-rw-r--r--src/tools/miri/tests/fail/layout_cycle.stderr28
2 files changed, 56 insertions, 0 deletions
diff --git a/src/tools/miri/tests/fail/layout_cycle.rs b/src/tools/miri/tests/fail/layout_cycle.rs
new file mode 100644
index 00000000000..d050310bd80
--- /dev/null
+++ b/src/tools/miri/tests/fail/layout_cycle.rs
@@ -0,0 +1,28 @@
+//@error-pattern: a cycle occurred during layout computation
+//~^ ERROR: cycle detected when computing layout of
+
+use std::mem;
+
+pub struct S<T: Tr> {
+    pub f: <T as Tr>::I,
+}
+
+pub trait Tr {
+    type I: Tr;
+}
+
+impl<T: Tr> Tr for S<T> {
+    type I = S<S<T>>;
+}
+
+impl Tr for () {
+    type I = ();
+}
+
+fn foo<T: Tr>() -> usize {
+    mem::size_of::<S<T>>()
+}
+
+fn main() {
+    println!("{}", foo::<S<()>>());
+}
diff --git a/src/tools/miri/tests/fail/layout_cycle.stderr b/src/tools/miri/tests/fail/layout_cycle.stderr
new file mode 100644
index 00000000000..62b7d5fb77d
--- /dev/null
+++ b/src/tools/miri/tests/fail/layout_cycle.stderr
@@ -0,0 +1,28 @@
+error[E0391]: cycle detected when computing layout of `S<S<()>>`
+   |
+   = note: ...which requires computing layout of `<S<()> as Tr>::I`...
+   = note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
+
+error: post-monomorphization error: a cycle occurred during layout computation
+  --> RUSTLIB/core/src/mem/mod.rs:LL:CC
+   |
+LL |     intrinsics::size_of::<T>()
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ a cycle occurred during layout computation
+   |
+   = note: inside `std::mem::size_of::<S<S<()>>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC
+note: inside `foo::<S<()>>`
+  --> $DIR/layout_cycle.rs:LL:CC
+   |
+LL |     mem::size_of::<S<T>>()
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+note: inside `main`
+  --> $DIR/layout_cycle.rs:LL:CC
+   |
+LL |     println!("{}", foo::<S<()>>());
+   |                    ^^^^^^^^^^^^^^
+
+note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0391`.