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: "no MIR available for DefId(...)" #97708

Closed
jamesmunns opened this issue Jun 3, 2022 · 11 comments · Fixed by #97716
Closed

ICE: "no MIR available for DefId(...)" #97708

jamesmunns opened this issue Jun 3, 2022 · 11 comments · Fixed by #97716
Assignees
Labels
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.

Comments

@jamesmunns
Copy link
Member

jamesmunns commented Jun 3, 2022

Code

Github: https://github.com/jamesmunns/pellegrino/tree/ice-2022-06-03/oaiu/melpomene

Repro:

git clone https://github.com/jamesmunns/pellegrino.git
cd pellegrino
git checkout ice-2022-06-03
cd oaiu/melpomene
cargo run

Meta

Reproduces in:

  • Stable Linux - rustc 1.61.0 (fe5b13d 2022-05-18)
  • Nightly Linux - rustc 1.63.0-nightly (e714405 2022-06-02)

Error output

   Compiling mnemos-std v0.1.0 (/home/james/hardware-v6/pellegrino/oaiu/mstd)
error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:969:9: no MIR available for DefId(18:254 ~ maitake[bea2]::task::nop)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1279:9
stack backtrace:
   0:     0x7f44e269e1cd - std::backtrace_rs::backtrace::libunwind::trace::h22893a5306c091b4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f44e269e1cd - std::backtrace_rs::backtrace::trace_unsynchronized::h29c3bc6f9e91819d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f44e269e1cd - std::sys_common::backtrace::_print_fmt::he497d8a0ec903793
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f44e269e1cd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9c2a9d2774d81873
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f44e26f801c - core::fmt::write::hba4337c43d992f49
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/fmt/mod.rs:1194:17
   5:     0x7f44e268f7c1 - std::io::Write::write_fmt::heb73de6e02cfabed
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/io/mod.rs:1655:15
   6:     0x7f44e26a12b5 - std::sys_common::backtrace::_print::h63c8b24acdd8e8ce
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f44e26a12b5 - std::sys_common::backtrace::print::h426700d6240cdcc2
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f44e26a12b5 - std::panicking::default_hook::{{closure}}::hc9a76eed0b18f82b
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:295:22
   9:     0x7f44e26a0f69 - std::panicking::default_hook::h2e88d02087fae196
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:314:9
  10:     0x7f44e2ead1d1 - rustc_driver[413d55b6344850e3]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f44e26a1a00 - std::panicking::rust_panic_with_hook::habfdcc2e90f9fd4c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:702:17
  12:     0x7f44e3f7d141 - std[3b302b3c9093c22]::panicking::begin_panic::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>::{closure#0}
  13:     0x7f44e3f7ce96 - std[3b302b3c9093c22]::sys_common::backtrace::__rust_end_short_backtrace::<std[3b302b3c9093c22]::panicking::begin_panic<rustc_errors[a7dbbf867eaca825]::ExplicitBug>::{closure#0}, !>
  14:     0x7f44e3f84406 - std[3b302b3c9093c22]::panicking::begin_panic::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>
  15:     0x7f44e3f90ec6 - std[3b302b3c9093c22]::panic::panic_any::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>
  16:     0x7f44e3f92673 - <rustc_errors[a7dbbf867eaca825]::HandlerInner>::bug
  17:     0x7f44e3f920d0 - <rustc_errors[a7dbbf867eaca825]::Handler>::bug
  18:     0x7f44e3ed1636 - rustc_middle[9ca07169fec39ed9]::ty::context::tls::with_opt::<rustc_middle[9ca07169fec39ed9]::util::bug::opt_span_bug_fmt<rustc_span[7238ca7210ca999e]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f44e3ed4746 - rustc_middle[9ca07169fec39ed9]::util::bug::opt_span_bug_fmt::<rustc_span[7238ca7210ca999e]::span_encoding::Span>
  20:     0x7f44e3ed46c3 - rustc_middle[9ca07169fec39ed9]::util::bug::bug_fmt
  21:     0x7f44e4f3c3e1 - rustc_monomorphize[aced05821cf249c6]::collector::should_codegen_locally
  22:     0x7f44e419f383 - rustc_monomorphize[aced05821cf249c6]::collector::collect_miri
  23:     0x7f44e419f27f - rustc_monomorphize[aced05821cf249c6]::collector::collect_miri
  24:     0x7f44e419ae21 - rustc_monomorphize[aced05821cf249c6]::collector::collect_items_rec
  25:     0x7f44e4f4a38b - <rustc_session[8df92abe178df33c]::session::Session>::time::<(), rustc_monomorphize[aced05821cf249c6]::collector::collect_crate_mono_items::{closure#1}>
  26:     0x7f44e4f3af56 - rustc_monomorphize[aced05821cf249c6]::collector::collect_crate_mono_items
  27:     0x7f44e4f41086 - rustc_monomorphize[aced05821cf249c6]::partitioning::collect_and_partition_mono_items
  28:     0x7f44e53369f4 - <rustc_query_system[ac245aac4c1950a0]::dep_graph::graph::DepGraph<rustc_middle[9ca07169fec39ed9]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[9ca07169fec39ed9]::ty::context::TyCtxt, (), (&std[3b302b3c9093c22]::collections::hash::set::HashSet<rustc_span[7238ca7210ca999e]::def_id::DefId, core[a3420257622cd381]::hash::BuildHasherDefault<rustc_hash[27b9c0adda3a04af]::FxHasher>>, &[rustc_middle[9ca07169fec39ed9]::mir::mono::CodegenUnit])>
  29:     0x7f44e527f571 - rustc_query_system[ac245aac4c1950a0]::query::plumbing::try_execute_query::<rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt, rustc_query_system[ac245aac4c1950a0]::query::caches::DefaultCache<(), (&std[3b302b3c9093c22]::collections::hash::set::HashSet<rustc_span[7238ca7210ca999e]::def_id::DefId, core[a3420257622cd381]::hash::BuildHasherDefault<rustc_hash[27b9c0adda3a04af]::FxHasher>>, &[rustc_middle[9ca07169fec39ed9]::mir::mono::CodegenUnit])>>
  30:     0x7f44e52b5e65 - rustc_query_system[ac245aac4c1950a0]::query::plumbing::get_query::<rustc_query_impl[b0f4194b24b225ee]::queries::collect_and_partition_mono_items, rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt>
  31:     0x7f44e5373932 - <rustc_query_impl[b0f4194b24b225ee]::Queries as rustc_middle[9ca07169fec39ed9]::ty::query::QueryEngine>::collect_and_partition_mono_items
  32:     0x7f44e48cad1c - rustc_codegen_ssa[1019aa072f95d074]::back::symbol_export::exported_symbols_provider_local
  33:     0x7f44e532d450 - <rustc_query_system[ac245aac4c1950a0]::dep_graph::graph::DepGraph<rustc_middle[9ca07169fec39ed9]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[9ca07169fec39ed9]::ty::context::TyCtxt, rustc_span[7238ca7210ca999e]::def_id::CrateNum, &[(rustc_middle[9ca07169fec39ed9]::middle::exported_symbols::ExportedSymbol, rustc_middle[9ca07169fec39ed9]::middle::exported_symbols::SymbolExportLevel)]>
  34:     0x7f44e526784f - rustc_query_system[ac245aac4c1950a0]::query::plumbing::try_execute_query::<rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt, rustc_query_system[ac245aac4c1950a0]::query::caches::DefaultCache<rustc_span[7238ca7210ca999e]::def_id::CrateNum, &[(rustc_middle[9ca07169fec39ed9]::middle::exported_symbols::ExportedSymbol, rustc_middle[9ca07169fec39ed9]::middle::exported_symbols::SymbolExportLevel)]>>
  35:     0x7f44e52a570c - rustc_query_system[ac245aac4c1950a0]::query::plumbing::get_query::<rustc_query_impl[b0f4194b24b225ee]::queries::exported_symbols, rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt>
  36:     0x7f44e48e89c7 - <rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::EncodeContext>::encode_crate_root
  37:     0x7f44e53f9d54 - rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::encode_metadata_impl
  38:     0x7f44e5426f21 - rustc_data_structures[29dbb8437998f908]::sync::join::<rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::EncodedMetadata, ()>
  39:     0x7f44e53f9493 - rustc_metadata[f7fa52a7d33da9c1]::rmeta::encoder::encode_metadata
  40:     0x7f44e4dae673 - <rustc_interface[550884b2b179878f]::passes::QueryContext>::enter::<<rustc_interface[550884b2b179878f]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[a3420257622cd381]::result::Result<alloc[59b4cdf2bf51ef42]::boxed::Box<dyn core[a3420257622cd381]::any::Any>, rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  41:     0x7f44e4ddb48f - <rustc_interface[550884b2b179878f]::queries::Queries>::ongoing_codegen
  42:     0x7f44e4d8fa8b - <rustc_interface[550884b2b179878f]::interface::Compiler>::enter::<rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}::{closure#2}, core[a3420257622cd381]::result::Result<core[a3420257622cd381]::option::Option<rustc_interface[550884b2b179878f]::queries::Linker>, rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  43:     0x7f44e4d7503f - rustc_span[7238ca7210ca999e]::with_source_map::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_interface[550884b2b179878f]::interface::create_compiler_and_run<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#1}>
  44:     0x7f44e4d910a4 - rustc_interface[550884b2b179878f]::interface::create_compiler_and_run::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>
  45:     0x7f44e4d737c2 - <scoped_tls[7ed3ce20ede545d8]::ScopedKey<rustc_span[7238ca7210ca999e]::SessionGlobals>>::set::<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  46:     0x7f44e4d8938f - std[3b302b3c9093c22]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  47:     0x7f44e4d74af9 - <<std[3b302b3c9093c22]::thread::Builder>::spawn_unchecked_<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#1} as core[a3420257622cd381]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x7f44e26abbf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha99802c2c52ada61
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  49:     0x7f44e26abbf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha39aea1c57e28a15
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  50:     0x7f44e26abbf3 - std::sys::unix::thread::Thread::new::thread_start::h9f8e3d72b1f7662f
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys/unix/thread.rs:108:17
  51:     0x7f44e24835c2 - start_thread
  52:     0x7f44e2508584 - __clone
  53:                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.61.0 (fe5b13d68 2022-05-18) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental

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
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `mnemos-std`
Backtrace

   Compiling mnemos-std v0.1.0 (/home/james/hardware-v6/pellegrino/oaiu/mstd)
error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:969:9: no MIR available for DefId(18:254 ~ maitake[bea2]::task::nop)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1279:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_monomorphize::collector::should_codegen_locally
   8: rustc_monomorphize::collector::collect_miri
   9: rustc_monomorphize::collector::collect_miri
  10: rustc_monomorphize::collector::collect_items_rec
  11: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  12: rustc_monomorphize::collector::collect_crate_mono_items
  13: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  14: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>
  15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  16: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  18: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  19: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>>
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::exported_symbols, rustc_query_impl::plumbing::QueryCtxt>
  22: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  23: rustc_metadata::rmeta::encoder::encode_metadata_impl
  24: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata::rmeta::encoder::EncodedMetadata, ()>
  25: rustc_metadata::rmeta::encoder::encode_metadata
  26: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
  27: <rustc_interface::queries::Queries>::ongoing_codegen
  28: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  29: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  30: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  31: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.61.0 (fe5b13d68 2022-05-18) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental

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
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `mnemos-std`

@jamesmunns jamesmunns 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 Jun 3, 2022
@jamesmunns
Copy link
Member Author

I'll see if I can make a smaller repro case

@jamesmunns
Copy link
Member Author

So, the minimal repro case is MUCH smaller:

in Cargo.toml:

[dependencies.maitake]
git = "https://github.com/hawkw/mycelium.git"
rev = "bde817203af5b21591cdca0d257173c1e57b20fe"
features = ["alloc"]
default-features = false

In main.rs:

use maitake::scheduler::TaskStub;
static TASK_STUB: TaskStub = TaskStub::new();
fn main() { }

Which points to these code chunks:

This seems to work in the tests for maitake, so it seems like the ICE only triggers when used from an external trait. Additionally, this ICE does NOT trigger in cargo check.

@jamesmunns
Copy link
Member Author

CC @hawkw

hawkw added a commit to hawkw/mycelium that referenced this issue Jun 3, 2022
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw
Copy link
Contributor

hawkw commented Jun 3, 2022

Yeah, this seems to occur specifically when trying to compile an external crate that calls this function. Lib tests inside the crate that call the function don't ICE, but adding an integration test (outside of the crate's compilation unit) does trigger the ICE: hawkw/mycelium@e1c5085

@hawkw
Copy link
Contributor

hawkw commented Jun 3, 2022

If the function is made pub, the ICE no longer occurs. For example, this commit does not ICE: hawkw/mycelium@b811dbe

@matthiaskrgr
Copy link
Member

@rustbot prioritize

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 3, 2022
@hawkw
Copy link
Contributor

hawkw commented Jun 3, 2022

...and, if the functions are made pub but placed in a private module, they get culled again, triggering the ICE: hawkw/mycelium@aa65400

hawkw added a commit to hawkw/mycelium that referenced this issue Jun 3, 2022
this makes the nop fns #[doc(hidden)] pub`. the `Header` type is moved
to a private module and made `pub`.

@jamesmunns if you have a better solution, let's do that

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
jamesmunns added a commit to hawkw/mycelium that referenced this issue Jun 3, 2022
@jamesmunns
Copy link
Member Author

It also appears that if you move the functions out of the const fn, AND mark them as #[no_mangle], the ICE is also abated.

See this PR for addressing: hawkw/mycelium#190

hawkw pushed a commit to hawkw/mycelium that referenced this issue Jun 3, 2022
@jamesmunns
Copy link
Member Author

For folks joining now/as a TL;DR, the offending code is basically this:

// in the "Header" type, which is a private type in maitake
pub(crate) const fn new_stub() -> Self {
    unsafe fn nop(_ptr: TaskRef) -> Poll<()> {
        #[cfg(debug_assertions)]
        unreachable!("stub task ({_ptr:?}) should never be polled!");
        #[cfg(not(debug_assertions))]
        Poll::Pending
    }

    unsafe fn nop_deallocate(ptr: NonNull<Header>) {
        unreachable!("stub task ({ptr:p}) should never be deallocated!");
    }

    Self {
        run_queue: mpsc_queue::Links::new_stub(),
        state: StateCell::new(),
        vtable: &Vtable {
            poll: nop,
            deallocate: nop_deallocate,
        },
    }
}

The new_stub() function produces a value, that gets created in a static:

// This is a public type in `maitake`
#[repr(transparent)]
#[cfg_attr(loom, allow(dead_code))]
pub struct TaskStub {
    hdr: Header,
}

impl TaskStub {
    /// Create a new unique stub [`Task`].
    pub const fn new() -> Self {
        Self {
            hdr: Header::new_stub(),
        }
    }
}

Which gets loaded into a static in user code:

use maitake::scheduler::TaskStub;
static TASK_STUB: TaskStub = TaskStub::new();
fn main() { }

It LOOKS like somehow the two original functions (declared inside a private, const fn; inside a private type), are getting culled, which means that when the static (in another compilation unit) goes to be created, the MIR for those functions are missing.

@compiler-errors
Copy link
Member

This is likely a disagreement between should_encode_mir and should_codegen_locally.

Though I don't know much about codegen.

@compiler-errors
Copy link
Member

Anyways I think I have a fix, though I am not certain it's the right one. In any case, I at least have a minimized UI test for rustc devs who know codegen better than me. PR incoming.

@compiler-errors compiler-errors self-assigned this Jun 4, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 4, 2022
…eywiser

Fix reachability analysis for const methods

Use `method_might_be_inlined` directly for `ImplItemKind::Fn` instead of duplicating the logic in `def_id_represents_local_inlined_item`.

This is parallel to how we use `item_might_be_inlined` for `ItemKind::Fn` in that same body.

Fixes rust-lang#97708
@bors bors closed this as completed in 9917f38 Jun 4, 2022
@inquisitivecrystal inquisitivecrystal removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 6, 2022
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) ❄️ 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.

6 participants