Skip to content

Conversation

@davidtwco
Copy link
Member

@davidtwco davidtwco commented Jul 14, 2025

Supercedes #118917.

Initial experimental implementation of rust-lang/rfcs#3838. Introduces a rustc_scalable_vector(N) attribute that can be applied to types with a single [$ty] field (for u{16,32,64}, i{16,32,64}, f{32,64}, bool). rustc_scalable_vector types are lowered to scalable vectors in the codegen backend.

As with any unstable feature, there will necessarily be follow-ups as we experiment and find cases that we've not considered or still need some logic to handle, but this aims to be a decent baseline to start from.

See #145052 for request for a lang experiment.

@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 14, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@davidtwco davidtwco marked this pull request as draft July 14, 2025 11:21
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 14, 2025
@davidtwco
Copy link
Member Author

I've changed this back to a draft and marked it as S-waiting-on-author while I rebase it and get the approval for an experimental implementation to go ahead.

@davidtwco davidtwco force-pushed the sve-infrastructure branch 2 times, most recently from cf9474d to d58c634 Compare July 14, 2025 11:53
@rust-log-analyzer

This comment was marked as resolved.

@davidtwco davidtwco force-pushed the sve-infrastructure branch 2 times, most recently from 0c22701 to 3ad0898 Compare July 14, 2025 12:12
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@davidtwco davidtwco force-pushed the sve-infrastructure branch from 5c92874 to 3edf1b6 Compare July 14, 2025 13:30
@rust-log-analyzer

This comment has been minimized.

@davidtwco davidtwco force-pushed the sve-infrastructure branch from 3edf1b6 to 4f6b823 Compare July 14, 2025 14:20
Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

I do not intend to have repr(simd) survive this year, so I do not think this should be added.

@davidtwco
Copy link
Member Author

I do not intend to have repr(simd) survive this year, so I do not think this should be added.

Could you elaborate?

@workingjubilee
Copy link
Member

I intend to replace it with an approach based on lang items for a variety of reasons, one of them being that to start with, the repr(simd) "attribute" does not compose and should not.

r? @workingjubilee

@workingjubilee

This comment was marked as outdated.

@davidtwco davidtwco changed the title repr(scalable) rustc_scalable_vector(N) Aug 12, 2025
@davidtwco
Copy link
Member Author

Updated this reflecting changes in rust-lang/rfcs#3838. It doesn't implement everything in it yet, and is definitely incomplete, but it's a starting point.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment was marked as resolved.

Ruanyx1823

This comment was marked as off-topic.

@bors

This comment was marked as resolved.

@ruanyuxin

This comment was marked as outdated.

davidtwco and others added 3 commits November 25, 2025 13:23
Extend parsing of `ReprOptions` with `rustc_scalable_vector(N)` which
optionally accepts a single literal integral value - the base multiple of
lanes that are in a scalable vector. Can only be applied to structs.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
Extend well-formedness checking and HIR analysis to prohibit the use of
scalable vectors in structs, enums, unions, tuples and arrays. LLVM does
not support scalable vectors being members of other types, so these
restrictions are necessary.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
`simd_reinterpret` is a replacement for `transmute`, specifically for
use with scalable SIMD types. It is used in the tests for scalable
vectors and in stdarch.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
@davidtwco
Copy link
Member Author

@workingjubilee are you open to reviewing this so that we can land it as an incomplete feature?

There's clearly still missing bits and ways that one could use the vectors defined using this incorrectly, but it's a lot easier to experiment with solutions and iterate when there's something landed and we can do those experiments in individual PRs. None of the details are set in stone, we're happy to change the attribute name, etc - can discuss some of that on the RFC.

I've rebased and this should pass CI.

cc @Amanieu

@davidtwco davidtwco added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2025
@rust-log-analyzer

This comment has been minimized.

davidtwco and others added 4 commits November 25, 2025 16:52
Introduces `BackendRepr::ScalableVector` corresponding to scalable
vector types annotated with `repr(scalable)` which lowers to a scalable
vector type in LLVM.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
LLVM doesn't handle stores on `<vscale x N x i1>` for `N != 16`, a type
used internally in SVE intrinsics. Spilling to the stack to create
debuginfo will cause errors during instruction selection. These types
that are an internal implementation detail to the intrinsic, so users
should never see them types and won't need any debuginfo.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
Scalable vectors cannot be members of ADTs and thus cannot be kept over
await points in async functions.
Scalable vector types only work with the relevant target features
enabled, so require this for any function with the types in its
signature.
@davidtwco
Copy link
Member Author

davidtwco commented Nov 25, 2025

That test has subtly different output for me locally (it was passing), but none of the differences seem important to so I've added a wildcard for the parts that seem to change.

@workingjubilee
Copy link
Member

@davidtwco Yes, I hadn't prioritized it because it became unclear how many changes it would receive from its then-current draft. As you have addressed my main request that I have seen, I'm happy for this to land in incomplete form. I'll try to take a look soon.

@davidtwco davidtwco marked this pull request as ready for review November 26, 2025 14:28
@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2025

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a

RustcScalableVector {
/// The base multiple of lanes that are in a scalable vector, if provided. `element_count`
/// is not provided for representing tuple types.
element_count: Option<u128>,
Copy link
Contributor

Choose a reason for hiding this comment

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

The size of Attribute jumps from 200 to 240. Probably worth boxing this to avoid that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants