Skip to content

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

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

Open
jxors opened this issue Dec 4, 2023 · 4 comments
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@jxors
Copy link

jxors commented Dec 4, 2023

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}

@jxors jxors 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 4, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 4, 2023
@jxors
Copy link
Author

jxors commented Dec 4, 2023

cargo-bisect-rustc suggests a regression between 2022-11-26 (8681d4c) and 2022-11-27 (80a9646):

finding bors merge commits
found 8 bors merge commits in the specified range
  commit[0] 2022-11-25: Auto merge of #104902 - matthiaskrgr:rollup-oo27a4u, r=matthiaskrgr
  commit[1] 2022-11-25: Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU
  commit[2] 2022-11-26: Auto merge of #104431 - alistair23:alistair/rv64-profiler, r=Mark-Simulacrum
  commit[3] 2022-11-26: Auto merge of #104730 - petrochenkov:modchild5, r=cjgillot
  commit[4] 2022-11-26: Auto merge of #103556 - clubby789:specialize-option-partial-eq, r=scottmcm
  commit[5] 2022-11-26: Auto merge of #104935 - matthiaskrgr:rollup-nuca86l, r=matthiaskrgr
  commit[6] 2022-11-26: Auto merge of #104731 - compiler-errors:early-binder-iter-size-hint, r=cjgillot
  commit[7] 2022-11-26: Auto merge of #104945 - GuillaumeGomez:rollup-ygzbpbe, r=GuillaumeGomez
ERROR: no CI builds available between 8681d4cffcd23bbe619984ab62772a91827a40dc and 80a96467ec5675e9f69683b5c075a8b15950c341 within last 167 days

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 7, 2023
@Luk-ESC
Copy link
Contributor

Luk-ESC commented Dec 29, 2023

Minimized:

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

struct Yo<const N: usize>;

const fn add<const A: usize, const B: usize>(_: Yo<A>, _: Yo<B>) -> Yo<{ A + B }> {
    Yo::<{ A + B }>
}

fn create_node<const N: usize>() -> Yo<{ N + N + 1 }> {
    add(add(Yo::<N>, Yo::<N>), Yo::<1>)
}


fn main(){
    create_node::<42>();
}

EDIT: The above is actually a different ICE, but you can get the old one by replacing Yo<N> with [(); N]:

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

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

fn create_node<const N: usize>() -> [(); N + N + 1] {
    add(add([(); N], [(); N]), [(); 1])
}


fn main(){
    create_node::<42>();
}

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@compiler-errors
Copy link
Member

No longer ICEs because we added the necessary normalization I think recently?

@rustbot label: E-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 3, 2025
@jxors
Copy link
Author

jxors commented Jan 9, 2025

On 1.86.0-nightly (a580b5c37 2025-01-08 it now crashes with:

/rustc/a580b5c379b4fca50dfe5afc0fc0ce00921e4e00/compiler/rustc_middle/src/mir/consts.rs:333:25: Normalization of `ty::ConstKind::Expr` is unimplemented

Edit: #132960 is related or possibly a duplicate

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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

6 participants