Skip to content

no MIR available for DefId #84455

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

Closed
MabezDev opened this issue Apr 22, 2021 · 7 comments · Fixed by #84549
Closed

no MIR available for DefId #84455

MabezDev opened this issue Apr 22, 2021 · 7 comments · Fixed by #84549
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MabezDev
Copy link
Contributor

MabezDev commented Apr 22, 2021

I couldn't I couldn't produce a single file example, as it seems the ICE is triggered when cross crate compilation is involved; i.e dumping the contents of lib.rs into test.rs does not trigger the ICE. This seems like a regression of the const-fn feature as this previously worked on nightly of the 1.50 stable release.

Code

lib.rs:

// ice_test
#![no_std]

#![feature(const_fn)]

use core::alloc::{GlobalAlloc, Layout};

pub static DEFAULT_ALLOCATOR: Allocator = Allocator::new(&DEFAULT_HEAP);
static DEFAULT_HEAP: GeneralAllocator = GeneralAllocator::new();

#[derive(Copy, Clone)]
pub struct Allocator {
    allocator: &'static (dyn GlobalAlloc + 'static),
}

unsafe impl Sync for Allocator {}

impl Allocator {
    const fn new(allocator: &'static dyn GlobalAlloc) -> Self {
        Self { allocator }
    }
}

unsafe impl GlobalAlloc for Allocator {
    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
        self.allocator.alloc(layout)
    }
    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
        self.allocator.dealloc(ptr, layout)
    }
}

pub struct GeneralAllocator;

unsafe impl Sync for GeneralAllocator {}

impl GeneralAllocator {
    pub const fn new() -> Self {
        Self {}
    }
}

unsafe impl GlobalAlloc for GeneralAllocator {
    unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
        todo!()
    }

    unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
        todo!()
    }
}

test.rs:

#![feature(alloc_error_handler)]
#![no_std]
#![no_main]

use ice_test::{Allocator, DEFAULT_ALLOCATOR};


extern crate alloc;

#[global_allocator]
pub static GLOBAL_ALLOCATOR: Allocator = DEFAULT_ALLOCATOR;

#[no_mangle]
fn main() {

}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

#[alloc_error_handler]
fn alloc_error_handler(layout: core::alloc::Layout) -> ! {
    panic!(
        "Error allocating  {} bytes of memory with alignment {}",
        layout.size(),
        layout.align()
    );
}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (b84932674 2021-04-21)
binary: rustc
commit-hash: b849326744a8eec939e592f0ab13bff85cc865d3
commit-date: 2021-04-21
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

error: internal compiler error: compiler/rustc_mir/src/monomorphize/collector.rs:865:9: no MIR available for DefId(5:12 ~ ice_test[1249]::DEFAULT_HEAP)

thread 'rustc' panicked at 'Box<Any>', /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/panic.rs:59:5
Backtrace

error: internal compiler error: compiler/rustc_mir/src/monomorphize/collector.rs:865:9: no MIR available for DefId(5:12 ~ ice_test[1249]::DEFAULT_HEAP)

thread 'rustc' panicked at 'Box<Any>', /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/panic.rs:59:5
stack backtrace:
   0:     0x7f8741544320 - std::backtrace_rs::backtrace::libunwind::trace::hdcf4f90f85129e83
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f8741544320 - std::backtrace_rs::backtrace::trace_unsynchronized::h2669e30cb82f6732
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8741544320 - std::sys_common::backtrace::_print_fmt::hfbda19e17f6db318
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f8741544320 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1a8751bf59281272
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f87415b56df - core::fmt::write::h7aa6cd0067dca82a
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/core/src/fmt/mod.rs:1094:17
   5:     0x7f8741538be5 - std::io::Write::write_fmt::hd7dd3a1df9b6befb
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/io/mod.rs:1580:15
   6:     0x7f87415480cb - std::sys_common::backtrace::_print::h551e9ec8a9fa8106
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f87415480cb - std::sys_common::backtrace::print::ha4b1c5e95fa040b3
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f87415480cb - std::panicking::default_hook::{{closure}}::h0b34c9ab7fb9f857
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/panicking.rs:208:50
   9:     0x7f8741547bad - std::panicking::default_hook::h3067e8318decd17a
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/panicking.rs:225:9
  10:     0x7f8741d0a3dd - rustc_driver::report_ice::h0582ed2432eb0d01
  11:     0x7f87415487e0 - std::panicking::rust_panic_with_hook::h81b8facc50f34daa
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/panicking.rs:595:17
  12:     0x7f8742ce53ce - std::panicking::begin_panic::{{closure}}::h85abbcbb712c1987
  13:     0x7f8742ce51a9 - std::sys_common::backtrace::__rust_end_short_backtrace::he1610f0d7a0319c4
  14:     0x7f8742ce5342 - std::panicking::begin_panic::h557498baf405e433
  15:     0x7f8742cd9f00 - std::panic::panic_any::hf715777e4b1eaeed
  16:     0x7f8742cdce4a - rustc_errors::HandlerInner::bug::h00435af82799a5b0
  17:     0x7f8742cdc8f3 - rustc_errors::Handler::bug::hf91cd3a9dd078744
  18:     0x7f8742c261cc - rustc_middle::ty::context::tls::with_opt::heaa8b0ae700b3982
  19:     0x7f8742c2b330 - rustc_middle::util::bug::opt_span_bug_fmt::hda20553eb086ba50
  20:     0x7f8742c2b2a6 - rustc_middle::util::bug::bug_fmt::hf350ebadeac0d8cd
  21:     0x7f87432d0dfb - rustc_mir::monomorphize::collector::should_codegen_locally::h33a6b6ceb32bec5c
  22:     0x7f87432d2a83 - rustc_mir::monomorphize::collector::collect_miri::h2d560ebdca978053
  23:     0x7f87432cc3db - rustc_mir::monomorphize::collector::collect_items_rec::h1931b09524a878fe
  24:     0x7f8743e5d953 - rustc_session::utils::<impl rustc_session::session::Session>::time::h6218e9d62a669ab9
  25:     0x7f8743dc3930 - rustc_mir::monomorphize::collector::collect_crate_mono_items::h87c766f3aedca3f8
  26:     0x7f874341e713 - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h5d71c129de19c17c
  27:     0x7f8743c237e9 - rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::collect_and_partition_mono_items>::compute::hb747675940babce4
  28:     0x7f87423f06e2 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::hae7b015dd63d891e
  29:     0x7f8743cd07b2 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hf8625a52e7db4eba
  30:     0x7f8743c3ec41 - rustc_data_structures::stack::ensure_sufficient_stack::hb05a6df061fa60a4
  31:     0x7f8743bf1e86 - rustc_query_system::query::plumbing::force_query_with_job::hf3efc5c5cbf0708f
  32:     0x7f8743b865e9 - rustc_query_system::query::plumbing::get_query_impl::h015a728ff988d543
  33:     0x7f8743ce31a8 - <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items::he82456e9dcaa8c50
  34:     0x7f87438a6594 - rustc_codegen_ssa::base::codegen_crate::h1bb404e3e428c3d1
  35:     0x7f87438a59a6 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h13bad5012bf8fc9b
  36:     0x7f874383597b - rustc_interface::passes::QueryContext::enter::hbf1d1b59095cc5c2
  37:     0x7f874383f556 - rustc_interface::queries::Queries::ongoing_codegen::h790fc9d1ff2c6880
  38:     0x7f87437fa8d6 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::hedca2acec6ab04da
  39:     0x7f87437f9844 - rustc_span::with_source_map::h67cb68e15a9ffc39
  40:     0x7f87437fb871 - rustc_interface::interface::create_compiler_and_run::he6a465670788f848
  41:     0x7f8743814ff8 - scoped_tls::ScopedKey<T>::set::h8de4c07d6e313e7a
  42:     0x7f8743815513 - std::sys_common::backtrace::__rust_begin_short_backtrace::h953d4096b984a1d5
  43:     0x7f8743818e05 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hf2d8af4e3cccbbb1
  44:     0x7f87415585b7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3aa31cb6360b59d9
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/alloc/src/boxed.rs:1546:9
  45:     0x7f87415585b7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7719d3c7c5841461
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/alloc/src/boxed.rs:1546:9
  46:     0x7f87415585b7 - std::sys::unix::thread::Thread::new::thread_start::hfbe13ead469fd0bc
                               at /rustc/b849326744a8eec939e592f0ab13bff85cc865d3/library/std/src/sys/unix/thread.rs:71:17
  47:     0x7f874147bfde - start_thread
  48:     0x7f87413a242f - clone
  49:                0x0 - <unknown>

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.53.0-nightly (b84932674 2021-04-21) running on x86_64-unknown-linux-gnu

note: compiler flags: -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error

error: could not compile `ice-test`

To learn more, run the command again with --verbose.

@MabezDev MabezDev 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 Apr 22, 2021
@tmiasko
Copy link
Contributor

tmiasko commented Apr 23, 2021

While regression itself is related to the introduction of CTFE MIR, it seems this actually never worked correctly, with DEFAULT_HEAP static ending up duplicated.

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 23, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 28, 2021
@hameerabbasi
Copy link
Contributor

I can't reproduce with the latest nightly and cargo.

$ cargo build --verbose
       Fresh ice_test v0.1.0 (/home/habbasi/bisect/ice_test)
   Compiling bisect v0.1.0 (/home/habbasi/bisect)
     Running `rustc --crate-name bisect --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=dffb54c3af23b7e8 -C extra-filename=-dffb54c3af23b7e8 --out-dir /home/habbasi/bisect/target/debug/deps -C incremental=/home/habbasi/bisect/target/debug/incremental -L dependency=/home/habbasi/bisect/target/debug/deps --extern ice_test=/home/habbasi/bisect/target/debug/deps/libice_test-e9c2aad897dc9d25.rlib`
error: language item required, but not found: `eh_personality`

error: aborting due to previous error

error: could not compile `bisect`

Caused by:
  process didn't exit successfully: `rustc --crate-name bisect --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=dffb54c3af23b7e8 -C extra-filename=-dffb54c3af23b7e8 --out-dir /home/habbasi/bisect/target/debug/deps -C incremental=/home/habbasi/bisect/target/debug/incremental -L dependency=/home/habbasi/bisect/target/debug/deps --extern ice_test=/home/habbasi/bisect/target/debug/deps/libice_test-e9c2aad897dc9d25.rlib` (exit status: 1)

Are there any further instructions for reproducing this?

@MabezDev
Copy link
Contributor Author

I can't reproduce with the latest nightly and cargo.

$ cargo build --verbose
       Fresh ice_test v0.1.0 (/home/habbasi/bisect/ice_test)
   Compiling bisect v0.1.0 (/home/habbasi/bisect)
     Running `rustc --crate-name bisect --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=dffb54c3af23b7e8 -C extra-filename=-dffb54c3af23b7e8 --out-dir /home/habbasi/bisect/target/debug/deps -C incremental=/home/habbasi/bisect/target/debug/incremental -L dependency=/home/habbasi/bisect/target/debug/deps --extern ice_test=/home/habbasi/bisect/target/debug/deps/libice_test-e9c2aad897dc9d25.rlib`
error: language item required, but not found: `eh_personality`

error: aborting due to previous error

error: could not compile `bisect`

Caused by:
  process didn't exit successfully: `rustc --crate-name bisect --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=dffb54c3af23b7e8 -C extra-filename=-dffb54c3af23b7e8 --out-dir /home/habbasi/bisect/target/debug/deps -C incremental=/home/habbasi/bisect/target/debug/incremental -L dependency=/home/habbasi/bisect/target/debug/deps --extern ice_test=/home/habbasi/bisect/target/debug/deps/libice_test-e9c2aad897dc9d25.rlib` (exit status: 1)

Are there any further instructions for reproducing this?

Apologies, forgot to mention you'll need to add

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

Or build for a target that does not have panic unwinding enabled by default.

@bors bors closed this as completed in f8e1e92 May 16, 2021
@pnkfelix pnkfelix self-assigned this Jun 3, 2021
@pnkfelix
Copy link
Member

pnkfelix commented Jun 3, 2021

(discussed in T-compiler meeting. This is an issue on stable, and might get a backport via #84549. Re-opening to investigate details of what worked, what stopped working, what is fixed, and what is still broken.)

@pnkfelix pnkfelix reopened this Jun 3, 2021
@tmiasko
Copy link
Contributor

tmiasko commented Jun 10, 2021

In the case reported here, one crate references DEFAULT_HEAP static from another crate. During mono item collection, should_codegen_locally based on reachability determines whether it will link to item from an upstream crate or codegen it locally. When decision is made to codegen locally, it is followed by an assertion that optimized MIR is available to do so.

In 1.50 static is non-reachable and codegenned locally.
In 1.51 and 1.52 static is non-reachable, but the assertion fails since statics no longer use optimized MIR.
In nightly, since #84549, the static is reachable and linked to.

The change seems safe for backporting to me.

fanninpm added a commit to fanninpm/glacier that referenced this issue Jun 18, 2021
JohnTitor pushed a commit to fanninpm/glacier that referenced this issue Jun 21, 2021
@JohnTitor
Copy link
Member

Closing as the backport was declined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants