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: InstanceDef::Virtual (Virtual(DefId(..))) is for direct calls only lazy_type_alias + mono items #114198

Open
matthiaskrgr opened this issue Jul 29, 2023 · 3 comments
Labels
C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 29, 2023

Code

rustc -Zprint-mono-items=eager file.rs

#![feature(lazy_type_alias)]

impl Trait for Struct {}
trait Trait {
    fn test(&self) {}
}

type Struct = dyn Trait + Send;

fn main() {}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

...
Backtrace

error: internal compiler error: compiler/rustc_mir_transform/src/shim.rs:85:13: InstanceDef::Virtual (Virtual(DefId(0:5 ~ treereduce[f361]::Trait::test), 3)) is for direct calls only

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/compiler/rustc_errors/src/lib.rs:1645:9
stack backtrace:
   0:     0x7f6500162fc1 - std::backtrace_rs::backtrace::libunwind::trace::hdb93c75af49465f7
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f6500162fc1 - std::backtrace_rs::backtrace::trace_unsynchronized::h173553974892ea20
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6500162fc1 - std::sys_common::backtrace::_print_fmt::h4a408d1535f12ce7
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f6500162fc1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h80e339e782587177
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f65001c949c - core::fmt::rt::Argument::fmt::h48c77cd529068ea0
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/core/src/fmt/rt.rs:138:9
   5:     0x7f65001c949c - core::fmt::write::hd5614e3697ba0662
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f65001555ce - std::io::Write::write_fmt::h18665f5cd588a024
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/io/mod.rs:1714:15
   7:     0x7f6500162dd5 - std::sys_common::backtrace::_print::h5415b7879e858e5a
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f6500162dd5 - std::sys_common::backtrace::print::hc72a2f092cb4fce1
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f6500165e2a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h11ce7931c3e3ad73
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/panicking.rs:278:22
  10:     0x7f6500165ac3 - std::panicking::panic_hook_with_disk_dump::h32f84721a84edaa9
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/panicking.rs:312:9
  11:     0x7f650340ef39 - rustc_driver_impl[2d064f46b3c8d597]::install_ice_hook::{closure#0}
  12:     0x7f65001666d0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h93009440feeb02eb
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/alloc/src/boxed.rs:2021:9
  13:     0x7f65001666d0 - std::panicking::rust_panic_with_hook::hc8970ff82cfba6ba
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/panicking.rs:733:13
  14:     0x7f65039ce591 - std[43ea1a6b17be2c75]::panicking::begin_panic::<rustc_errors[a4390c3b40f87867]::ExplicitBug>::{closure#0}
  15:     0x7f65039ce396 - std[43ea1a6b17be2c75]::sys_common::backtrace::__rust_end_short_backtrace::<std[43ea1a6b17be2c75]::panicking::begin_panic<rustc_errors[a4390c3b40f87867]::ExplicitBug>::{closure#0}, !>
  16:     0x7f650397c646 - std[43ea1a6b17be2c75]::panicking::begin_panic::<rustc_errors[a4390c3b40f87867]::ExplicitBug>
  17:     0x7f65039dd7a4 - <rustc_errors[a4390c3b40f87867]::HandlerInner>::bug::<alloc[98daf3ced61b4627]::string::String>
  18:     0x7f65039dd636 - <rustc_errors[a4390c3b40f87867]::Handler>::bug::<alloc[98daf3ced61b4627]::string::String>
  19:     0x7f65039b97cc - rustc_middle[dfa6d6dd80f6535c]::util::bug::opt_span_bug_fmt::<rustc_span[5d15a33e9175a7b0]::span_encoding::Span>::{closure#0}
  20:     0x7f65039b85ca - rustc_middle[dfa6d6dd80f6535c]::ty::context::tls::with_opt::<rustc_middle[dfa6d6dd80f6535c]::util::bug::opt_span_bug_fmt<rustc_span[5d15a33e9175a7b0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f65039b8598 - rustc_middle[dfa6d6dd80f6535c]::ty::context::tls::with_context_opt::<rustc_middle[dfa6d6dd80f6535c]::ty::context::tls::with_opt<rustc_middle[dfa6d6dd80f6535c]::util::bug::opt_span_bug_fmt<rustc_span[5d15a33e9175a7b0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f6501dd15e0 - rustc_middle[dfa6d6dd80f6535c]::util::bug::bug_fmt
  23:     0x7f65027a3dbd - rustc_mir_transform[ef19b90d23ceef0f]::shim::make_shim
  24:     0x7f650206388f - rustc_query_impl[9b7bf9fcc2c74b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b7bf9fcc2c74b]::query_impl::mir_shims::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dfa6d6dd80f6535c]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f650206384c - <rustc_query_impl[9b7bf9fcc2c74b]::query_impl::mir_shims::dynamic_query::{closure#2} as core[b78222062286ce0]::ops::function::FnOnce<(rustc_middle[dfa6d6dd80f6535c]::ty::context::TyCtxt, rustc_middle[dfa6d6dd80f6535c]::ty::instance::InstanceDef)>>::call_once
  26:     0x7f6502065e70 - rustc_query_system[d8ac3be064c6a648]::query::plumbing::try_execute_query::<rustc_query_impl[9b7bf9fcc2c74b]::DynamicConfig<rustc_query_system[d8ac3be064c6a648]::query::caches::DefaultCache<rustc_middle[dfa6d6dd80f6535c]::ty::instance::InstanceDef, rustc_middle[dfa6d6dd80f6535c]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9b7bf9fcc2c74b]::plumbing::QueryCtxt, false>
  27:     0x7f6502065b83 - rustc_query_impl[9b7bf9fcc2c74b]::query_impl::mir_shims::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f65018f7afc - <rustc_middle[dfa6d6dd80f6535c]::ty::context::TyCtxt>::instance_mir
  29:     0x7f6501478c46 - rustc_monomorphize[1ccdbbc078c7102a]::collector::collect_used_items
  30:     0x7f6501475615 - rustc_monomorphize[1ccdbbc078c7102a]::collector::collect_items_rec
  31:     0x7f65029c7d60 - rustc_data_structures[2f54d9eed481ad54]::sync::par_for_each_in::<alloc[98daf3ced61b4627]::vec::Vec<rustc_middle[dfa6d6dd80f6535c]::mir::mono::MonoItem>, rustc_monomorphize[1ccdbbc078c7102a]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  32:     0x7f65029c7659 - <rustc_session[6dc82fd81d82b638]::session::Session>::time::<(), rustc_monomorphize[1ccdbbc078c7102a]::collector::collect_crate_mono_items::{closure#1}>
  33:     0x7f65029c72b8 - rustc_monomorphize[1ccdbbc078c7102a]::collector::collect_crate_mono_items
  34:     0x7f65029c5897 - rustc_monomorphize[1ccdbbc078c7102a]::partitioning::collect_and_partition_mono_items
  35:     0x7f6502a12c39 - rustc_query_impl[9b7bf9fcc2c74b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9b7bf9fcc2c74b]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dfa6d6dd80f6535c]::query::erase::Erased<[u8; 24usize]>>
  36:     0x7f6502a12c0b - <rustc_query_impl[9b7bf9fcc2c74b]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[b78222062286ce0]::ops::function::FnOnce<(rustc_middle[dfa6d6dd80f6535c]::ty::context::TyCtxt, ())>>::call_once
  37:     0x7f6502af881c - rustc_query_system[d8ac3be064c6a648]::query::plumbing::try_execute_query::<rustc_query_impl[9b7bf9fcc2c74b]::DynamicConfig<rustc_query_system[d8ac3be064c6a648]::query::caches::SingleCache<rustc_middle[dfa6d6dd80f6535c]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[9b7bf9fcc2c74b]::plumbing::QueryCtxt, false>
  38:     0x7f6502d85d48 - rustc_query_impl[9b7bf9fcc2c74b]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f6502458c26 - rustc_codegen_ssa[7aa2eca03bf336cb]::base::codegen_crate::<rustc_codegen_llvm[7357bbc6bc95b1a0]::LlvmCodegenBackend>
  40:     0x7f6502458a0b - <rustc_codegen_llvm[7357bbc6bc95b1a0]::LlvmCodegenBackend as rustc_codegen_ssa[7aa2eca03bf336cb]::traits::backend::CodegenBackend>::codegen_crate
  41:     0x7f6502668762 - <rustc_session[6dc82fd81d82b638]::session::Session>::time::<alloc[98daf3ced61b4627]::boxed::Box<dyn core[b78222062286ce0]::any::Any>, rustc_interface[e815501e41232ae3]::passes::start_codegen::{closure#0}>
  42:     0x7f65026682db - rustc_interface[e815501e41232ae3]::passes::start_codegen
  43:     0x7f6502662f6a - <rustc_middle[dfa6d6dd80f6535c]::ty::context::GlobalCtxt>::enter::<<rustc_interface[e815501e41232ae3]::queries::Queries>::ongoing_codegen::{closure#0}, core[b78222062286ce0]::result::Result<alloc[98daf3ced61b4627]::boxed::Box<dyn core[b78222062286ce0]::any::Any>, rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>
  44:     0x7f6502661fa3 - <rustc_interface[e815501e41232ae3]::interface::Compiler>::enter::<rustc_driver_impl[2d064f46b3c8d597]::run_compiler::{closure#1}::{closure#2}, core[b78222062286ce0]::result::Result<core[b78222062286ce0]::option::Option<rustc_interface[e815501e41232ae3]::queries::Linker>, rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>
  45:     0x7f650265aff8 - std[43ea1a6b17be2c75]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e815501e41232ae3]::util::run_in_thread_pool_with_globals<rustc_interface[e815501e41232ae3]::interface::run_compiler<core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>, rustc_driver_impl[2d064f46b3c8d597]::run_compiler::{closure#1}>::{closure#0}, core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>
  46:     0x7f650265a77e - <<std[43ea1a6b17be2c75]::thread::Builder>::spawn_unchecked_<rustc_interface[e815501e41232ae3]::util::run_in_thread_pool_with_globals<rustc_interface[e815501e41232ae3]::interface::run_compiler<core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>, rustc_driver_impl[2d064f46b3c8d597]::run_compiler::{closure#1}>::{closure#0}, core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b78222062286ce0]::result::Result<(), rustc_span[5d15a33e9175a7b0]::ErrorGuaranteed>>::{closure#1} as core[b78222062286ce0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x7f6500170dc5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f82faf6b02ba832
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/alloc/src/boxed.rs:2007:9
  48:     0x7f6500170dc5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf73d60080ca8008e
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/alloc/src/boxed.rs:2007:9
  49:     0x7f6500170dc5 - std::sys::unix::thread::Thread::new::thread_start::hb438279e2a921916
                               at /rustc/04abc370b9f3855b28172b65a7f7d5a433f41412/library/std/src/sys/unix/thread.rs:108:17
  50:     0x7f64ffebf44b - <unknown>
  51:     0x7f64fff42e40 - <unknown>
  52:                0x0 - <unknown>

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: please attach the file at `/tmp/im/rustc-ice-2023-07-29T04:50:29.860118737Z-3547485.txt` to your bug report

note: compiler flags: -Z print-mono-items=eager

query stack during panic:
#0 [mir_shims] generating MIR shim for `Trait::test`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error; 1 warning emitted

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. F-lazy_type_alias `#![feature(lazy_type_alias)]` labels Jul 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@matthiaskrgr
Copy link
Member Author

Regression in nightly-2023-06-22
started with #112853 🤷

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@fmease
Copy link
Member

fmease commented Aug 4, 2023

This doesn't need lazy type aliases to reproduce:

rustc -Zprint-mono-items=eager

impl Trait for <Ty as Owner>::Struct {}
trait Trait {
    fn test(&self) {}
}

enum Ty {}
trait Owner { type Struct: ?Sized; }
impl Owner for Ty {
    type Struct = dyn Trait + Send;
}

fn main() {}

@fmease
Copy link
Member

fmease commented Aug 4, 2023

I'd like to clarify, we should definitely keep the label F-lazy_type_alias since this code will regress if / once we make lazy type aliases the default (in a new edition). However, my finding demonstrates that the bug is preexisting. The faulty code path doesn't handle alias types (ty::AliasTy) correctly (ty::Projection in the case of associated types and ty::Weak in the case of lazy type aliases).

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 18, 2024
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. F-lazy_type_alias `#![feature(lazy_type_alias)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

4 participants