Skip to content

Conversation

@matthiaskrgr
Copy link
Member

@matthiaskrgr matthiaskrgr commented Nov 29, 2025

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

RalfJung and others added 18 commits November 9, 2025 14:32
Existing but private bindings - break, everything else - continue.
…for non-glob and glob bindings.

In preparation for introducing `Scope::Module(Non)Globs` and `ScopeSet::Module`.
…avidtwco

const validation: remove check for mutable refs in final value of const

This check rejects code that is not necessarily UB, e.g. a mutable ref to a `static mut` that is very carefully used correctly. That led to us having to describe it in the Reference, which uncovered just how ad-hoc this check is (rust-lang/reference#2074).

Even without this check, we still reject things like
```rust
const C: &mut i32 = &mut 0;
```
This is rejected by const checking -- the part of the frontend that looks at the source code and says whether it is allowed in const context. In the Reference, this restriction is explained [here](https://doc.rust-lang.org/nightly/reference/const_eval.html#r-const-eval.const-expr.borrows).

So, the check during validation is just a safety net. And it is already a safety net with gaping holes since we only check `&mut T`, not `&UnsafeCell<T>`, due to the fact that we promote some immutable values that have `!Freeze` type so `&!Freeze` actually can occur in the final value of a const.

So... it may be time for me to acknowledge that the "mutable ref in final value of const" check is a cure that's worth than the disease. Nobody asked for that check, I just added it because I was worried about soundness issues when we allow mutable references in constants. Originally it was much stricter, but I had to slowly relax it to its current form to prevent t from firing on code we intend to allow. In the end there are only 3 tests left that trigger this error, and they are all just constants containing references to mutable statics -- not the safest code in the world, but also not so bad that we have to spend a lot of time devising a core language limitation and associated Reference wording to prevent it from ever happening.

So... `@rust-lang/wg-const-eval` `@rust-lang/lang`  I propose that we allow code like this
```rust
static mut S: i32 = 3;
const C2: &'static mut i32 = unsafe { &mut * &raw mut S };
```
`@theemathas` would be great if you could try to poke a hole into this. ;)
std: split up the `thread` module

Almost all functionality in `std::thread` is currently implemented in `thread/mod.rs`, resulting in a *huge* file with more than 2000 lines and multiple, interoperating `unsafe` sections. This PR splits the file up into multiple different private modules, each implementing mostly independent parts of the functionality. The only remaining `unsafe` interplay is that of the `lifecycle` and `scope` modules, the `spawn_scoped` implementation relies on the live thread count being updated correctly by the `lifecycle` module.

This PR contains no functional changes and only moves code around for the most part, with a few notable exceptions:
* `with_current_name` is moved to the already existing `current` module and now uses the `name` method instead of calculating the name from private fields. The old code was just a reimplementation of that method anyway.
* The private `JoinInner` type used to implement both join handles now has some more methods (`is_finished`, `thread` and the `AsInner`/`IntoInner` implementations) to avoid having to expose private fields and their invariants.
* The private `spawn_unchecked_` (note the underscore) method of `Builder` is now a freestanding function in `lifecycle`.

The rest of the changes are just visibility annotations.

I realise this PR ended up quite large – let me know if there is anyway I can aid the review process.

Edit: I've simplified the diff by adding an intermediate commit that creates all the new files by duplicating `mod.rs`. The actual changes in the second commit thus appear to delete the non-relevant parts from the respective file.
resolve: Identifier resolution refactorings

Mostly splitting large functions into smaller functions, including some parts from rust-lang#144131, there should be no functional changes.
See individual commits.
@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. rollup A PR which is a rollup labels Nov 29, 2025
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=5

@bors
Copy link
Collaborator

bors commented Nov 29, 2025

📌 Commit b35b187 has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 29, 2025
@bors
Copy link
Collaborator

bors commented Nov 29, 2025

⌛ Testing commit b35b187 with merge 3ff30e7...

@bors
Copy link
Collaborator

bors commented Nov 29, 2025

☀️ Test successful - checks-actions
Approved by: matthiaskrgr
Pushing 3ff30e7 to main...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 29, 2025
@bors bors merged commit 3ff30e7 into rust-lang:main Nov 29, 2025
12 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 29, 2025
@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#148746 const validation: remove check for mutable refs in final va… fa3c1be23d59fdaacc0b84c97102e7ac874f49a2 (link)
#148765 std: split up the thread module 1a5f39451c434fbd8705192273a96f2216b0e26f (link)
#149454 resolve: Identifier resolution refactorings fad09d218d373566253ee77c1687fa3c276ed8ab (link)

previous master: 8a3a6bdb68

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8a3a6bd (parent) -> 3ff30e7 (this PR)

Test differences

Show 191 test diffs

Stage 1

  • [ui] tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs: pass -> [missing] (J1)

Stage 2

  • [ui] tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs: pass -> [missing] (J0)

Additionally, 189 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 3ff30e7eafc1da7104c3960187d17939172428ed --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. aarch64-apple: 7647.9s -> 12150.7s (+58.9%)
  2. dist-x86_64-apple: 7035.4s -> 7998.8s (+13.7%)
  3. i686-gnu-2: 5392.4s -> 6115.2s (+13.4%)
  4. aarch64-gnu-llvm-20-2: 2173.0s -> 2455.5s (+13.0%)
  5. x86_64-gnu-llvm-20: 2413.5s -> 2727.0s (+13.0%)
  6. x86_64-gnu-gcc: 3010.2s -> 3339.7s (+10.9%)
  7. x86_64-mingw-1: 9629.1s -> 10545.3s (+9.5%)
  8. x86_64-gnu-debug: 6617.0s -> 7240.1s (+9.4%)
  9. dist-aarch64-msvc: 6210.6s -> 5635.4s (-9.3%)
  10. dist-x86_64-msvc-alt: 9581.1s -> 8704.7s (-9.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3ff30e7): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.5% [0.1%, 1.0%] 160
Regressions ❌
(secondary)
0.6% [0.1%, 2.0%] 82
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.5%, -0.5%] 1
All ❌✅ (primary) 0.5% [0.1%, 1.0%] 160

Max RSS (memory usage)

Results (secondary -3.5%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-3.5%, -3.5%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary 0.2%, secondary 0.0%)

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

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

Bootstrap: 471.041s -> 470.301s (-0.16%)
Artifact size: 386.90 MiB -> 386.94 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Nov 30, 2025
@matthiaskrgr
Copy link
Member Author

@rust-timer build fad09d2

@rust-timer

This comment has been minimized.

@matthiaskrgr
Copy link
Member Author

@rust-timer build fa3c1be

@Kobzol
Copy link
Member

Kobzol commented Nov 30, 2025

(You can't schedule more than a single parallel build per PR. It mught be a bit more practical to do the runs on the rolled up PRs directly).

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fad09d2): comparison URL.

Overall result: ❌ regressions - please read the text below

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.5% [0.1%, 1.0%] 159
Regressions ❌
(secondary)
0.6% [0.1%, 2.0%] 78
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.1%, 1.0%] 159

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 471.041s -> 468.72s (-0.49%)
Artifact size: 386.90 MiB -> 386.92 MiB (0.00%)

@matthiaskrgr
Copy link
Member Author

@rust-timer build fa3c1be

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fa3c1be): comparison URL.

Overall result: no relevant changes - no action needed

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 471.041s -> 471.472s (0.09%)
Artifact size: 386.90 MiB -> 386.90 MiB (0.00%)

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Nov 30, 2025

cc @petrochenkov looks like there are a bunch of tiny perf degradations in #149454 🤔

@petrochenkov
Copy link
Contributor

@matthiaskrgr This is from the last commit - c91b6ca (can revert and benchmark it to be sure), because we now look up a name in a module ~twice.
It's an important change unblocking #144131 and the open API work, so I'd rather continue with it.

It can be potentially optimized, and would be good to optimize it, but that code is a bit of a minefield, with any change, including bugfixes, being able to cause breakage in user code.

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

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. rollup A PR which is a rollup 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.

8 participants