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: issue-69398.rs with mir-opt-level=3 and --crate-type=lib: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize <() as Foo>::Bar #91745

Closed
matthiaskrgr opened this issue Dec 10, 2021 · 5 comments · Fixed by #91875
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

code from ./src/test/ui/associated-types/issue-69398.rs
cc #69398

Code

// check-pass

pub trait Foo {
    type Bar;
}

pub trait Broken {
    type Assoc;
    fn broken(&self) where Self::Assoc: Foo;
}

impl<T> Broken for T {
    type Assoc = ();
    fn broken(&self) where Self::Assoc: Foo {
        let _x: <Self::Assoc as Foo>::Bar;
    }
}

fn main() {
    let _m: &dyn Broken<Assoc=()> = &();
}

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (0b42deacc 2021-12-09)
binary: rustc
commit-hash: 0b42deaccc2cbe17a68067aa5fdb76104369e1fd
commit-date: 2021-12-09
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

rustc ./src/test/ui/associated-types/issue-69398.rs -Zmir-opt-level=3 --crate-type lib

Note that --crate-type lib is required to reproduce the ICE

warning: function is never used: `main`
  --> ./src/test/ui/associated-types/issue-69398.rs:19:4
   |
19 | fn main() {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize `<() as Foo>::Bar`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<() as Foo>::Bar`
#1 [optimized_mir] optimizing MIR for `<impl at ./src/test/ui/associated-types/issue-69398.rs:12:1: 17:2>::broken`
end of query stack
error: aborting due to previous error; 1 warning emitted

Backtrace

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:62:32: could not fully normalize `<() as Foo>::Bar`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
stack backtrace:
   0:     0x7f2e30bd535c - std::backtrace_rs::backtrace::libunwind::trace::hf7449935ead7573e
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2e30bd535c - std::backtrace_rs::backtrace::trace_unsynchronized::h221aa2d88d72372a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2e30bd535c - std::sys_common::backtrace::_print_fmt::h1c77e8983e1df895
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f2e30bd535c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4ec41a9a6b0d22c
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f2e30c3237c - core::fmt::write::h72801a82c94e6ff1
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/core/src/fmt/mod.rs:1149:17
   5:     0x7f2e30bc5a65 - std::io::Write::write_fmt::haf74340a8cbeaa88
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/io/mod.rs:1660:15
   6:     0x7f2e30bd8520 - std::sys_common::backtrace::_print::h2d15cd157796a64a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f2e30bd8520 - std::sys_common::backtrace::print::h52d286d22e2398eb
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f2e30bd8520 - std::panicking::default_hook::{{closure}}::h6da08fba6306daf2
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:211:50
   9:     0x7f2e30bd80cb - std::panicking::default_hook::h266f67a22e76b11a
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:228:9
  10:     0x7f2e316fc291 - rustc_driver[feb513e6adc957d8]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f2e30bd8d39 - std::panicking::rust_panic_with_hook::he55698a957f4fb6d
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:610:17
  12:     0x7f2e3282ae6b - std[f24903a91e569aa2]::panicking::begin_panic::<rustc_errors[248f3f311c690252]::ExplicitBug>::{closure#0}
  13:     0x7f2e3282ae06 - std[f24903a91e569aa2]::sys_common::backtrace::__rust_end_short_backtrace::<std[f24903a91e569aa2]::panicking::begin_panic<rustc_errors[248f3f311c690252]::ExplicitBug>::{closure#0}, !>
  14:     0x7f2e3282df5f - std[f24903a91e569aa2]::panicking::begin_panic::<rustc_errors[248f3f311c690252]::ExplicitBug>
  15:     0x7f2e32838ead - std[f24903a91e569aa2]::panic::panic_any::<rustc_errors[248f3f311c690252]::ExplicitBug>
  16:     0x7f2e3283a56d - <rustc_errors[248f3f311c690252]::HandlerInner>::bug
  17:     0x7f2e3283a010 - <rustc_errors[248f3f311c690252]::Handler>::bug
  18:     0x7f2e326be5b6 - rustc_middle[f720485c3bb04922]::ty::context::tls::with_opt::<rustc_middle[f720485c3bb04922]::util::bug::opt_span_bug_fmt<rustc_span[dda57b1885b40b9a]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f2e326beae0 - rustc_middle[f720485c3bb04922]::util::bug::opt_span_bug_fmt::<rustc_span[dda57b1885b40b9a]::span_encoding::Span>
  20:     0x7f2e326bea56 - rustc_middle[f720485c3bb04922]::util::bug::bug_fmt
  21:     0x7f2e32f9d466 - <rustc_infer[7479c472c492593c]::infer::InferCtxtBuilder>::enter::<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg, rustc_traits[3a05bb033114c414]::normalize_erasing_regions::normalize_after_erasing_regions<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>::{closure#0}>
  22:     0x7f2e32f99bba - <rustc_traits[3a05bb033114c414]::normalize_erasing_regions::provide::{closure#0} as core[cc79c391059f8e46]::ops::function::FnOnce<(rustc_middle[f720485c3bb04922]::ty::context::TyCtxt, rustc_middle[f720485c3bb04922]::ty::ParamEnvAnd<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>)>>::call_once
  23:     0x7f2e32fbfd19 - rustc_query_system[27ba240b72fd7978]::query::plumbing::try_execute_query::<rustc_query_impl[9c2ccd6b3a0df356]::plumbing::QueryCtxt, rustc_query_system[27ba240b72fd7978]::query::caches::DefaultCache<rustc_middle[f720485c3bb04922]::ty::ParamEnvAnd<rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>, rustc_middle[f720485c3bb04922]::ty::subst::GenericArg>>
  24:     0x7f2e33067924 - <rustc_query_impl[9c2ccd6b3a0df356]::Queries as rustc_middle[f720485c3bb04922]::ty::query::QueryEngine>::normalize_generic_arg_after_erasing_regions
  25:     0x7f2e3343cef6 - <rustc_middle[f720485c3bb04922]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle[f720485c3bb04922]::ty::fold::TypeFolder>::fold_ty
  26:     0x7f2e32ab8c40 - <rustc_middle[f720485c3bb04922]::ty::context::TyCtxt>::normalize_erasing_regions::<&rustc_middle[f720485c3bb04922]::ty::TyS>
  27:     0x7f2e3198285b - <rustc_mir_transform[f9737dd6152db8c1]::reveal_all::RevealAll as rustc_middle[f720485c3bb04922]::mir::MirPass>::run_pass
  28:     0x7f2e32aa443f - rustc_mir_transform[f9737dd6152db8c1]::pass_manager::run_passes
  29:     0x7f2e337808e7 - rustc_mir_transform[f9737dd6152db8c1]::optimized_mir
  30:     0x7f2e32fe1efd - rustc_query_system[27ba240b72fd7978]::query::plumbing::try_execute_query::<rustc_query_impl[9c2ccd6b3a0df356]::plumbing::QueryCtxt, rustc_query_system[27ba240b72fd7978]::query::caches::DefaultCache<rustc_span[dda57b1885b40b9a]::def_id::DefId, &rustc_middle[f720485c3bb04922]::mir::Body>>
  31:     0x7f2e33059b97 - <rustc_query_impl[9c2ccd6b3a0df356]::Queries as rustc_middle[f720485c3bb04922]::ty::query::QueryEngine>::optimized_mir
  32:     0x7f2e330eb609 - <rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::EncodeContext>::encode_crate_root
  33:     0x7f2e33c39801 - rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata_impl
  34:     0x7f2e33c4bfe1 - rustc_data_structures[740a91d2eeb9710d]::sync::join::<rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::EncodedMetadata, ()>
  35:     0x7f2e33c38fe6 - rustc_metadata[b7dbc791ee3c9388]::rmeta::encoder::encode_metadata
  36:     0x7f2e335c09a1 - <rustc_interface[4c4b5644b43577f1]::queries::Queries>::ongoing_codegen
  37:     0x7f2e3359081d - <rustc_interface[4c4b5644b43577f1]::interface::Compiler>::enter::<rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}::{closure#2}, core[cc79c391059f8e46]::result::Result<core[cc79c391059f8e46]::option::Option<rustc_interface[4c4b5644b43577f1]::queries::Linker>, rustc_errors[248f3f311c690252]::ErrorReported>>
  38:     0x7f2e3358d14d - rustc_span[dda57b1885b40b9a]::with_source_map::<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_interface[4c4b5644b43577f1]::interface::create_compiler_and_run<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#1}>
  39:     0x7f2e335917ef - <scoped_tls[3fea4c3dcac147b1]::ScopedKey<rustc_span[dda57b1885b40b9a]::SessionGlobals>>::set::<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>
  40:     0x7f2e3358f995 - std[f24903a91e569aa2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>
  41:     0x7f2e335afffa - <<std[f24903a91e569aa2]::thread::Builder>::spawn_unchecked<rustc_interface[4c4b5644b43577f1]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[4c4b5644b43577f1]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>, rustc_driver[feb513e6adc957d8]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[248f3f311c690252]::ErrorReported>>::{closure#1} as core[cc79c391059f8e46]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f2e30be3e23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4beb69a85f7fb16c
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/alloc/src/boxed.rs:1811:9
  43:     0x7f2e30be3e23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hef865a799f44aaf2
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/alloc/src/boxed.rs:1811:9
  44:     0x7f2e30be3e23 - std::sys::unix::thread::Thread::new::thread_start::hee0b2d4e2414fa96
                               at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/sys/unix/thread.rs:108:17
  45:     0x7f2e30af1259 - start_thread
  46:     0x7f2e30a065e3 - __GI___clone
  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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 --crate-type lib

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<() as Foo>::Bar`
#1 [optimized_mir] optimizing MIR for `<impl at ./src/test/ui/associated-types/issue-69398.rs:12:1: 17:2>::broken`
end of query stack
error: aborting due to previous error; 1 warning emitted

@matthiaskrgr matthiaskrgr 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 Dec 10, 2021
@matthiaskrgr
Copy link
Member Author

cc @b-naber maybe you have an idea why this still crashes with --crate-type lib ?

@b-naber
Copy link
Contributor

b-naber commented Dec 10, 2021

No, I don't unfortunately. The version of normalize_erasing_regions version I worked on is meant to be called before typecheck has finished and where normalization could still fail. This call seems to occur during codegen, where normalization should (in theory) always succeed (or rather errors should have been caught earlier), but I'm not that familiar with the later stages of the compiler, so I might be missing something.

@Aaron1011
Copy link
Member

@b-naber This normalization is happening in an optimization pass (RevealAll) which can run on MIR that can never be codegenned. In this case, the broken method impl has an impossible-to-satisfy where clause, so it can never actually be called or codegenned.

The optimization pass should be changed to use try_normalize_erasing_regions - it can just do nothing if it fails.

@b-naber
Copy link
Contributor

b-naber commented Dec 13, 2021

@Aaron1011 Thanks for pointing out the problem. Would you like to open a PR for this or are you ok with me trying to fix this?

@Aaron1011
Copy link
Member

@b-naber Feel free to open a PR

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 13, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 14, 2021
…g, r=Aaron1011

Use try_normalize_erasing_regions in RevealAllVisitor

Fixes rust-lang#91745

Thanks to `@Aaron1011` for [pointing out the problem](rust-lang#91745 (comment)).

r? `@Aaron1011`
@bors bors closed this as completed in b50bb65 Dec 14, 2021
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. glacier ICE tracked in rust-lang/glacier. 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.

4 participants