Skip to content

Resolver: Introduce CmRef which has a speclative borrow variant for CmRefCell - #160271

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
LorrensP-2158466:res-cm-refcell
Aug 1, 2026
Merged

Resolver: Introduce CmRef which has a speclative borrow variant for CmRefCell#160271
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
LorrensP-2158466:res-cm-refcell

Conversation

@LorrensP-2158466

@LorrensP-2158466 LorrensP-2158466 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

View all comments

part of #158845

We now introduce CmRef that is returned by CmRefCell::borrow, which does a normal borrow of the underlying T if we are in speculative resolution. We do not alter state during speculative resolution and because it will be run in parallel in the future, updating the RefCell borrow counters is not possible. Thus we just return &T that is "untracked".

Also allows us to remove the CmRefCell wrapper around the external module resolution table.

r? @petrochenkov

@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. labels Jul 31, 2026
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 31, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 31, 2026
Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
@petrochenkov petrochenkov 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 31, 2026
@rust-bors

rust-bors Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: caf2dd1 (caf2dd11317e37ec790b3746057fae8a36779c87)
Base parent: 922325b (922325bb13bfea5b41454318563f2a65e83c2336)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (caf2dd1): comparison URL.

Overall result: ❌ regressions - 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 rustc-perf
@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.2% [0.2%, 0.3%] 34
Regressions ❌
(secondary)
0.4% [0.1%, 0.8%] 22
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 3
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 34

Max RSS (memory usage)

Results (primary 1.5%, 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)
3.4% [3.4%, 3.4%] 1
Regressions ❌
(secondary)
2.8% [0.8%, 6.2%] 4
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.4%] 2
All ❌✅ (primary) 1.5% [-0.4%, 3.4%] 2

Cycles

Results (primary 0.3%, secondary -1.2%)

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

mean range count
Regressions ❌
(primary)
1.2% [0.4%, 2.7%] 7
Regressions ❌
(secondary)
1.7% [0.5%, 3.5%] 15
Improvements ✅
(primary)
-1.0% [-2.2%, -0.5%] 5
Improvements ✅
(secondary)
-5.1% [-10.8%, -0.6%] 11
All ❌✅ (primary) 0.3% [-2.2%, 2.7%] 12

Binary size

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

Bootstrap: 490.333s -> 490.941s (0.12%)
Artifact size: 392.58 MiB -> 390.55 MiB (-0.52%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 31, 2026
@Kobzol

Kobzol commented Jul 31, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 31, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 31, 2026
Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
@rust-bors

rust-bors Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 14a8f12 (14a8f12f6d59bdebd04ce9fc8ef7b4f0a25f0a4f)
Base parent: 64af19d (64af19d44c63587455c76f484ce76261a9971e96)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (14a8f12): comparison URL.

Overall result: ❌ regressions - 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 rustc-perf
@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.3% [0.2%, 0.4%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 4.1%, secondary 2.7%)

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

mean range count
Regressions ❌
(primary)
5.2% [2.6%, 9.9%] 4
Regressions ❌
(secondary)
4.3% [2.2%, 6.4%] 2
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
-0.6% [-0.6%, -0.6%] 1
All ❌✅ (primary) 4.1% [-0.6%, 9.9%] 5

Cycles

Results (primary 0.4%, secondary 0.2%)

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

mean range count
Regressions ❌
(primary)
0.8% [0.5%, 1.1%] 10
Regressions ❌
(secondary)
0.9% [0.5%, 2.6%] 13
Improvements ✅
(primary)
-0.7% [-0.9%, -0.5%] 3
Improvements ✅
(secondary)
-2.4% [-4.3%, -0.6%] 3
All ❌✅ (primary) 0.4% [-0.9%, 1.1%] 13

Binary size

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

Bootstrap: 492.106s -> 489.164s (-0.60%)
Artifact size: 390.46 MiB -> 390.45 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 1, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

I'm surprised it's a regression at all, it's such a tiny thing, checking a flag once per module, not even per declaration.

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

It is also per Resolution, those are wrapped in a CmRefCell as well.

Deref is also an enum match, niche optimization puts the niche on the Ref.ptr.

@petrochenkov

petrochenkov commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

It is also per Resolution, those are wrapped in a CmRefCell as well.
Deref is also an enum match, niche optimization puts the niche on the Ref.ptr.

I mean in this PR, not in follow ups.
"checking a flag once per module" is the deref on resolutions' returned value.

I've been trying to use a closure-based interface for this for the last half an hour, like

    fn with_resolutions<R>(&self, module: Module<'ra>, f: impl FnOnce(&ResolutionTable<'ra>) -> R) -> R { ... }

but it's getting too unwieldy, maybe not today.

r=me on this PR after squashing commits.
@rustbot author

CmRefCell::borrow with the token optimization will be the next step.

@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

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

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

"checking a flag once per module" is the deref on resolutions' returned value.

right yeah, forgot the revert.

r=me on this PR after squashing commits.

squashed, but can't r=you, @rustbot ready.

@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 Aug 1, 2026
@LorrensP-2158466

LorrensP-2158466 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

CmRefCell::borrow with the token optimization will be the next step.

i'll open a pr based of this pr with the token, rebasing will remove this pr's commit.

Edit: Do you want the new version of borrow as well here? Which I had to revert here.

@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9890f66 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Aug 1, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

Edit: Do you want the new version of borrow as well here? Which I had to revert here.

Yes, the full CmRefCell change.

rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #160262 (Library lock file maintenance)
 - #158548 (Move `std::io::copy` to `alloc::io`)
 - #158814 (Produce an error when `#[inline]` and `#[rust_force_inline]` are used together)
 - #160025 (Fix an edge case with `StepBy::nth` on non-fused iterators)
 - #160271 (Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`)
 - #160281 (Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in `set_get_permissions_nofollows*`)
 - #160325 (tidy: Check `proc_macro_deps.rs` by reading it, not by including it)
 - #160334 (Add regression test for unused_allocation on boxed comparison)
@rust-bors
rust-bors Bot merged commit 4f8f88e into rust-lang:main Aug 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 1, 2026
rust-timer added a commit that referenced this pull request Aug 1, 2026
Rollup merge of #160271 - LorrensP-2158466:res-cm-refcell, r=petrochenkov

Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`

part of #158845

We now introduce `CmRef` that is returned by `CmRefCell::borrow`, which does a normal borrow of the underlying `T` if we are in speculative resolution. We do not alter state during speculative resolution and because it will be run in parallel in the future, updating the `RefCell` borrow counters is not possible. Thus we just return `&T` that is "untracked".

Also allows us to remove the `CmRefCell` wrapper around the external module resolution table.

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

Labels

perf-regression Performance regression. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants