Skip to content
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

rustc struggles to recognize legal vectors-of-pointers #85915

Closed
workingjubilee opened this issue Jun 1, 2021 · 0 comments · Fixed by #85919
Closed

rustc struggles to recognize legal vectors-of-pointers #85915

workingjubilee opened this issue Jun 1, 2021 · 0 comments · Fixed by #85919
Labels
A-simd Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug.

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Jun 1, 2021

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

match e.kind() {
ty::Param(_) => { /* struct<T>(T, T, T, T) is ok */ }
_ if e.is_machine() => { /* struct(u8, u8, u8, u8) is ok */ }
ty::Array(ty, _c) if ty.is_machine() => { /* struct([f32; 4]) */ }
_ => {
struct_span_err!(

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).

@workingjubilee workingjubilee added A-simd Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. labels Jun 1, 2021
@bors bors closed this as completed in 4e20754 Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-simd Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant