Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,11 +1371,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
ItemKind::Struct(ident, generics, vdata) => {
self.with_tilde_const(Some(TildeConstReason::Struct { span: item.span }), |this| {
// Scalable vectors can only be tuple structs
let is_scalable_vector =
item.attrs.iter().any(|attr| attr.has_name(sym::rustc_scalable_vector));
if is_scalable_vector && !matches!(vdata, VariantData::Tuple(..)) {
this.dcx()
.emit_err(errors::ScalableVectorNotTupleStruct { span: item.span });
let scalable_vector_attr =
item.attrs.iter().find(|attr| attr.has_name(sym::rustc_scalable_vector));
if let Some(attr) = scalable_vector_attr {
if !matches!(vdata, VariantData::Tuple(..)) {
this.dcx()
.emit_err(errors::ScalableVectorNotTupleStruct { span: item.span });
}
if !self.sess.target.arch.supports_scalable_vectors() {
this.dcx().emit_err(errors::ScalableVectorBadArch { span: attr.span });
}
}

match vdata {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,10 @@ pub(crate) struct ScalableVectorNotTupleStruct {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("scalable vectors are not supported on this architecture")]
pub(crate) struct ScalableVectorBadArch {
#[primary_span]
pub span: Span,
}
13 changes: 13 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,19 @@ impl Arch {
| X86_64 | Xtensa => true,
}
}

/// Whether `#[rustc_scalable_vector]` is supported for a target architecture
pub fn supports_scalable_vectors(&self) -> bool {
use Arch::*;

match self {
AArch64 | RiscV32 | RiscV64 => true,
AmdGpu | Arm | Arm64EC | Avr | Bpf | CSky | Hexagon | LoongArch32 | LoongArch64
| M68k | Mips | Mips32r6 | Mips64 | Mips64r6 | Msp430 | Nvptx64 | PowerPC
| PowerPC64 | S390x | Sparc | Sparc64 | SpirV | Wasm32 | Wasm64 | X86 | X86_64
| Xtensa | Other(_) => false,
}
}
}

crate::target_spec_enum! {
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/directives/directive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"ignore-powerpc",
"ignore-powerpc64",
"ignore-remote",
"ignore-riscv32",
"ignore-riscv64",
"ignore-rustc-debug-assertions",
"ignore-rustc_abi-x86-sse2",
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/scalable-vectors/bad-architectures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ ignore-aarch64
//@ ignore-riscv32
//@ ignore-riscv64

// Confirm that non-AArch64 and non-RISC-V targets error when compiling scalable vectors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we just mention #153593 here

// (see #153593)

#![crate_type = "lib"]
#![feature(rustc_attrs)]

#[rustc_scalable_vector(4)]
//~^ ERROR: scalable vectors are not supported on this architecture
struct ScalableVec(i32);
8 changes: 8 additions & 0 deletions tests/ui/scalable-vectors/bad-architectures.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: scalable vectors are not supported on this architecture
--> $DIR/bad-architectures.rs:11:1
|
LL | #[rustc_scalable_vector(4)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

1 change: 1 addition & 0 deletions tests/ui/scalable-vectors/fn-trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ only-aarch64
#![allow(internal_features)]
#![feature(rustc_attrs)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/scalable-vectors/fn-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: scalable vectors cannot be tuple fields
--> $DIR/fn-trait.rs:9:8
--> $DIR/fn-trait.rs:10:8
|
LL | T: Fn(ScalableSimdFloat),
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ only-aarch64
#![allow(incomplete_features, internal_features)]
#![feature(rustc_attrs)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: scalable vector types cannot be initialised using their constructor
--> $DIR/illegal_init.rs:8:15
--> $DIR/illegal-init.rs:9:15
|
LL | let foo = svint32_t(1);
| ^^^^^^^^^ you can create scalable vectors using intrinsics
Expand Down
1 change: 1 addition & 0 deletions tests/ui/scalable-vectors/illformed-element-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: --crate-type=lib
//@ only-aarch64
#![allow(internal_features)]
#![feature(extern_types)]
#![feature(never_type)]
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/scalable-vectors/illformed-element-type.stderr
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:15:1
--> $DIR/illformed-element-type.rs:16:1
|
LL | struct TyChar(char);
| ^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:19:1
--> $DIR/illformed-element-type.rs:20:1
|
LL | struct TyConstPtr(*const u8);
| ^^^^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:23:1
--> $DIR/illformed-element-type.rs:24:1
|
LL | struct TyMutPtr(*mut u8);
| ^^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:27:1
--> $DIR/illformed-element-type.rs:28:1
|
LL | struct TyStruct(Foo);
| ^^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:31:1
--> $DIR/illformed-element-type.rs:32:1
|
LL | struct TyEnum(Bar);
| ^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:35:1
--> $DIR/illformed-element-type.rs:36:1
|
LL | struct TyUnion(Baz);
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:39:1
--> $DIR/illformed-element-type.rs:40:1
|
LL | struct TyForeign(Qux);
| ^^^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:43:1
--> $DIR/illformed-element-type.rs:44:1
|
LL | struct TyArray([u32; 4]);
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:47:1
--> $DIR/illformed-element-type.rs:48:1
|
LL | struct TySlice([u32]);
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:51:1
--> $DIR/illformed-element-type.rs:52:1
|
LL | struct TyRef<'a>(&'a u32);
| ^^^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:55:1
--> $DIR/illformed-element-type.rs:56:1
|
LL | struct TyFnPtr(fn(u32) -> u32);
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:59:1
--> $DIR/illformed-element-type.rs:60:1
|
LL | struct TyDyn(dyn std::io::Write);
| ^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:63:1
--> $DIR/illformed-element-type.rs:64:1
|
LL | struct TyNever(!);
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:67:1
--> $DIR/illformed-element-type.rs:68:1
|
LL | struct TyTuple((u32, u32));
| ^^^^^^^^^^^^^^
|
= help: only `u*`, `i*`, `f*` and `bool` types are accepted

error: element type of a scalable vector must be a primitive scalar
--> $DIR/illformed-element-type.rs:77:1
--> $DIR/illformed-element-type.rs:78:1
|
LL | struct TyInvalidAlias(InvalidAlias);
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: --crate-type=lib
//@ only-aarch64
#![allow(internal_features)]
#![feature(rustc_attrs)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error: scalable vectors must be tuple structs
--> $DIR/illformed-tuples-of-scalable-vectors.rs:15:1
--> $DIR/illformed-tuples-of-scalable-vectors.rs:16:1
|
LL | struct Struct { x: ValidI64, y: ValidI64 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: all fields in a scalable vector struct must be the same type
--> $DIR/illformed-tuples-of-scalable-vectors.rs:19:39
--> $DIR/illformed-tuples-of-scalable-vectors.rs:20:39
|
LL | struct DifferentVectorTypes(ValidI64, ValidI32);
| ^^^^^^^^

error: scalable vector structs can only have scalable vector fields
--> $DIR/illformed-tuples-of-scalable-vectors.rs:23:23
--> $DIR/illformed-tuples-of-scalable-vectors.rs:24:23
|
LL | struct NonVectorTypes(u32, u64);
| ^^^

error: scalable vector structs can only have scalable vector fields
--> $DIR/illformed-tuples-of-scalable-vectors.rs:27:32
--> $DIR/illformed-tuples-of-scalable-vectors.rs:28:32
|
LL | struct DifferentNonVectorTypes(u32, u64);
| ^^^

error: scalable vector structs can only have scalable vector fields
--> $DIR/illformed-tuples-of-scalable-vectors.rs:31:34
--> $DIR/illformed-tuples-of-scalable-vectors.rs:32:34
|
LL | struct SomeVectorTypes(ValidI64, u64);
| ^^^

error: scalable vector structs cannot contain other scalable vector structs
--> $DIR/illformed-tuples-of-scalable-vectors.rs:35:20
--> $DIR/illformed-tuples-of-scalable-vectors.rs:36:20
|
LL | struct NestedTuple(ValidTuple, ValidTuple);
| ^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions tests/ui/scalable-vectors/illformed-within-types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: --crate-type=lib
//@ only-aarch64
#![allow(internal_features)]
#![feature(rustc_attrs)]

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/scalable-vectors/illformed-within-types.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error: scalable vectors cannot be fields of a struct
--> $DIR/illformed-within-types.rs:9:8
--> $DIR/illformed-within-types.rs:10:8
|
LL | x: ValidI64,
| ^^^^^^^^

error: scalable vectors cannot be tuple fields
--> $DIR/illformed-within-types.rs:11:15
--> $DIR/illformed-within-types.rs:12:15
|
LL | in_tuple: (ValidI64,),
| ^^^^^^^^^^^

error: scalable vectors cannot be fields of a struct
--> $DIR/illformed-within-types.rs:15:20
--> $DIR/illformed-within-types.rs:16:20
|
LL | struct TupleStruct(ValidI64);
| ^^^^^^^^

error: scalable vectors cannot be fields of a variant
--> $DIR/illformed-within-types.rs:19:26
--> $DIR/illformed-within-types.rs:20:26
|
LL | StructVariant { _ty: ValidI64 },
| ^^^^^^^^

error: scalable vectors cannot be fields of a variant
--> $DIR/illformed-within-types.rs:21:18
--> $DIR/illformed-within-types.rs:22:18
|
LL | TupleVariant(ValidI64),
| ^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions tests/ui/scalable-vectors/illformed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: --crate-type=lib
//@ only-aarch64
#![allow(internal_features)]
#![feature(rustc_attrs)]

Expand Down
Loading
Loading