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

"Found unstable fingerprints for optimized_mir" ICE when moving a dot in a method call chain between lines within a function with an impl Trait parameter #119353

Open
lmilasius opened this issue Dec 27, 2023 · 2 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lmilasius
Copy link

Related to #84970.

Code

Filename: main.rs

fn main() {
    ice_repro::foo("foo");
}

Filename: lib.rs

pub fn foo(_: impl std::fmt::Display) {
    let _ = "bar".trim().
        trim();
}

At this point run cargo build, which should work fine. Then move the trailing dot in line 2 like this:

Filename: lib.rs

pub fn foo(_: impl std::fmt::Display) {
    let _ = "bar".trim()
        .trim();
}

Now run cargo build and observe the ICE.

Some relevant observations:

  1. Having both functions in main.rs doesn't work; foo() needs to be in lib.rs or in a deeper module. Having both in lib.rs also doesn't work.
  2. The impl Trait parameter is necessary (there's no ICE without it), and any trait seems to work.
  3. The particular methods and types in foo() don't seem to matter; the key is that there's a chain of method calls on separate lines and that a dot is moved from trailing position in line n to leading position in line n + 1 or vice versa.

Meta

rustc --version --verbose:

rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4

Also reproduced on nightly:

rustc 1.77.0-nightly (bf8716f1c 2023-12-24)
binary: rustc
commit-hash: bf8716f1cd6416266807706bcae0ecb2e51c9d4a
commit-date: 2023-12-24
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Error output

Output + backtrace

% cargo build
   Compiling ice-repro v0.1.0 (/home/liudvikas/Code/rust/ice-repro)
error: internal compiler error: encountered incremental compilation error with optimized_mir(ice_repro[ed7c]::foo)
  |
  = help: This is a known issue with the compiler. Run `cargo clean -p ice_repro` or `cargo clean` to allow your project to compile
  = note: Please follow the instructions below to create a bug report with the provided information
  = note: See <https://github.com/rust-lang/rust/issues/84970> for more information

thread 'rustc' panicked at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/compiler/rustc_query_system/src/query/plumbing.rs:711:9:
Found unstable fingerprints for optimized_mir(ice_repro[ed7c]::foo): Body { basic_blocks: BasicBlocks { basic_blocks: [BasicBlockData { statements: [_5 = const "bar"], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 2:25 (#0), scope: scope[0] }, kind: _4 = core::str::<impl str>::trim(_5) -> [return: bb1, unwind: bb4] }), is_cleanup: false }, BasicBlockData { statements: [_3 = _4], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 3:16 (#0), scope: scope[0] }, kind: _2 = core::str::<impl str>::trim(move _3) -> [return: bb2, unwind: bb4] }), is_cleanup: false }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:4:1: 4:2 (#0), scope: scope[0] }, kind: drop(_1) -> [return: bb3, unwind continue] }), is_cleanup: false }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:4:2: 4:2 (#0), scope: scope[0] }, kind: return }), is_cleanup: false }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:4:1: 4:2 (#0), scope: scope[0] }, kind: drop(_1) -> [return: bb5, unwind terminate(cleanup)] }), is_cleanup: true }, BasicBlockData { statements: [], terminator: Some(Terminator { source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:1:1: 4:2 (#0), scope: scope[0] }, kind: resume }), is_cleanup: true }], cache: Cache { predecessors: OnceCell(<uninit>), switch_sources: OnceCell(<uninit>), is_cyclic: OnceCell(<uninit>), reverse_postorder: OnceCell(<uninit>), dominators: OnceCell(<uninit>) } }, phase: Runtime(Optimized), pass_count: 1, source: MirSource { instance: Item(DefId(20:3 ~ ice_repro[ed7c]::foo)), promoted: None }, source_scopes: [SourceScopeData { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:1:1: 4:2 (#0), parent_scope: None, inlined: None, inlined_parent_scope: None, local_data: Clear }, SourceScopeData { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:5: 4:2 (#0), parent_scope: Some(scope[0]), inlined: None, inlined_parent_scope: None, local_data: Clear }], generator: None, local_decls: [LocalDecl { mutability: Mut, local_info: Clear, internal: false, ty: (), user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:1:39: 1:39 (#0), scope: scope[0] } }, LocalDecl { mutability: Mut, local_info: Clear, internal: false, ty: impl std::fmt::Display/#0, user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:1:12: 1:13 (#0), scope: scope[0] } }, LocalDecl { mutability: Mut, local_info: Clear, internal: false, ty: &ReErased str, user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 3:16 (#0), scope: scope[0] } }, LocalDecl { mutability: Mut, local_info: Clear, internal: false, ty: &ReErased str, user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 2:25 (#0), scope: scope[0] } }, LocalDecl { mutability: Not, local_info: Clear, internal: false, ty: &ReErased str, user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 2:25 (#0), scope: scope[0] } }, LocalDecl { mutability: Not, local_info: Clear, internal: false, ty: &ReErased str, user_ty: None, source_info: SourceInfo { span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:2:13: 2:18 (#0), scope: scope[0] } }], user_type_annotations: [], arg_count: 1, spread_arg: None, var_debug_info: [], span: /home/liudvikas/Code/rust/ice-repro/src/lib.rs:1:1: 4:2 (#0), required_consts: [], is_polymorphic: true, injection_phase: None, tainted_by_errors: None }
stack backtrace:
   0:     0x7fada7f6433c - std::backtrace_rs::backtrace::libunwind::trace::ha69d38c49f1bf263
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fada7f6433c - std::backtrace_rs::backtrace::trace_unsynchronized::h93125d0b85fd543c
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fada7f6433c - std::sys_common::backtrace::_print_fmt::h8d65f438e8343444
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fada7f6433c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h41751d2af6c8033a
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fada7fc9f9c - core::fmt::rt::Argument::fmt::h5db2f552d8a28f63
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/fmt/rt.rs:138:9
   5:     0x7fada7fc9f9c - core::fmt::write::h99465148a27e4883
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/fmt/mod.rs:1114:21
   6:     0x7fada7f570be - std::io::Write::write_fmt::hee8dfd57bd179ab2
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/io/mod.rs:1763:15
   7:     0x7fada7f64124 - std::sys_common::backtrace::_print::h019a3cee3e814da4
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fada7f64124 - std::sys_common::backtrace::print::h55694121c2ddf918
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fada7f67003 - std::panicking::default_hook::{{closure}}::h29cbe3da3891b0b0
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:272:22
  10:     0x7fada7f66d24 - std::panicking::default_hook::h881e76b2b8c74280
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:292:9
  11:     0x7fadab11115f - std[afc0969a1e8d0069]::panicking::update_hook::<alloc[8b5739118bbd196f]::boxed::Box<rustc_driver_impl[edf179010582d687]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fada7f67831 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hdafd71b4fdf5de15
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/alloc/src/boxed.rs:2021:9
  13:     0x7fada7f67831 - std::panicking::rust_panic_with_hook::hcc36e25b6e33969c
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:735:13
  14:     0x7fada7f675b1 - std::panicking::begin_panic_handler::{{closure}}::ha415efb0f69f41f9
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:609:13
  15:     0x7fada7f64866 - std::sys_common::backtrace::__rust_end_short_backtrace::h395fe90f99451e4e
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fada7f67302 - rust_begin_unwind
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
  17:     0x7fada7fc6625 - core::panicking::panic_fmt::h452a83e54ecd764e
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
  18:     0x7fadab9db3c8 - rustc_query_system[38ffe91b6b23055d]::query::plumbing::incremental_verify_ich_failed::<rustc_middle[9d619393e8ff4f31]::ty::context::TyCtxt>.2152
  19:     0x7fada9d423da - rustc_query_system[38ffe91b6b23055d]::query::plumbing::try_execute_query::<rustc_query_impl[2832811689f625f6]::DynamicConfig<rustc_query_system[38ffe91b6b23055d]::query::caches::DefaultCache<rustc_span[16fed22730bc75c0]::def_id::DefId, rustc_middle[9d619393e8ff4f31]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2832811689f625f6]::plumbing::QueryCtxt, true>
  20:     0x7fadaaa5d52b - rustc_query_impl[2832811689f625f6]::query_impl::optimized_mir::get_query_incr::__rust_end_short_backtrace
  21:     0x7fada97029c4 - <rustc_middle[9d619393e8ff4f31]::ty::context::TyCtxt>::instance_mir
  22:     0x7fada9ed2522 - rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_used_items
  23:     0x7fada9ecf905 - rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_items_rec
  24:     0x7fada9ecfdf4 - rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_items_rec
  25:     0x7fadaa5e72d8 - rustc_data_structures[96d7b101533d65de]::sync::parallel::disabled::par_for_each_in::<alloc[8b5739118bbd196f]::vec::Vec<rustc_middle[9d619393e8ff4f31]::mir::mono::MonoItem>, rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  26:     0x7fadaa5e6670 - <rustc_session[c6557f37e70f1e4]::session::Session>::time::<(), rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_crate_mono_items::{closure#1}>
  27:     0x7fadaa5e62b8 - rustc_monomorphize[4949fb4b01b29ff1]::collector::collect_crate_mono_items
  28:     0x7fadaa5e4888 - rustc_monomorphize[4949fb4b01b29ff1]::partitioning::collect_and_partition_mono_items
  29:     0x7fadaa6f72d9 - rustc_query_impl[2832811689f625f6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2832811689f625f6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[9d619393e8ff4f31]::query::erase::Erased<[u8; 24usize]>>
  30:     0x7fadaa6f72ad - <rustc_query_impl[2832811689f625f6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[e044522c7ef2d325]::ops::function::FnOnce<(rustc_middle[9d619393e8ff4f31]::ty::context::TyCtxt, ())>>::call_once
  31:     0x7fadaa8e8c3f - rustc_query_system[38ffe91b6b23055d]::query::plumbing::try_execute_query::<rustc_query_impl[2832811689f625f6]::DynamicConfig<rustc_query_system[38ffe91b6b23055d]::query::caches::SingleCache<rustc_middle[9d619393e8ff4f31]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[2832811689f625f6]::plumbing::QueryCtxt, true>
  32:     0x7fadaaa7944b - rustc_query_impl[2832811689f625f6]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  33:     0x7fadaa2927fb - rustc_codegen_ssa[6c532c925ba7d7b6]::base::codegen_crate::<rustc_codegen_llvm[cec41227985bab51]::LlvmCodegenBackend>
  34:     0x7fadaa2925ff - <rustc_codegen_llvm[cec41227985bab51]::LlvmCodegenBackend as rustc_codegen_ssa[6c532c925ba7d7b6]::traits::backend::CodegenBackend>::codegen_crate
  35:     0x7fadaa6532a2 - <rustc_session[c6557f37e70f1e4]::session::Session>::time::<alloc[8b5739118bbd196f]::boxed::Box<dyn core[e044522c7ef2d325]::any::Any>, rustc_interface[250c7deb490bcc66]::passes::start_codegen::{closure#0}>
  36:     0x7fadaa652dfb - rustc_interface[250c7deb490bcc66]::passes::start_codegen
  37:     0x7fadaa64d9ba - <rustc_middle[9d619393e8ff4f31]::ty::context::GlobalCtxt>::enter::<<rustc_interface[250c7deb490bcc66]::queries::Queries>::ongoing_codegen::{closure#0}, core[e044522c7ef2d325]::result::Result<alloc[8b5739118bbd196f]::boxed::Box<dyn core[e044522c7ef2d325]::any::Any>, rustc_span[16fed22730bc75c0]::ErrorGuaranteed>>
  38:     0x7fadaa64c51d - rustc_span[16fed22730bc75c0]::set_source_map::<core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>, rustc_interface[250c7deb490bcc66]::interface::run_compiler<core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>, rustc_driver_impl[edf179010582d687]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  39:     0x7fadaa646750 - std[afc0969a1e8d0069]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[250c7deb490bcc66]::util::run_in_thread_with_globals<rustc_interface[250c7deb490bcc66]::interface::run_compiler<core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>, rustc_driver_impl[edf179010582d687]::run_compiler::{closure#1}>::{closure#0}, core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>>
  40:     0x7fadaa64605e - <<std[afc0969a1e8d0069]::thread::Builder>::spawn_unchecked_<rustc_interface[250c7deb490bcc66]::util::run_in_thread_with_globals<rustc_interface[250c7deb490bcc66]::interface::run_compiler<core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>, rustc_driver_impl[edf179010582d687]::run_compiler::{closure#1}>::{closure#0}, core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e044522c7ef2d325]::result::Result<(), rustc_span[16fed22730bc75c0]::ErrorGuaranteed>>::{closure#1} as core[e044522c7ef2d325]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7fada7f72395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h51435299acd7166e
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/alloc/src/boxed.rs:2007:9
  42:     0x7fada7f72395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3f833c0a4926bdd4
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/alloc/src/boxed.rs:2007:9
  43:     0x7fada7f72395 - std::sys::unix::thread::Thread::new::thread_start::h2c486d0230ab0d99
                               at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/sys/unix/thread.rs:108:17
  44:     0x7fada7d129eb - <unknown>
  45:     0x7fada7d967cc - <unknown>
  46:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.74.1 (a28077b28 2023-12-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `ice_repro::foo`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `ice-repro` (bin "ice-repro") due to previous error

@lmilasius lmilasius added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 27, 2023
@tmiasko tmiasko added A-incr-comp Area: Incremental compilation S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 27, 2023
@Noratrieb
Copy link
Member

Thank you so much for minimizing it!

@cjgillot cjgillot self-assigned this Dec 29, 2023
@Noratrieb
Copy link
Member

I took a small look at it
diffing crudely formatted MIR before and after (the issue is with the binary crate, so I intercepted metadata decoding)

26c26
<             span: /tmp/tmp.QU14zdD0QA/re/src/lib.rs: 2: 13: 3: 15(#0),
---
>             span: /tmp/tmp.QU14zdD0QA/re/src/lib.rs: 2: 13: 3: 16(#0),
163c163
<         span: /tmp/tmp.QU14zdD0QA/re/src/lib.rs: 2: 13: 3: 15(#0),
---
>         span: /tmp/tmp.QU14zdD0QA/re/src/lib.rs: 2: 13: 3: 16(#0),

The thing that's different between the two bodies is the span of a &str local and one of the trim call terminators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants