rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.6k stars 12.48k forks source link

Encountering the type length limit ICEs Miri #127699

Open saethlin opened 1 month ago

saethlin commented 1 month ago

The following program ICEs Miri:

#![type_length_limit = "8"]
fn main() {}

Miri reports:

Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
note: the place in the program where the ICE was triggered
   --> /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:140:5
    |
140 |     panic::catch_unwind(move || unsafe { init(argc, argv, sigpipe) }).map_err(rt_abort)?;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: BACKTRACE:
    = note: inside `std::rt::lang_start_internal` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:140:5: 140:70
    = note: inside `std::rt::lang_start::<()>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:158:17: 163:6

error: internal compiler error: src/tools/miri/src/diagnostics.rs:324:17: This error should be impossible in Miri: encountered overly generic constant

thread 'rustc' panicked at src/tools/miri/src/diagnostics.rs:324:17:
<backtrace to Miri's error reporting code, not relevant>

I'm filing this here because I'm pretty sure the problem is that the core interpreter logic does not handle the new failure path out of Instance::try_resolve correctly.

rustc 1.81.0-nightly (c6727fc9b 2024-07-12)
binary: rustc
commit-hash: c6727fc9b5c64cefa7263486497ee95e529bd0f8
commit-date: 2024-07-12
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7
RalfJung commented 1 month ago

Seems like this leads to a TooGeneric?

error: internal compiler error: src/tools/miri/src/diagnostics.rs:324:17: This error should be impossible in Miri: encountered overly generic constant

Miri bails out on TooGeneric since it knows everything is monomorphized. (codegen does the same.) Does the type length limit cause TooGeneric errors? That would IMO be a wrong use of that error code, precisely because we have users that know that things are not generic any more so we should be able to distinguish errors they can see (like this type length limit) and errors they cannot see (like failing to compute the layout of a type due to generics).