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 -Zpolymorphize=on "collection encountered polymorphic constant: Unevaluated(UnevaluatedConst" #105249

Open
matthiaskrgr opened this issue Dec 4, 2022 · 5 comments
Assignees
Labels
-Zpolymorphize Unstable option: Polymorphization. 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) ❄️ S-bug-has-test Status: A `known-bug` test has been added for this bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 4, 2022

Code

src/test/ui/issues/issue-39292.rs

// run-pass
// Regression test for issue #39292. The object vtable was being
// incorrectly left with a null pointer.

trait Foo<T> {
    fn print<'a>(&'a self) where T: 'a { println!("foo"); }
}

impl<'a> Foo<&'a ()> for () { }

trait Bar: for<'a> Foo<&'a ()> { }

impl Bar for () {}

fn main() {
    (&() as &dyn Bar).print(); // Segfault
}

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (32e613bba 2022-12-02)
binary: rustc
commit-hash: 32e613bbaafee1bcabba48a2257b838f8d1c03d3
commit-date: 2022-12-02
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

rustc src/test/ui/issues/issue-39292.rs -Zpolymorphize=on

<output>
Backtrace

error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:786:54: collection encountered polymorphic constant: Unevaluated(UnevaluatedConst { def: WithOptConstParam { did: DefId(0:5 ~ issue_39292[a2ad]::Foo::print), const_param_did: None }, substs: [(), T, ReErased], promoted: Some(promoted[1]) }, &[&str; 1])
 --> src/test/ui/issues/issue-39292.rs:6:51
  |
6 |     fn print<'a>(&'a self) where T: 'a { println!("foo"); }
  |                                                   ^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/compiler/rustc_errors/src/lib.rs:972:33
stack backtrace:
   0:     0x7ff11c464a5a - std::backtrace_rs::backtrace::libunwind::trace::h445f1a380ebe24fa
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff11c464a5a - std::backtrace_rs::backtrace::trace_unsynchronized::h8c542444dc84bbad
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff11c464a5a - std::sys_common::backtrace::_print_fmt::hd1e3793b0f95c644
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ff11c464a5a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h515025d5c2825d78
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff11c8efe4e - core::fmt::write::hfd15a46634ae3152
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/core/src/fmt/mod.rs:1208:17
   5:     0x7ff11c458cc5 - std::io::Write::write_fmt::h74b2e38eb2a622bf
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/io/mod.rs:1682:15
   6:     0x7ff11c464825 - std::sys_common::backtrace::_print::hd2af8aafbe5d4e4d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7ff11c464825 - std::sys_common::backtrace::print::hc83e0ce2c452dd90
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7ff11c466baf - std::panicking::default_hook::{{closure}}::h6fa5498814662258
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:267:22
   9:     0x7ff11c4668eb - std::panicking::default_hook::h27c5cc64dbc8482d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:286:9
  10:     0x7ff11b6bdf24 - rustc_driver[1a6385c1c72d16e7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7ff11c4673ad - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h555d7d9f22ed347d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2032:9
  12:     0x7ff11c4673ad - std::panicking::rust_panic_with_hook::hf0b4a17e8b00f779
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:692:13
  13:     0x7ff11bd9e991 - std[79527836cf90b5dd]::panicking::begin_panic::<rustc_errors[643e9caaba05b420]::ExplicitBug>::{closure#0}
  14:     0x7ff11bd9e376 - std[79527836cf90b5dd]::sys_common::backtrace::__rust_end_short_backtrace::<std[79527836cf90b5dd]::panicking::begin_panic<rustc_errors[643e9caaba05b420]::ExplicitBug>::{closure#0}, !>
  15:     0x7ff11bd95d56 - std[79527836cf90b5dd]::panicking::begin_panic::<rustc_errors[643e9caaba05b420]::ExplicitBug>
  16:     0x7ff11bdaab56 - std[79527836cf90b5dd]::panic::panic_any::<rustc_errors[643e9caaba05b420]::ExplicitBug>
  17:     0x7ff11bda9af9 - <rustc_errors[643e9caaba05b420]::HandlerInner>::span_bug::<rustc_span[c03eaf4ea18165a3]::span_encoding::Span, &alloc[976f33e9556b75e2]::string::String>
  18:     0x7ff11bda9780 - <rustc_errors[643e9caaba05b420]::Handler>::span_bug::<rustc_span[c03eaf4ea18165a3]::span_encoding::Span, &alloc[976f33e9556b75e2]::string::String>
  19:     0x7ff11bda7211 - rustc_middle[19d5e5a4d6179ade]::ty::context::tls::with_context_opt::<rustc_middle[19d5e5a4d6179ade]::ty::context::tls::with_opt<rustc_middle[19d5e5a4d6179ade]::util::bug::opt_span_bug_fmt<rustc_span[c03eaf4ea18165a3]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  20:     0x7ff11bda70c6 - rustc_middle[19d5e5a4d6179ade]::util::bug::opt_span_bug_fmt::<rustc_span[c03eaf4ea18165a3]::span_encoding::Span>
  21:     0x7ff11bda7084 - rustc_middle[19d5e5a4d6179ade]::util::bug::span_bug_fmt::<rustc_span[c03eaf4ea18165a3]::span_encoding::Span>
  22:     0x7ff1195f9335 - rustc_monomorphize[f852be8325467616]::collector::collect_neighbours
  23:     0x7ff1195e92e9 - rustc_monomorphize[f852be8325467616]::collector::collect_items_rec
  24:     0x7ff1195e9754 - rustc_monomorphize[f852be8325467616]::collector::collect_items_rec
  25:     0x7ff11aa5e7b5 - <rustc_session[2f16cc1ca0f45371]::session::Session>::time::<(), rustc_monomorphize[f852be8325467616]::collector::collect_crate_mono_items::{closure#1}>
  26:     0x7ff11aa5e2d4 - rustc_monomorphize[f852be8325467616]::collector::collect_crate_mono_items
  27:     0x7ff11aa5d6e3 - rustc_monomorphize[f852be8325467616]::partitioning::collect_and_partition_mono_items
  28:     0x7ff11ae33a00 - rustc_query_system[c29954e9c418d3e1]::query::plumbing::try_execute_query::<rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt, rustc_query_system[c29954e9c418d3e1]::query::caches::DefaultCache<(), (&std[79527836cf90b5dd]::collections::hash::set::HashSet<rustc_span[c03eaf4ea18165a3]::def_id::DefId, core[7075224b64f80aa]::hash::BuildHasherDefault<rustc_hash[7698cfb367caca01]::FxHasher>>, &[rustc_middle[19d5e5a4d6179ade]::mir::mono::CodegenUnit])>>
  29:     0x7ff11ae336c4 - rustc_query_system[c29954e9c418d3e1]::query::plumbing::get_query::<rustc_query_impl[81623dbe8f24b13f]::queries::collect_and_partition_mono_items, rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt>
  30:     0x7ff11ae335fe - <rustc_query_impl[81623dbe8f24b13f]::Queries as rustc_middle[19d5e5a4d6179ade]::ty::query::QueryEngine>::collect_and_partition_mono_items
  31:     0x7ff11ab215fb - rustc_codegen_ssa[234fb96bead002ba]::base::codegen_crate::<rustc_codegen_llvm[7650bcf584e55ba6]::LlvmCodegenBackend>
  32:     0x7ff11ab213a9 - <rustc_codegen_llvm[7650bcf584e55ba6]::LlvmCodegenBackend as rustc_codegen_ssa[234fb96bead002ba]::traits::backend::CodegenBackend>::codegen_crate
  33:     0x7ff11a7f4941 - <rustc_session[2f16cc1ca0f45371]::session::Session>::time::<alloc[976f33e9556b75e2]::boxed::Box<dyn core[7075224b64f80aa]::any::Any>, rustc_interface[ee8495dca531fc0c]::passes::start_codegen::{closure#0}>
  34:     0x7ff11a7f4435 - rustc_interface[ee8495dca531fc0c]::passes::start_codegen
  35:     0x7ff11a7efb1d - <rustc_interface[ee8495dca531fc0c]::passes::QueryContext>::enter::<<rustc_interface[ee8495dca531fc0c]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[7075224b64f80aa]::result::Result<alloc[976f33e9556b75e2]::boxed::Box<dyn core[7075224b64f80aa]::any::Any>, rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  36:     0x7ff11a7ed334 - <rustc_interface[ee8495dca531fc0c]::queries::Queries>::ongoing_codegen
  37:     0x7ff11a7ec501 - <rustc_interface[ee8495dca531fc0c]::interface::Compiler>::enter::<rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}::{closure#2}, core[7075224b64f80aa]::result::Result<core[7075224b64f80aa]::option::Option<rustc_interface[ee8495dca531fc0c]::queries::Linker>, rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  38:     0x7ff11a7e74e8 - rustc_span[c03eaf4ea18165a3]::with_source_map::<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  39:     0x7ff11a7e6fd5 - <scoped_tls[6605aed902b0fb11]::ScopedKey<rustc_span[c03eaf4ea18165a3]::SessionGlobals>>::set::<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  40:     0x7ff11a7e65c2 - std[79527836cf90b5dd]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ee8495dca531fc0c]::util::run_in_thread_pool_with_globals<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  41:     0x7ff11af6b8e8 - <<std[79527836cf90b5dd]::thread::Builder>::spawn_unchecked_<rustc_interface[ee8495dca531fc0c]::util::run_in_thread_pool_with_globals<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#1} as core[7075224b64f80aa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7ff11c46e5e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb948150b9fd67a86
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2000:9
  43:     0x7ff11c46e5e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2f842213b427eb19
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2000:9
  44:     0x7ff11c46e5e3 - std::sys::unix::thread::Thread::new::thread_start::h2adb6f1223042fb8
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys/unix/thread.rs:108:17
  45:     0x7ff1182658fd - <unknown>
  46:     0x7ff1182e7a60 - <unknown>
  47:                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.67.0-nightly (32e613bba 2022-12-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z polymorphize=on

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

@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. labels Dec 4, 2022
@matthiaskrgr
Copy link
Member Author

searched toolchains 95a992a68694d8bf3959bd2c0ac27ce9e9208b59 through 98ad6a5519651af36e246c0335c964dd52c554ba
Regression in c524c7d
#98588 cc @b-naber

@b-naber
Copy link
Contributor

b-naber commented Dec 4, 2022

@rustbot claim

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 22, 2022
@matthiaskrgr
Copy link
Member Author

Another example

fn pass_to_ptr_call<T>(f: fn(T), x: T) {
    f(x);
}

trait TrackedTrait {
    fn trait_tracked_unit_default(_: ()) {
        let location = std::panic::Location::caller();
        assert_eq!(location.file(), file!());
    }
}

impl TrackedTrait for () {}

fn main() {
    pass_to_ptr_call(<() as TrackedTrait>::trait_tracked_unit_default, ());
}

@chenyukang
Copy link
Member

@b-naber
whether it's Ok to report the error:

error: unexpected polymorphic constant
  --> tests/ui/higher-ranked/trait-bounds/issue-39292.rs:10:18
   |
10 |         println!("foo");
   |                  ^^^^^

My Pr #114985 take care the error.

@cushionbadak
Copy link

Similar case but additional -Zprint-mono-items=eager option required to produce ICE:

Code

pub struct S();

pub trait X {
    fn unused3(var: i32) {
        println!("{}", var);
    }
}

impl X for S {}

fn main() {}

Command

rustc -Zprint-mono-items=eager -Zpolymorphize=on

Meta

rustc 1.79.0-nightly (c9f8f3438 2024-03-27)
binary: rustc
commit-hash: c9f8f3438a8134a413aa5d4903e0196e44e37bbc
commit-date: 2024-03-27
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Output

Output

error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:820:50: collection encountered polymorphic constant: Unevaluated(UnevaluatedConst { def: DefId(0:6 ~ reduced_3C760D49C[7e62]::X::unused3), args: [Self/#0], promoted: Some(promoted[0]) }, &'{erased} [&'{erased} str; 2_usize])
 --> 0327/reduced_3C760D49C.rs:5:18
  |
5 |         println!("{}", var);
  |                  ^^^^

thread 'rustc' panicked at compiler/rustc_monomorphize/src/collector.rs:820:50:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxt>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_monomorphize::collector::MirUsedCollector>::eval_constant
   8: <rustc_monomorphize::collector::MirUsedCollector as rustc_middle::mir::visit::Visitor>::visit_operand
   9: rustc_monomorphize::collector::collect_items_rec::{closure#0}
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  12: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: rustc_interface::passes::start_codegen
  15: <rustc_interface::queries::Queries>::codegen_and_build_linker
  16: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 `/Volumes/T7/workspace/placeholder_rustexec/rustc-ice-2024-03-28T04_33_10-57934.txt` to your bug report

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

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

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: A `known-bug` test has been added for this bug. label Apr 20, 2024
@fmease fmease added the -Zpolymorphize Unstable option: Polymorphization. label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zpolymorphize Unstable option: Polymorphization. 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) ❄️ S-bug-has-test Status: A `known-bug` test has been added for this bug. 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

6 participants