Description
rustc has trouble recognizing legal {tuples,arrays} of pointers for #[repr(simd)]
to use.
What Does Work
The following is an example of a vector-of-pointers type that works.
#![feature(repr_simd)]
#[derive(Copy, Clone, Debug)]
#[repr(simd)]
pub struct ptrx2<T>(T, T);
fn main() {
let v = vec![2, 3, 4];
let x = ptrx2(v.as_ptr(), v.as_ptr());
}
Note that the pointer-ness here is only determined during monomorphization. This does not follow the same pattern as e.g. *const T
being parameterized over <T>
.
What Does Not Work
Attempts to define things like these give me errors.
#[repr(simd)]
pub struct ptrx2<T>(*const T, *const T);
or, in particular, the inciting incident:
#[repr(simd)]
struct SimdConst<T, const LANES: usize>([*const T; LANES]);
I expected rustc to recognize a legal definition of a vector-of-pointers and proceed to monomorphize it.
Instead, this happened:
error[E0077]: SIMD vector element type should be a primitive scalar (integer/float/pointer) type
--> crates\core_simd\src\array.rs:76:1
|
76 | struct SimdConst<T, const LANES: usize>([*const T; LANES]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Meta
rustc --version --verbose
:
rustc 1.54.0-nightly (9111b8ae9 2021-05-26)
binary: rustc
commit-hash: 9111b8ae9793f18179a1336417618fc07a9cac85
commit-date: 2021-05-26
host: x86_64-pc-windows-msvc
release: 1.54.0-nightly
LLVM version: 12.0.1
Likely Causes
This is likely caused by the clauses in
rust/compiler/rustc_typeck/src/check/check.rs
Lines 1217 to 1222 in 7f9ab03
A parameter is accepted, but not a pointer, even though &T
and *const T
(but not &[T]
or fn() -> ()
) are valid inputs to that parameter (i.e. they monomorphize successfully).