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
This commit is contained in:
commit
e87fcf979f
6 changed files with 119 additions and 44 deletions
28
src/tools/miri/tests/fail/layout_cycle.rs
Normal file
28
src/tools/miri/tests/fail/layout_cycle.rs
Normal file
|
|
@ -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<()>>());
|
||||
}
|
||||
28
src/tools/miri/tests/fail/layout_cycle.stderr
Normal file
28
src/tools/miri/tests/fail/layout_cycle.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue