rust-lang / rust-lang/rust

ICE: `expected SIMD field to have definite array size`

Open
#137,291 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-SIMD C-bug I-ICE T-compiler WG-const-eval
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This example hits an ICE. The area around the error message provides some context

https://github.com/rust-lang/rust/blob/ed49386d3aa3a445a9889707fd405df01723eced/compiler/rustc_middle/src/ty/sty.rs#L1175-L1185

cc https://github.com/rust-lang/rust/pull/78863#discussion_r522784112

So, this is sort of expected. Maybe there is a more complete way of getting that length 5 years later?

Context: I'm trying to use this in the stdarch implementation of s390x vector intrinsics. The test function below is actually in a macro, hence the calculation of N that might look a bit weird at first glance.

Code
#![feature(portable_simd, repr_simd, core_intrinsics)]

#[derive(Debug, Clone, Copy)]
#[repr(simd)]
struct vector_signed_int([i32; 4]);

#[no_mangle]
unsafe fn test(a: vector_signed_int) -> vector_signed_int {
    const N: usize = core::mem::size_of::<vector_signed_int>() / core::mem::size_of::<i32>();

    #[repr(simd)]
    struct Helper([u32; N]);

    const INDEX: Helper = const {
        let mut index = [0; N];
        let mut i = 0;
        while i < N {
            index[i] = (N - i - 1) as u32;
            i += 1;
        }
        Helper(index)
    };

    core::intrinsics::simd::simd_shuffle(a, a, INDEX)
}

fn main() {}
Meta

rustc --version --verbose:

rustc 1.86.0-nightly (ef148cd7e 2025-02-12)
binary: rustc
commit-hash: ef148cd7eb00a5a973130dc6473da71fd6c487ee
commit-date: 2025-02-12
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Error output
<none>
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:1182:18:
expected SIMD field to have definite array size
stack backtrace:
   0:     0x7bd140b7bc65 - std::backtrace::Backtrace::create::hbb6ec95241d4d0ca
   1:     0x7bd13f03c875 - std::backtrace::Backtrace::force_capture::h28bcc72d9be8b631
   2:     0x7bd13e1b45b4 - std[633b0bd6f2fb4ba3]::panicking::update_hook::<alloc[6f8679578b5d1085]::boxed::Box<rustc_driver_impl[da41d138b3cf9bec]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x7bd13f054ff3 - std::panicking::rust_panic_with_hook::h8a1db2c7a950f63a
   4:     0x7bd13f054cea - std::panicking::begin_panic_handler::{{closure}}::hd4ae0500663b7b24
   5:     0x7bd13f052679 - std::sys::backtrace::__rust_end_short_backtrace::h830be9a18b3fa6b1
   6:     0x7bd13f0549ad - rust_begin_unwind
   7:     0x7bd13bc415b0 - core::panicking::panic_fmt::h019406d7deaf35a5
   8:     0x7bd13cdf17db - core::option::expect_failed::hca492385653fd117
   9:     0x7bd14136fb19 - <rustc_middle[644c635b116d1ee0]::ty::Ty>::simd_size_and_type.cold
  10:     0x7bd13fd71790 - <rustc_codegen_ssa[c9f50b7cd58b52ea]::mir::FunctionCx<rustc_codegen_llvm[58eb01b1dd183b6b]::builder::GenericBuilder<rustc_codegen_llvm[58eb01b1dd183b6b]::context::CodegenCx>>>::codegen_operand
  11:     0x7bd14045574d - rustc_codegen_ssa[c9f50b7cd58b52ea]::mir::codegen_mir::<rustc_codegen_llvm[58eb01b1dd183b6b]::builder::GenericBuilder<rustc_codegen_llvm[58eb01b1dd183b6b]::context::CodegenCx>>
  12:     0x7bd14042a0c8 - rustc_codegen_llvm[58eb01b1dd183b6b]::base::compile_codegen_unit::module_codegen
  13:     0x7bd1406c7fae - <rustc_codegen_llvm[58eb01b1dd183b6b]::LlvmCodegenBackend as rustc_codegen_ssa[c9f50b7cd58b52ea]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  14:     0x7bd1406c3e97 - rustc_codegen_ssa[c9f50b7cd58b52ea]::base::codegen_crate::<rustc_codegen_llvm[58eb01b1dd183b6b]::LlvmCodegenBackend>
  15:     0x7bd1406c322f - <rustc_codegen_llvm[58eb01b1dd183b6b]::LlvmCodegenBackend as rustc_codegen_ssa[c9f50b7cd58b52ea]::traits::backend::CodegenBackend>::codegen_crate
  16:     0x7bd1408201f4 - <rustc_interface[4d9624c47f887345]::queries::Linker>::codegen_and_build_linker
  17:     0x7bd1408181df - rustc_interface[4d9624c47f887345]::passes::create_and_enter_global_ctxt::<core[897dc7c96c0db261]::option::Option<rustc_interface[4d9624c47f887345]::queries::Linker>, rustc_driver_impl[da41d138b3cf9bec]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  18:     0x7bd140778e9c - rustc_interface[4d9624c47f887345]::interface::run_compiler::<(), rustc_driver_impl[da41d138b3cf9bec]::run_compiler::{closure#0}>::{closure#1}
  19:     0x7bd1406ea404 - std[633b0bd6f2fb4ba3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4d9624c47f887345]::util::run_in_thread_with_globals<rustc_interface[4d9624c47f887345]::util::run_in_thread_pool_with_globals<rustc_interface[4d9624c47f887345]::interface::run_compiler<(), rustc_driver_impl[da41d138b3cf9bec]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  20:     0x7bd1406ea0d9 - <<std[633b0bd6f2fb4ba3]::thread::Builder>::spawn_unchecked_<rustc_interface[4d9624c47f887345]::util::run_in_thread_with_globals<rustc_interface[4d9624c47f887345]::util::run_in_thread_pool_with_globals<rustc_interface[4d9624c47f887345]::interface::run_compiler<(), rustc_driver_impl[da41d138b3cf9bec]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[897dc7c96c0db261]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x7bd1406e986f - std::sys::pal::unix::thread::Thread::new::thread_start::h9cc83cf24679d9ac
  22:     0x7bd13a69ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  23:     0x7bd13a729c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
  24:                0x0 - <unknown>


rustc version: 1.86.0-nightly (ef148cd7e 2025-02-12)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

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

Reproduce the provided SIMD example, then read compiler/rustc_middle/src/ty/sty.rs around lines 1175-1185 and follow Ty::simd_size_and_type in the backtrace. Investigate how the const-generic SIMD array length is handled; done means the example no longer triggers the compiler panic and its behavior is covered by appropriate compiler testing.

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
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.