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

ICE: broken mir with -Zinline-mir issue-50865-private-impl-trait/auxiliary/lib.rs #78442

Closed
Tracked by #81567
matthiaskrgr opened this issue Oct 27, 2020 · 5 comments · Fixed by #78969, #85254 or #90649
Closed
Tracked by #81567
Assignees
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 27, 2020

Previously: #77668
Now:

Code

// revisions: default miropt
//[miropt]compile-flags: -Z inline-mir
// ~^ This flag is for #77668, it used to be ICE.

#![crate_type = "lib"]

pub fn bar<P>( // Error won't happen if "bar" is not generic
    _baz: P,
) {
    hide_foo()();
}

fn hide_foo() -> impl Fn() { // Error won't happen if "iterate" hasn't impl Trait or has generics
    foo
}

fn foo() { // Error won't happen if "foo" isn't used in "iterate" or has generics
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (20b1e05a8 2020-10-27)
binary: rustc
commit-hash: 20b1e05a8d0e1773dc840a3286aa37916e87d84b
commit-date: 2020-10-27
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

RUST_BACKTRACE=full /home/matthias/.rustup/toolchains/master/bin/rustc ./src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs -Zmir-opt-level=2

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ lib[8787]::bar), const_param_did: None }) (end of phase Optimization) at bb1[1]:
encountered non-callable type impl Fn<()> in `Call` terminator
  --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/ops/function.rs:70:5
   |
70 |     extern "rust-call" fn call(&self, args: Args) -> Self::Output;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_mir/src/transform/validate.rs:160:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:961:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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.49.0-nightly (20b1e05a8 2020-10-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=2

query stack during panic:
end of query stack
Backtrace

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ lib[8787]::bar), const_param_did: None }) (end of phase Optimization) at bb1[1]:
encountered non-callable type impl Fn<()> in `Call` terminator
  --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/ops/function.rs:70:5
   |
70 |     extern "rust-call" fn call(&self, args: Args) -> Self::Output;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_mir/src/transform/validate.rs:160:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:961:13
stack backtrace:
   0:     0x7f33170bab70 - std::backtrace_rs::backtrace::libunwind::trace::h448c56741b6011d3
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:100:5
   1:     0x7f33170bab70 - std::backtrace_rs::backtrace::trace_unsynchronized::h881b9d30a8a89a0c
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f33170bab70 - std::sys_common::backtrace::_print_fmt::h720a2f61f75b9f58
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f33170bab70 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8d62bbfda6d5c836
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f331712aaac - core::fmt::write::h1857a60b204f1b6a
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/core/src/fmt/mod.rs:1076:17
   5:     0x7f33170ac7d2 - std::io::Write::write_fmt::h16a9fe7680ac245c
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/io/mod.rs:1516:15
   6:     0x7f33170bfb25 - std::sys_common::backtrace::_print::h9ba51a6db618de7d
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f33170bfb25 - std::sys_common::backtrace::print::h5f20e41c85e91716
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f33170bfb25 - std::panicking::default_hook::{{closure}}::h8d48653392f3b04c
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:208:50
   9:     0x7f33170bf7c8 - std::panicking::default_hook::hb3948d1f74b6ff4c
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:227:9
  10:     0x7f3317987818 - rustc_driver::report_ice::h1ddbc5609a6e1f37
  11:     0x7f33170c0426 - std::panicking::rust_panic_with_hook::h55d23fef0ad751bc
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:597:17
  12:     0x7f33170bff47 - std::panicking::begin_panic_handler::{{closure}}::h56ae74c6dea6e141
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:499:13
  13:     0x7f33170bb00c - std::sys_common::backtrace::__rust_end_short_backtrace::h3c4721f56689fae4
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f33170bfea9 - rust_begin_unwind
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:495:5
  15:     0x7f33170bfe5b - std::panicking::begin_panic_fmt::h447a9fe10c3ac155
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/panicking.rs:437:5
  16:     0x7f331a997141 - rustc_errors::HandlerInner::flush_delayed::hcdae04493e012a6e
  17:     0x7f331a993b11 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h27a485c12bfd5a8a
  18:     0x7f3317993296 - core::ptr::drop_in_place::hac2c86d61f6a657d
  19:     0x7f3317998286 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h60c965ef9381f1d3
  20:     0x7f3317974c1d - core::ptr::drop_in_place::h11c56312c481deac
  21:     0x7f3317967f3f - rustc_span::with_source_map::h7455fffe3cd153a4
  22:     0x7f331799f851 - scoped_tls::ScopedKey<T>::set::h8ae8151712a551fd
  23:     0x7f33179a9f85 - std::sys_common::backtrace::__rust_begin_short_backtrace::h26de371bc27662fc
  24:     0x7f33179292de - core::ops::function::FnOnce::call_once{{vtable.shim}}::h674a38f3420d24cb
  25:     0x7f33170cf42a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9e7afb7a0a438236
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/alloc/src/boxed.rs:1312:9
  26:     0x7f33170cf42a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h70c646c4271337a1
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/alloc/src/boxed.rs:1312:9
  27:     0x7f33170cf42a - std::sys::unix::thread::Thread::new::thread_start::h35d2b8d36f210d02
                               at /rustc/20b1e05a8d0e1773dc840a3286aa37916e87d84b/library/std/src/sys/unix/thread.rs:89:17
  28:     0x7f3316fce3e9 - start_thread
  29:     0x7f3316eeb293 - __GI___clone
  30:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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.49.0-nightly (20b1e05a8 2020-10-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=2

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr 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 Oct 27, 2020
@camelid camelid added the A-mir-opt Area: MIR optimizations label Oct 28, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 28, 2020
@tmiasko
Copy link
Contributor

tmiasko commented Nov 11, 2020

Inlining exposes a use of unnormalized local in a call terminator (not sure if this is more of an issue with inlining or a validator):

--- mir_dump/lib.bar.004-003.Inline.before.mir
+++ mir_dump/lib.bar.004-003.Inline.after.mir
@@ -1,50 +1,49 @@
 fn bar(_1: P) -> () {
     debug _baz => _1;
     let mut _0: ();
     let _2: ();
     let mut _3: &impl std::ops::Fn<()>;
     let _4: impl std::ops::Fn<()>;
     let mut _5: ();
+    scope 1 (inlined <fn() {foo} as Fn<()>>::call - shim(fn() {foo})) {
+    }


     bb1: {
         _3 = &_4;
         StorageLive(_5);
-        _2 = <impl Fn<()> as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4];
+        _2 = move (*_3)() -> [return: bb5, unwind: bb3];
     }

Note: revision annotation doesn't work in an auxiliary file (so it isn't tested on CI with mir-opt-level=2).

@rustbot modify labels: +A-mir-opt-inlining

@rustbot rustbot added the A-mir-opt-inlining Area: MIR inlining label Nov 11, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
Normalize function type during validation

During inlining, the callee body is normalized and has types revealed,
but some of locals corresponding to the arguments might come from the
caller body which is not. As a result the caller body does not pass
validation without additional normalization.

Closes rust-lang#78442.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
Normalize function type during validation

During inlining, the callee body is normalized and has types revealed,
but some of locals corresponding to the arguments might come from the
caller body which is not. As a result the caller body does not pass
validation without additional normalization.

Closes rust-lang#78442.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 14, 2020
Normalize function type during validation

During inlining, the callee body is normalized and has types revealed,
but some of locals corresponding to the arguments might come from the
caller body which is not. As a result the caller body does not pass
validation without additional normalization.

Closes rust-lang#78442.
@bors bors closed this as completed in 7e0441d Nov 15, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…avidtwco

Revert rust-lang#78969 "Normalize function type during validation"

Closes rust-lang#79066.
Reopens rust-lang#78442.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…avidtwco

Revert rust-lang#78969 "Normalize function type during validation"

Closes rust-lang#79066.
Reopens rust-lang#78442.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…avidtwco

Revert rust-lang#78969 "Normalize function type during validation"

Closes rust-lang#79066.
Reopens rust-lang#78442.
@matthiaskrgr
Copy link
Member Author

This ICEs again because the fix was reverted #79193 (comment)
Can someone reopen please?

@mati865
Copy link
Contributor

mati865 commented Mar 14, 2021

Due to #82736 this new requires -Zmir-opt-level=3 to trigger.

ICE:
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ lib[8787]::bar), const_param_did: None }) (end of phase Optimization) at bb1[1]:
encountered non-callable type impl Fn<()> in `Call` terminator
  --> Projects/rust/src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs:10:5
   |
10 |     hide_foo()();
   |     ^^^^^^^^^^^^
   |
  ::: /home/mateusz/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:70:5
   |
70 |     extern "rust-call" fn call(&self, args: Args) -> Self::Output;
   |     -------------------------------------------------------------- in the inlined copy of this code
   |
   = note: delayed at compiler/rustc_mir/src/transform/validate.rs:120:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1012:13
stack backtrace:
   0:     0x7fa44379f930 - std::backtrace_rs::backtrace::libunwind::trace::hfe3b1cace85e87d8
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7fa44379f930 - std::backtrace_rs::backtrace::trace_unsynchronized::h542330af06479043
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa44379f930 - std::sys_common::backtrace::_print_fmt::h6b88726367858985
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fa44379f930 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcd76ce6b485adbea
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7fa44380dabf - core::fmt::write::h127419eb46f2ecc9
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/core/src/fmt/mod.rs:1092:17
   5:     0x7fa443793a42 - std::io::Write::write_fmt::h0facb64ef2e7f5d8
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/io/mod.rs:1567:15
   6:     0x7fa4437a3675 - std::sys_common::backtrace::_print::h7bf1633ea5421f7b
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7fa4437a3675 - std::sys_common::backtrace::print::h5cc4d09049928ba5
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7fa4437a3675 - std::panicking::default_hook::{{closure}}::h9e84dc005bfc9fc7
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:208:50
   9:     0x7fa4437a31d3 - std::panicking::default_hook::h123278a03b1f796b
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:225:9
  10:     0x7fa443f753fb - rustc_driver::report_ice::h036d06dbb7c2c24c
  11:     0x7fa4437a3de0 - std::panicking::rust_panic_with_hook::h4040631aa6c7bc27
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:595:17
  12:     0x7fa4437a3957 - std::panicking::begin_panic_handler::{{closure}}::h02a17b22ac092d08
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:497:13
  13:     0x7fa44379fdec - std::sys_common::backtrace::__rust_end_short_backtrace::h6063b024443b5852
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7fa4437a38b9 - rust_begin_unwind
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:493:5
  15:     0x7fa44376803b - std::panicking::begin_panic_fmt::h10b51f96d6207ff1
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/panicking.rs:435:5
  16:     0x7fa44668486e - rustc_errors::HandlerInner::flush_delayed::hfd981d840ce2a87f
  17:     0x7fa44668317b - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::hcc27ba916259eda8
  18:     0x7fa445cae396 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hfd8ad55a7830aec9
  19:     0x7fa445cb0a10 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h60fefb93b4088059
  20:     0x7fa445cad56d - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::h18cfca8587e69926
  21:     0x7fa445cacdda - rustc_span::with_source_map::h512fd197bcd2b7c3
  22:     0x7fa445cb1ee3 - scoped_tls::ScopedKey<T>::set::hd407f010a973eb63
  23:     0x7fa445cb33a4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h3c42279179caa5db
  24:     0x7fa445cce765 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hd56f564efc764ea1
  25:     0x7fa4437b3258 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd8ea7ada17dfa868
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/alloc/src/boxed.rs:1546:9
  26:     0x7fa4437b3258 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h91ce3a636c58b978
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/alloc/src/boxed.rs:1546:9
  27:     0x7fa4437b3258 - std::sys::unix::thread::Thread::new::thread_start::h2e193c2e23720fdf
                               at /rustc/acca818928654807ed3bc1ce0e97df118f8716c8/library/std/src/sys/unix/thread.rs:71:17
  28:     0x7fa4436e1609 - start_thread
  29:     0x7fa4435f5293 - clone
  30:                0x0 - <unknown>

error: internal compiler error: unexpected panic

@ghost
Copy link

ghost commented Mar 14, 2021

Due to #82736 this new requires -Zmir-opt-level=3 to trigger.

(FWIW -Zinline-mir can also trigger this: https://godbolt.org/z/GvEb45)

@JohnTitor JohnTitor changed the title ICE: broken mir with -Zmir-opt-level=2 issue-50865-private-impl-trait/auxiliary/lib.rs ICE: broken mir with -Zinline-mir issue-50865-private-impl-trait/auxiliary/lib.rs Mar 16, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 23, 2021
Normalize MIR with RevealAll before optimizations.

Fixes rust-lang#78442
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 24, 2021
Normalize MIR with RevealAll before optimizations.

Fixes rust-lang#78442
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 24, 2021
Normalize MIR with RevealAll before optimizations.

Fixes rust-lang#78442
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 24, 2021
Normalize MIR with RevealAll before optimizations.

Fixes rust-lang#78442
@bors bors closed this as completed in ed08a67 Oct 24, 2021
@Alexendoo
Copy link
Member

#85254 fixes this for -Z mir-opt-level=3 and -Z mir-opt-level=3 -Z inline-mir, but it still ICEs with -Z inline-mir on its own or with mir-opt-level 1/2

cc @cjgillot

@Alexendoo Alexendoo reopened this Nov 1, 2021
@cjgillot cjgillot self-assigned this Nov 6, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 6, 2021
Run reveal_all on MIR when inlining is activated.

Fix logic error in rust-lang#85254 which prevented the pass from running when needed.
Fixes rust-lang#78442
r? `@lcnr`
@bors bors closed this as completed in ec471de Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
9 participants