Skip to content

simd_shuffle, simd_insert, simd_extract should use const generics #85229

Open
@RalfJung

Description

@RalfJung

simd_shuffle requires its last parameter, the array defining the shuffling, to be a constant:

emit_error!("shuffle index #{} is not a constant", arg_idx);

Currently (after #85110), this is enforced by an ad-hoc hack in compiler/rustc_mir/src/transform/lower_intrinsics.rs.

But I think it'd be better to instead change the type of simd_shuffle to make the shuffle array a const generic parameter. I am not doing this yet since const generic arrays require enabling an incomplete_feature which is not great, but once const generic arrays are sufficiently stable we could use them as a more principled way to ensure that simd_shuffle is called in the right way.

Update (2024-02-17): A const-generic version of simd_shuffle now exists, but using it in stdarch would require generic_const_exprs and that's too experimental for such uses.

Cc @rust-lang/project-const-generics

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-SIMDArea: SIMD (Single Instruction Multiple Data)A-const-genericsArea: const generics (parameters and arguments)A-intrinsicsArea: IntrinsicsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions