Skip to content

no MIR available for DefId #84455

Closed
@MabezDev

Description

@MabezDev

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.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions