Skip to content

mir: prohibit projection into scalable vec - #160642

Open
davidtwco wants to merge 1 commit into
rust-lang:mainfrom
davidtwco:sve-field-projection
Open

mir: prohibit projection into scalable vec#160642
davidtwco wants to merge 1 commit into
rust-lang:mainfrom
davidtwco:sve-field-projection

Conversation

@davidtwco

@davidtwco davidtwco commented Aug 6, 2026

Copy link
Copy Markdown
Member

View all comments

Fixes #160580. Preventing projections into scalable vectors is an oversight from the initial implementation and something we should fix.

I'm surprised it caused a stdarch CI failure as reported by #160580, as nothing in rustc or stdarch seems to have changed that would have caused that to start happening as far as I can tell. This likely won't fix that stdarch CI failure if it keeps happening, because if there is a projection coming from somewhere then that needs to be fixed - nevertheless, preventing them as in this patch is the right thing to do.

I've tested this against the stdarch CI locally.

@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2026
@rustbot rustbot added 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. labels Aug 6, 2026
@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 16 candidates

@davidtwco

Copy link
Copy Markdown
Member Author

r? @folkertdev

@rustbot rustbot assigned folkertdev and unassigned TaKO8Ki Aug 6, 2026
//@ compile-flags: --target aarch64-unknown-linux-gnu -Copt-level=0
//@ check-fail
//@ needs-llvm-components: aarch64
//@ only-aarch64

@oli-obk oli-obk Aug 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the --target and needs-llvm-components necessary when it's already restricted to aarch64?

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

going in the other direction, I think this can be a minicore test?

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.

is the --target and needs-llvm-components necessary when it's already restricted to aarch64?

are you suggesting to remove both? (if you have a test with a --target, tidy will require needs-llvm-components)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But combining //@ only-aarch64 with compile-flags: --target aarch64-unknown-linux-gnu doesn't really make sense I think?

Anyhow, this should be a minicore test so it run everywhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed --target and needs-llvm-components, added minicore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, I meant to keep --target and needs-llvm-components in combination with minicore, so that this test runs even on my x86_64 machine. The logic here isn't os-specific, so defaulting to aarch64-unknown-linux-gnu should be fine. It's the only-aarch64 that should go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, fixed

Comment thread library/stdarch/crates/core_arch/src/aarch64/sve/mod.rs
Comment thread compiler/rustc_hir_typeck/src/expr.rs Outdated
@workingjubilee

Copy link
Copy Markdown
Member

cc @scottmcm Since you worked on prohibiting similar projections in the past.

@davidtwco
davidtwco force-pushed the sve-field-projection branch from 303387d to 168f22f Compare August 7, 2026 08:55
@davidtwco

davidtwco commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

cc @scottmcm Since you worked on prohibiting similar projections in the past.

I looked at #143833 while doing this - the rustc_mir_transform/src/validate.rs change is the same, not strictly necessary in my patch but gives a more deliberate ICE than the previous one as a fallback, but I didn't think the rustc_codegen_ssa/src/mir/operand.rs change was relevant here. I went further than that patch with the rustc_hir_typeck change to give a nicer error than the MIR validation one.


#[derive(Diagnostic)]
#[diag("cannot project into scalable vector type `{$ty}`")]
pub(crate) struct ScalableVectorFieldAccess<'tcx> {

@scottmcm scottmcm Aug 7, 2026

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.

Are you expecting scalable vectors to be something that people can mess up like this outside of the library? We intentionally just ICE under rust-lang/compiler-team#620 for the misuses of repr(simd).

(The tricky cases were things that didn't have a great place in the code to point at.)

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, that makes sense, I hadn't considered that the visibility errors would prevent field access normally, so this was really only for direct uses of rustc_scalable_vector, so the MIR validator error is sufficient - removed the typeck error.

}

if adt_def.repr().simd() {
if adt_def.repr().simd() || adt_def.repr().scalable() {

@scottmcm scottmcm Aug 7, 2026

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.

Would it worth having a negative test that mir-opt SRoA doesn't try to explode one of these, or similar?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added one now

@davidtwco
davidtwco force-pushed the sve-field-projection branch from 168f22f to c1f9520 Compare August 7, 2026 11:54
@davidtwco davidtwco changed the title hir_typeck: prohibit projection into scalable vec mir: prohibit projection into scalable vec Aug 7, 2026
@davidtwco
davidtwco force-pushed the sve-field-projection branch from c1f9520 to ae4a53f Compare August 7, 2026 11:58

@folkertdev folkertdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, r=me when CI is green.

View changes since this review

@rust-log-analyzer

This comment was marked as resolved.

@davidtwco
davidtwco force-pushed the sve-field-projection branch from ae4a53f to 8574222 Compare August 7, 2026 12:39
@rust-log-analyzer

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor

Hmm i've been running into this too. Tidy already lints on tests having --target without an llvm component, maybe it can also lint on whether the target is available with gcc and error when it's not and suggest to ignore gcc.

@davidtwco
davidtwco force-pushed the sve-field-projection branch from 8574222 to 0e878d6 Compare August 7, 2026 14:59
@folkertdev

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0e878d6 has been approved by folkertdev

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 7, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 7, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 8, 2026
…folkertdev

mir: prohibit projection into scalable vec

Fixes rust-lang#160580. Preventing projections into scalable vectors is an oversight from the initial implementation and something we should fix.

I'm surprised it caused a stdarch CI failure as reported by rust-lang#160580, as nothing in rustc or stdarch seems to have changed that would have caused that to start happening as far as I can tell. This likely won't fix that stdarch CI failure if it keeps happening, because if there is a projection coming from somewhere then that needs to be fixed - nevertheless, preventing them as in this patch is the right thing to do.

I've tested this against the stdarch CI locally.
rust-bors Bot pushed a commit that referenced this pull request Aug 8, 2026
Rollup of 5 pull requests

Successful merges:

 - #160634 (miri subtree update)
 - #160642 (mir: prohibit projection into scalable vec)
 - #160303 (rustc_parse: A few cleanups to expression parsing next to attributes)
 - #160429 (tidy: Update Python version requirements to 3.10)
 - #160543 (Default `RawOsError` to `i16` for 16-bit targets)
extern crate minicore;

#[rustc_scalable_vector(4)]
pub struct Sv(f32);

@jhpratt jhpratt Aug 8, 2026

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.

This needs to silence a lint.

@bors r- #160735 (comment)

---- [ui] tests/ui/scalable-vectors/project-into-field-extern.rs stdout ----

error: auxiliary build of /Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs failed to compile: 
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2/bin/rustc" "/Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/runner/work/rust/rust/vendor" "--sysroot" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage2" "--target=aarch64-apple-darwin" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "--out-dir" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "-Cpanic=abort" "-Cforce-unwind-tables=yes" "-Copt-level=0" "--crate-type" "dylib" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "--extern" "minicore=/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/libminicore.rlib"
stdout: none
--- stderr -------------------------------
warning: field `0` is never read
##[warning]  --> /Users/runner/work/rust/rust/tests/ui/scalable-vectors/auxiliary/simple.rs:13:15
   |
LL | pub struct Sv(f32);
   |            -- ^^^
   |            |
   |            field in this struct
   |
   = help: consider removing this field
   = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

error: linking with `cc` failed: exit status: 1
   |
   = note:  "cc" "-Wl,-exported_symbols_list" "-Wl,/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/list" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/symbols.o" "<1 object files omitted>" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/rustcnDOBCi/rmeta.o" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/libminicore.rlib" "-arch" "arm64" "-mmacosx-version-min=11.0.0" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/native/rust-test-helpers" "-L" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary" "-o" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/ui/scalable-vectors/project-into-field-extern/auxiliary/libsimple.dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-install_name" "-Wl,@rpath/libsimple.dylib" "-nodefaultlibs"
   = note: some arguments are omitted. use `--verbose` to show all linker arguments
   = note: Undefined symbols for architecture arm64:
             "dyld_stub_binder", referenced from:
                 <initial-undefines>
           ld: symbol(s) not found for architecture arm64
           clang: error: linker command failed with exit code 1 (use -v to see invocation)
           

error: aborting due to 1 previous error; 1 warning emitted
------------------------------------------

View changes since the review

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 8, 2026
@rust-bors

rust-bors Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#160735), which was unapproved.

View changes since this unapproval

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: Scalable vectors hit an assert in mir/operand.rs

10 participants