rust-lang / rust-lang/rust

ICE: gce: `fn_abi_of_instance(..) failed: Layout(Unknown([FlatTree; UnevaluatedConst { .. }: usize]))`

Open
#118,603 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Code
#![feature(generic_const_exprs)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct FlatTree;

#[derive(Copy, Clone)]
struct TreeLeaf;

#[derive(Copy, Clone)]
struct TreeNode<V, W>(V, W);

const fn const_concat<const A: usize, const B: usize>(_: [FlatTree; A], _: [FlatTree; B]) -> [FlatTree; A + B] {
    [FlatTree; A + B]
}

struct Builder<const N: usize, I> {
    ops: [FlatTree; N],
    builder: I,
}

fn create_node<const N: usize, const M: usize, A, B>(a: Builder<N, A>, b: Builder<M, B>) -> Builder<{ N + M + 1 }, TreeNode<A, B>> {
    Builder {
        ops: const_concat(const_concat::<N, M>(a.ops, b.ops), [FlatTree]),
        builder: TreeNode(a.builder, b.builder),
    }
}

const LEAF: Builder<1, TreeLeaf> = Builder {
    ops: [FlatTree],
    builder: TreeLeaf,
};

static INTERNAL_SIMPLE_BOOLEAN_TEMPLATES: &[fn()] = &[{
    fn eval() {
        create_node(LEAF, create_node(LEAF, LEAF));
    }

    eval
}];
Meta

rustc --version --verbose:

rustc 1.76.0-nightly (9fad68599 2023-12-03)
binary: rustc
commit-hash: 9fad6859925b34f9a0b1af592a7839ccb1e71f60
commit-date: 2023-12-03
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5
Error output
   Compiling minimal-rust v0.1.0 (/home/../workspace/repro/minimal-rust)
[..] (warnings removed)
error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1043:21: `fn_abi_of_instance(const_concat::<{const expr}, 1>, [])` failed: Layout(Unknown([FlatTree; UnevaluatedConst { def: DefId(0:8 ~ minimal_rust[599e]::const_concat::{constant#2}), args: [(Add: 1_usize, 3_usize): usize, 1_usize] }: usize]))
  --> minimal-rust/src/lib.rs:11:1
   |
11 | const fn const_concat<const A: usize, const B: usize>(_: [FlatTree; A], _: [FlatTree; B]) -> [FlatTree; A + B] {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at /rustc/9fad6859925b34f9a0b1af592a7839ccb1e71f60/compiler/rustc_errors/src/lib.rs:995:33:
Box<dyn Any>


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 `/home/../workspace/repro/rustc-ice-2023-12-04T12_27_11-290639.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=2 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C incremental=[REDACTED]

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

query stack during panic:
end of query stack
warning: `minimal-rust` (lib) generated 6 warnings
error: could not compile `minimal-rust` (lib); 6 warnings emitted
Backtrace


thread 'rustc' panicked at /rustc/9fad6859925b34f9a0b1af592a7839ccb1e71f60/compiler/rustc_errors/src/lib.rs:995:33:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   2: <rustc_errors::Handler>::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_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
   8: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::FnAbiOf>::fn_abi_of_instance::{closure#0}
   9: <rustc_codegen_llvm::context::CodegenCx as rustc_codegen_ssa::traits::declare::PreDefineMethods>::predefine_fn
  10: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  11: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  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}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the supplied minimal example with the reported rustc version and inspect compiler/rustc_codegen_llvm/src/context.rs around handle_fn_abi_err. Follow the fn_abi_of_instance and predefine_fn codegen path shown in the backtrace. Done means this example no longer produces an internal compiler error and receives appropriate compiler handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.