Skip to content

make volatile operations const#159092

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:const-volatile
Jul 11, 2026
Merged

make volatile operations const#159092
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:const-volatile

Conversation

@RalfJung

@RalfJung RalfJung commented Jul 10, 2026

Copy link
Copy Markdown
Member

This came up in gfx-rs/wgpu#8897 (comment). The tl;dr is that it can be useful to have shared codepaths between things that need to work on special memory (and hence need to use volatile) and things that work on regular Rust memory, and for the regular Rust memory case those things totally could and should be const fn.

So, let's (unstably, for now) allow volatile reads and writes in const, and specify them to behave just like normal reads and writes. In const we know that there's nobody trying to observe those locations so there's nothing special we have to do with those accesses.

Cc @rust-lang/opsem @rust-lang/wg-const-eval

Tracking issue: #159094

@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

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

cc @rust-lang/miri

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

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

Some changes occurred to the CTFE machinery

cc @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added 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. labels Jul 10, 2026
@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
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: libs
  • libs expanded to 12 candidates
  • Random selection from 6 candidates

self.typed_swap_nonoverlapping_intrinsic(&args[0], &args[1])?;
}

sym::volatile_load => {

@oli-obk oli-obk Jul 10, 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.

This is the shared space for intrinsics for miri and ctfe. But this impl will only be used by ctfe, so it should live in the ctfe intrinsic impl file

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.

No, the same impl should be used by CTFE and Miri.

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.

Ah I assumed we'd want do so extra checks in miri, although who but other threads would be randomly modifying memory idk either

@oli-obk

oli-obk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

r? @oli-obk

@bors r+

@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d9e15dd has been approved by oli-obk

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 Jul 10, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 10, 2026
@oli-obk

oli-obk commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

@bors rollup

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
make volatile operations const

This came up in gfx-rs/wgpu#8897 (comment). The tl;dr is that it can be useful to have shared codepaths between things that need to work on special memory (and hence need to use volatile) and things that work on regular Rust memory, and for the regular Rust memory case those things totally could and should be `const fn`.

So, let's (unstably, for now) allow volatile reads and writes in `const`, and specify them to behave just like normal reads and writes. In const we *know* that there's nobody trying to observe those locations so there's nothing special we have to do with those accesses.

Cc @rust-lang/opsem @rust-lang/wg-const-eval

Tracking issue: rust-lang#159094
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 10, 2026
make volatile operations const

This came up in gfx-rs/wgpu#8897 (comment). The tl;dr is that it can be useful to have shared codepaths between things that need to work on special memory (and hence need to use volatile) and things that work on regular Rust memory, and for the regular Rust memory case those things totally could and should be `const fn`.

So, let's (unstably, for now) allow volatile reads and writes in `const`, and specify them to behave just like normal reads and writes. In const we *know* that there's nobody trying to observe those locations so there's nothing special we have to do with those accesses.

Cc @rust-lang/opsem @rust-lang/wg-const-eval

Tracking issue: rust-lang#159094
rust-bors Bot pushed a commit that referenced this pull request Jul 11, 2026
Rollup of 15 pull requests

Successful merges:

 - #159106 (Update LLVM)
 - #157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - #159005 (Use `as_lang_item` instead of repeatedly matching)
 - #156735 (Move NativeLib::filename to the rmeta-link archive member)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158269 (jq directives for jsondocck)
 - #158767 (merge DefKind::InlineConst into AnonConst)
 - #159099 (Stabilize String::from_utf8_lossy_owned)
 - #158930 (Reorganize `tests/ui/issues` [20/N])
 - #158965 (Add codegen test for Result is_ok unwrap)
 - #158979 (Reorganize `tests/ui/issues` [21/N])
 - #159050 (assert only opaques with sub unified hidden infer are non-rigid)
 - #159062 (Remove unused WEAK_ONLY_LANG_ITEMS static)
 - #159070 (Add `io::ErrorKind::InputOutputError`)
 - #159092 (make volatile operations const)
rust-bors Bot pushed a commit that referenced this pull request Jul 11, 2026
Rollup of 15 pull requests

Successful merges:

 - #159106 (Update LLVM)
 - #157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - #159005 (Use `as_lang_item` instead of repeatedly matching)
 - #156735 (Move NativeLib::filename to the rmeta-link archive member)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158269 (jq directives for jsondocck)
 - #158767 (merge DefKind::InlineConst into AnonConst)
 - #159099 (Stabilize String::from_utf8_lossy_owned)
 - #158930 (Reorganize `tests/ui/issues` [20/N])
 - #158965 (Add codegen test for Result is_ok unwrap)
 - #158979 (Reorganize `tests/ui/issues` [21/N])
 - #159050 (assert only opaques with sub unified hidden infer are non-rigid)
 - #159062 (Remove unused WEAK_ONLY_LANG_ITEMS static)
 - #159070 (Add `io::ErrorKind::InputOutputError`)
 - #159092 (make volatile operations const)
@rust-bors rust-bors Bot merged commit 3657ecd into rust-lang:main Jul 11, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 11, 2026
rust-timer added a commit that referenced this pull request Jul 11, 2026
Rollup merge of #159092 - RalfJung:const-volatile, r=oli-obk

make volatile operations const

This came up in gfx-rs/wgpu#8897 (comment). The tl;dr is that it can be useful to have shared codepaths between things that need to work on special memory (and hence need to use volatile) and things that work on regular Rust memory, and for the regular Rust memory case those things totally could and should be `const fn`.

So, let's (unstably, for now) allow volatile reads and writes in `const`, and specify them to behave just like normal reads and writes. In const we *know* that there's nobody trying to observe those locations so there's nothing special we have to do with those accesses.

Cc @rust-lang/opsem @rust-lang/wg-const-eval

Tracking issue: #159094
@RalfJung RalfJung deleted the const-volatile branch July 11, 2026 08:33
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@rust-timer build 95ccb43

@rust-timer

This comment has been minimized.

pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 12, 2026
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#159106 (Update LLVM)
 - rust-lang/rust#157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - rust-lang/rust#159005 (Use `as_lang_item` instead of repeatedly matching)
 - rust-lang/rust#156735 (Move NativeLib::filename to the rmeta-link archive member)
 - rust-lang/rust#157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - rust-lang/rust#158269 (jq directives for jsondocck)
 - rust-lang/rust#158767 (merge DefKind::InlineConst into AnonConst)
 - rust-lang/rust#159099 (Stabilize String::from_utf8_lossy_owned)
 - rust-lang/rust#158930 (Reorganize `tests/ui/issues` [20/N])
 - rust-lang/rust#158965 (Add codegen test for Result is_ok unwrap)
 - rust-lang/rust#158979 (Reorganize `tests/ui/issues` [21/N])
 - rust-lang/rust#159050 (assert only opaques with sub unified hidden infer are non-rigid)
 - rust-lang/rust#159062 (Remove unused WEAK_ONLY_LANG_ITEMS static)
 - rust-lang/rust#159070 (Add `io::ErrorKind::InputOutputError`)
 - rust-lang/rust#159092 (make volatile operations const)
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (95ccb43): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 7
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 1.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.9% [-0.9%, -0.9%] 1
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.3%, secondary 1.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.4% [2.5%, 9.3%] 4
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
-3.2% [-4.0%, -2.7%] 3
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.729s -> 491.445s (0.15%)
Artifact size: 389.29 MiB -> 389.91 MiB (0.16%)

@rustbot rustbot added the perf-regression Performance regression. label Jul 12, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@rustbot label: +perf-regression-triaged
Noise

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants