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: Failing to compile gfx-backend-metal: Unexpected type for constructor #89393

Closed
tuzz opened this issue Sep 30, 2021 · 6 comments · Fixed by #89441
Closed

ICE: Failing to compile gfx-backend-metal: Unexpected type for constructor #89393

tuzz opened this issue Sep 30, 2021 · 6 comments · Fixed by #89441
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns 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

@tuzz
Copy link

tuzz commented Sep 30, 2021

Repro

When compiling on an Apple M1 processor:

git clone https://github.com/gfx-rs/gfx.git
cd gfx/src/backend/metal
RUST_BACKTRACE=1 cargo check

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (11491938f 2021-09-29)

Error output

error: internal compiler error: compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs:1191:22: Unexpected type for `Single` constructor: <&soft::Ref as soft::Resources>::BufferArray

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146: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.57.0-nightly (11491938f 2021-09-29) running on aarch64-apple-darwin

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

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_match] match-checking `soft::<impl at src/backend/metal/src/soft.rs:208:1: 476:2>::own_render`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `gfx-backend-metal`
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_mir_build::thir::pattern::deconstruct_pat::Fields::wildcards
   8: rustc_mir_build::thir::pattern::deconstruct_pat::DeconstructedPat::specialize
   9: rustc_mir_build::thir::pattern::usefulness::is_useful
  10: rustc_mir_build::thir::pattern::usefulness::is_useful
  11: rustc_mir_build::thir::pattern::usefulness::is_useful
  12: rustc_mir_build::thir::pattern::usefulness::is_useful
  13: rustc_mir_build::thir::pattern::usefulness::compute_match_usefulness
  14: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  15: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  16: rustc_mir_build::thir::pattern::check_match::check_match
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  18: rustc_data_structures::stack::ensure_sufficient_stack
  19: rustc_query_system::query::plumbing::try_execute_query
  20: rustc_query_system::query::plumbing::get_query
  21: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  22: rustc_session::utils::<impl rustc_session::session::Session>::time
  23: rustc_session::utils::<impl rustc_session::session::Session>::time
  24: rustc_interface::passes::analysis
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  26: rustc_data_structures::stack::ensure_sufficient_stack
  27: rustc_query_system::query::plumbing::try_execute_query
  28: rustc_query_system::query::plumbing::get_query
  29: rustc_interface::passes::QueryContext::enter
  30: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  31: rustc_span::with_source_map
  32: scoped_tls::ScopedKey<T>::set

@tuzz tuzz 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 Sep 30, 2021
@tuzz tuzz changed the title Failing to compile gfx-backend-metal: Unexpected type for constructor ICE: Failing to compile gfx-backend-metal: Unexpected type for constructor Sep 30, 2021
@camdencheek
Copy link

Can also reproduce this when compiling on an Intel Macbook

@P1n3appl3
Copy link
Contributor

P1n3appl3 commented Sep 30, 2021

I've encountered the same error on a different platform (x86_64) when compiling this crate. The project doesn't use cargo so repro is nontrivial, but from our CI I can see that the ICE started occurring at 6df1d82 which is a rollup of #88950.

Error output

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.57.0-nightly (6dc08b909 2021-09-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dep-info-omit-d-target -Z mutable-noalias=off -Z panic_abort_tests -Z allow-features=min_specialization,specialization -C linker=../../prebuilt/third_party/clang/linux-x64/bin/lld -C link-arg=--sysroot=gen/zircon/public/sysroot/cpp -C link-arg=-L../../prebuilt/third_party/clang/linux-x64/bin/../lib/x86_64-unknown-fuchsia -C link-arg=-L../../prebuilt/third_party/clang/linux-x64/lib/clang/14.0.0/lib/x86_64-unknown-fuchsia -C link-arg=--pack-dyn-relocs=relr -C link-arg=-dynamic-linker=ld.so.1 -C link-arg=--icf=all -C force-frame-pointers -C opt-level=0 -C debuginfo=2 -C debug-assertions=yes -C link-args=-zstack-size=0x200000 -C panic=abort -C force-unwind-tables=yes -C link-arg=-Bdynamic -C link-arg=x64-shared/lib.unstripped/libcrypto.so --crate-type rlib

query stack during panic:
#0 [check_match] match-checking `ip::gmp::igmp::run_action`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_mir_build::thir::pattern::deconstruct_pat::Fields::wildcards
   8: rustc_mir_build::thir::pattern::deconstruct_pat::DeconstructedPat::specialize
   9: rustc_mir_build::thir::pattern::usefulness::is_useful
  10: rustc_mir_build::thir::pattern::usefulness::is_useful
  11: rustc_mir_build::thir::pattern::usefulness::compute_match_usefulness
  12: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  13: rustc_hir::intravisit::walk_expr
  14: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  15: rustc_mir_build::thir::pattern::check_match::check_match
  16: rustc_query_system::query::plumbing::try_execute_query
  17: rustc_query_system::query::plumbing::get_query
  18: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  19: rustc_session::utils::<impl rustc_session::session::Session>::time
  20: rustc_session::utils::<impl rustc_session::session::Session>::time
  21: rustc_interface::passes::analysis
  22: rustc_query_system::query::plumbing::try_execute_query
  23: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  24: rustc_interface::passes::QueryContext::enter
  25: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  26: rustc_span::with_source_map
  27: scoped_tls::ScopedKey<T>::set

@ndmitchell
Copy link

@hkratz
Copy link
Contributor

hkratz commented Oct 1, 2021

Somewhat minimized standalone testcase:

pub trait Resources2 {
    type BufferArray;
}

pub enum RenderCommand2<R: Resources2> {
    BindBuffers { buffers: R::BufferArray },
}

pub struct Ref2;
impl<'a> Resources2 for &'a Ref2 {
    type BufferArray = (&'a u32, &'a u32);
}

pub fn own_render2(com: RenderCommand2<&Ref2>) -> u32 {
    match com {
        RenderCommand2::BindBuffers {
            buffers: (_buffers, _offsets),
        } => 0,
    }
}

Playground

Builds on stable, fails on nightly.

cc @Nadrieril

@Nadrieril Nadrieril added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Oct 1, 2021
@Nadrieril
Copy link
Member

Nadrieril commented Oct 1, 2021

Thanks for the minimization! Seems like we've hit #72476 again, but through a different code path. I'm investigating.

@Lukas-Dresel
Copy link

I think #89448 might be another duplicate of this, triggered when compiling the smt2 crate.

@bors bors closed this as completed in 5ab1245 Oct 2, 2021
mikegerwitz pushed a commit to lovullo/tame that referenced this issue Nov 23, 2021
This provides a child `raw` module that exposes a SymbolId representing the
inner value of each of the static newtypes.  This is needed in situations
where the type must match and the type of the static symbol is not
important.

In particular, when comparing against runtime-allocated symbols in `match`
expressions.

It is also worth noting that this commit managed to hit a bug in Rustc that
was fixed on 10/1/2021.  We use nightly, and it doesn't seem that this
occurred in stable, from bug reports.

  - rust-lang/rust#89393
  - rust-lang/rust@5ab1245
  - Original issue: rust-lang/rust#72476

The error was:

  compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs:1191:22:
  Unexpected type for `Single` constructor: <u32 as sym::symbol::SymbolIndexSize>::NonZero

  thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9

This occurred because we were trying to use `SymbolId` as the type, which
uses a projected type as its inner value: `SymbolId<Ix: SymbolIndexSize>(Ix::NonZero)`.
This was not a problem with the static newtypes because their inner type was
simply `SymbolId<Ix>`, which is not projected.

This is one of the risks of using nightly.

But, the point is: if you receive this error, upgrade your toolchain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns 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.

7 participants