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

miri fails to apply recursion limit, hits stack overflow instead #2934

Open
matthiaskrgr opened this issue Jun 18, 2023 · 1 comment
Open
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE

Comments

@matthiaskrgr
Copy link
Member

tests/ui/issues/issue-37311-type-length-limit/issue-37311.rs

// build-fail
// normalize-stderr-test: ".nll/" -> "/"
// ignore-compare-mode-next-solver (hangs)

trait Mirror {
    type Image;
}

impl<T> Mirror for T { type Image = T; }

trait Foo {
    fn recurse(&self);
}

impl<T> Foo for T {
    #[allow(unconditional_recursion)]
    fn recurse(&self) {
        (self, self).recurse(); //~ ERROR reached the recursion limit
    }
}

fn main() {
    ().recurse();
}

cargo check or build:

error: reached the recursion limit while instantiating `<(&(&(..., ...), ...), ...) as Foo>::recurse`
  --> src/main.rs:18:9
   |
18 |         (self, self).recurse(); //~ ERROR reached the recursion limit
   |         ^^^^^^^^^^^^^^^^^^^^^^
   |
note: `<T as Foo>::recurse` defined here
  --> src/main.rs:17:5
   |
17 |     fn recurse(&self) {
   |     ^^^^^^^^^^^^^^^^^
   = note: the full type name has been written to '/tmp/im/mri/target/release/deps/mri-6a905e68387b7bf1.long-type.txt'

error: could not compile `mri` (bin "mri") due to previous error

Yet cargo miri run accepts this code and will stack overflow eventually 🤔

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
[1]    378748 IOT instruction  cargo --color=always miri run
@saethlin
Copy link
Member

The recursion looks like this:


#13981 0x00007f6eb527eb02 in <rustc_infer[91c6539b30333cb7]::infer::generalize::Generalizer<rustc_infer[91c6539b30333cb7]::infer::generalize::CombineDelegate> as rustc_middle[419c519ecacfa367]::ty::relate::TypeRelation>::tys ()
   from /home/ben/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-796e47691512e4e9.so
#13982 0x00007f6eb5274dc6 in rustc_middle[419c519ecacfa367]::ty::relate::structurally_relate_tys::<rustc_infer[91c6539b30333cb7]::infer::generalize::Generalizer<rustc_infer[91c6539b30333cb7]::infer::generalize::CombineDelegate>> ()
   from /home/ben/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-796e47691512e4e9.so
#13983 0x00007f6eb527eb02 in <rustc_infer[91c6539b30333cb7]::infer::generalize::Generalizer<rustc_infer[91c6539b30333cb7]::infer::generalize::CombineDelegate> as rustc_middle[419c519ecacfa367]::ty::relate::TypeRelation>::tys ()
   from /home/ben/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-796e47691512e4e9.so

And this is of course hit during interpreting:

#13998 0x00007f6eb5f3cdc1 in <rustc_middle[419c519ecacfa367]::ty::instance::Instance>::resolve ()
   from /home/ben/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_driver-796e47691512e4e9.so
#13999 0x000055555c294acb in rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>::resolve<miri::machine::MiriMachine> (self=<optimized out>, def=..., substs=0x0)
    at /rustc/33c3d101280c8eb3cd8af421bfb56a8afcc3881d/compiler/rustc_const_eval/src/interpret/eval_context.rs:541
#14000 0x000055555c2be1c3 in rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>::eval_terminator<miri::machine::MiriMachine> (self=0x7f6eaabe7840, terminator=0x7f6ea40515a0)
    at /rustc/33c3d101280c8eb3cd8af421bfb56a8afcc3881d/compiler/rustc_const_eval/src/interpret/terminator.rs:87
#14001 rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>::terminator<miri::machine::MiriMachine>
    (self=0x7f6eaabe7840, terminator=0x7f6ea40515a0)
    at /rustc/33c3d101280c8eb3cd8af421bfb56a8afcc3881d/compiler/rustc_const_eval/src/interpret/step.rs:339

(the code between the two chunks of the backtrace is query runtime stuff)

@RalfJung RalfJung added C-bug Category: This is a bug. A-interpreter Area: affects the core interpreter I-ICE Impact: makes Miri crash with some ICE labels Apr 18, 2024
@RalfJung RalfJung changed the title miri misses recursion limit miri fails to apply recursion limit, hits stack overflow instead Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE
Projects
None yet
Development

No branches or pull requests

3 participants