Skip to content

Conversation

@sayantn
Copy link
Contributor

@sayantn sayantn commented Dec 4, 2025

recently most SIMD intrinsics were made available in const contexts in #147521. This PR makes the indirectly stable to use in const contexts.

cc @RalfJung @rust-lang/lang @rust-lang/wg-const-eval

This exposes most SIMD intrinsics to be used in stable const functions, except for the following

  • simd_f{min,max} and simd_reduce_{min,max}: See @RalfJung's comment
  • simd_reduce_{add,mul}_unordered: These are not even const yet, due to concerns about possible unsoundness due to non-determinism in float operations
  • simd_expose_provenance: Rust doesn't allow ptr->int casts in const code yet
  • simd_relaxed_fma: Same nondet concerns, also the scalar version fmuladd is not even indirectly stable yet
  • simd_f{sin,cos,exp,exp2,log10,log2,log}: Not const yet

These all have const tests in tests/ui/simd (added in #147521), and some of these are currently also being tested in x86 stdarch (we have already converted some intrinsics to be available in const, and the stdarch testsuite automatically tests the const code).

I want to emphasize that I am not aiming to stabilize any of the const stdarch intrinsics in near future. The reason being that it is difficult to fix perf regressions in generic SIMD code (normally stdarch uses LLVM intrinsics, but we are aiming to convert as many as possible to generic SIMD. Unfortunately that sometimes leads to perf regressions, which might force us to go back to LLVM intrinsics). There is const_eval_select, but it is still a pain to use (considering that we have to ensure that the 2 alternatives behave identically to be sound). A recent such problem surfaced in #150560, and fixed in rust-lang/stdarch#1985.

@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

⚠️ #[rustc_intrinsic_const_stable_indirect] controls whether intrinsics can be exposed to stable const
code; adding it needs t-lang approval.

cc @rust-lang/wg-const-eval

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 platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

r? @joboet

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

@RalfJung
Copy link
Member

RalfJung commented Dec 4, 2025

So you plan to soon const-stabilize functions using these intrinsics?

@sayantn
Copy link
Contributor Author

sayantn commented Dec 4, 2025

I won't say soon (it would require t-libs-api approval), but yes the plan is eventually to stabilize them

@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Dec 5, 2025
@RalfJung
Copy link
Member

RalfJung commented Dec 5, 2025

Usually we do the t-lang FCP for const intrinsics as part of that stabilization, not preemptively.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

For some of these I am not sure they are ready for stabilization.

Also, please give an overview of the test coverage we have for these being invoked from const-eval.

View changes since this review

@joboet
Copy link
Member

joboet commented Dec 5, 2025

r? @RalfJung
I'm really not sure who normally handles these PRs, feel free to reassign as necessary.

@rustbot rustbot assigned RalfJung and unassigned joboet Dec 5, 2025
@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Dec 5, 2025
@RalfJung
Copy link
Member

@rustbot author
based on the comments above

I would propose to remove all controversial cases, then we can proceed to FCP.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 20, 2025
@sayantn
Copy link
Contributor Author

sayantn commented Jan 3, 2026

Apologize for the delay. @RalfJung do the above-mentioned caveats also apply to simd_fmax and simd_fmin?

@RalfJung
Copy link
Member

RalfJung commented Jan 4, 2026

Yeah, they do.

@sayantn sayantn force-pushed the const-stable-indirect branch from 9a84c00 to a87092b Compare January 5, 2026 14:07
@rustbot

This comment has been minimized.

@sayantn
Copy link
Contributor Author

sayantn commented Jan 5, 2026

@rustbot ready

I have removed the attributes from simd_reduce_{min,max}, simd_f{max,min} and simd_relaxed_fma.

@rustbot rustbot 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 Jan 5, 2026
@RalfJung RalfJung added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jan 5, 2026
@RalfJung
Copy link
Member

RalfJung commented Jan 5, 2026

I have nominated this for t-lang discussion. It'd be good to update the PR description to give the required context to team members visiting this during triage: which new capabilities are exposed to const code here, and what does the test coverage look like?

@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Jan 5, 2026
@joshtriplett
Copy link
Member

Summary: this makes it possible for functions that indirectly call these SIMD intrinsics to be called from stable const-eval code.

The lang decision when things are marked as rustc_intrinsic_const_stable_indirect is to review what new language capabilities are exposed to const evaluation. In this case, as far as I can tell, these intrinsics don't give any new language capabilities, they're just other ways of doing basic operations (e.g. math and memory) that are optimized by SIMD at runtime. So, I think this adds no new const capabilities in practice.

@rfcbot merge lang

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Jan 21, 2026

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 21, 2026
@traviscross
Copy link
Contributor

To reiterate what @RalfJung said, it'd still be good to see this:

It'd be good to update the PR description to give the required context to team members visiting this during triage: which new capabilities are exposed to const code here, and what does the test coverage look like?

@RalfJung
Copy link
Member

RalfJung commented Jan 21, 2026

Ah sorry, I guess I should have waited for someone (specifically, @sayantn :) to do that before nominating. I was hoping it would be taken care of quickly enough to happen before t-lang gets around to look at the PR.

@sayantn
Copy link
Contributor Author

sayantn commented Jan 22, 2026

@RalfJung sorry for the delay. I have updated the description, could you check if it is ok?

@sayantn sayantn force-pushed the const-stable-indirect branch from a87092b to 5e7ef31 Compare January 22, 2026 16:56
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung
Copy link
Member

Instead of listing which intrinsics are not affected, could you list the ones that are? Remember, the reader has likely ~never looked at these intrinsics before.

I want to emphasize that I am not aiming to stabilize any of the const stdarch intrinsics in near future.

That makes me wonder why we should go through the trouble of approving these attributes.^^

There is const_eval_select, but it is still a pain to use (considering that we have to ensure that the 2 alternatives behave identically to be sound)

Given that the stdarch tests check that the right instructions get emitted even with the "generic" version, how could they possibly not behave identically?

(Also, calling this "generic" is confusing since Rust generics are something very different. I'd call it "portable" or "target-independent".)

@traviscross
Copy link
Contributor

Instead of listing which intrinsics are not affected, could you list the ones that are?

I might tweak this ask to "in addition to" rather than "instead of". It is valuable seeing what's not here, but it'd be good to say explicitly what is.

I want to emphasize that I am not aiming to stabilize any of the const stdarch intrinsics in near future.

That makes me wonder why we should go through the trouble of approving these attributes.^^

If you could speak more to this in particular, that would be helpful. I.e., I'd like to know more about the motivation and what specifically we're unblocking by accepting this. What do we want to do that will be possible after we approve this? An example would help.

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team 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.

8 participants