Skip to content

Remove global next_disambiguator state and handle it with a DisambiguatorState type #140453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 5, 2025

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Apr 29, 2025

This removes Definitions.next_disambiguator as it doesn't guarantee deterministic def paths when create_def is called in parallel. Instead a new DisambiguatorState type is passed as a mutable reference to create_def to help create unique def paths. create_def calls with distinct DisambiguatorState instances must ensure that that the def paths are unique without its help.

Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the DefPathData to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.

DefPathData::NestedStatic is added to use for nested data inside statics instead of reusing DefPathData::AnonConst to avoid conflicts with those.

cc @oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @estebank

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

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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 Apr 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Apr 29, 2025
@oli-obk oli-obk assigned oli-obk and unassigned estebank Apr 29, 2025

impl DisambiguatorState {
pub fn new() -> Self {
Self { next: Default::default() }
Copy link
Contributor

Choose a reason for hiding this comment

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

#[derive(Default)] can be used instead of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do prefer new if Default isn't needed though.

@petrochenkov petrochenkov removed their assignment Apr 29, 2025
@oli-obk oli-obk removed the PG-exploit-mitigations Project group: Exploit mitigations label May 2, 2025
@Zoxc Zoxc force-pushed the next-disambiguator branch from d5a3b9c to 6a48217 Compare May 2, 2025 13:51
@rustbot rustbot added the PG-exploit-mitigations Project group: Exploit mitigations label May 2, 2025
@oli-obk oli-obk 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 May 2, 2025
@oli-obk
Copy link
Contributor

oli-obk commented May 4, 2025

@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 May 4, 2025
@bors
Copy link
Collaborator

bors commented May 4, 2025

⌛ Trying commit acb50d5 with merge 1febaad...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2025
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type

This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct  `DisambiguatorState` instances must ensure that that the def paths are unique without its help.

Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.

`DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those.

cc `@oli-obk`
@bors
Copy link
Collaborator

bors commented May 4, 2025

☀️ Try build successful - checks-actions
Build commit: 1febaad (1febaad87593af7579d4d2dc363e8854d2d6e0fb)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1febaad): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

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

Instruction count

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

Max RSS (memory usage)

Results (primary 0.2%, secondary 1.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.7% [0.4%, 1.4%] 12
Regressions ❌
(secondary)
1.9% [1.9%, 1.9%] 1
Improvements ✅
(primary)
-0.6% [-0.9%, -0.4%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-0.9%, 1.4%] 18

Cycles

Results (primary -0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.4%, 1.1%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.2%, -0.4%] 18
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-1.2%, 1.1%] 24

Binary size

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

Bootstrap: 770.413s -> 770.195s (-0.03%)
Artifact size: 365.46 MiB -> 365.34 MiB (-0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 4, 2025
@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 5, 2025

📌 Commit acb50d5 has been approved by oli-obk

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 5, 2025
@bors
Copy link
Collaborator

bors commented May 5, 2025

⌛ Testing commit acb50d5 with merge 243c5a3...

@bors
Copy link
Collaborator

bors commented May 5, 2025

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 243c5a3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 5, 2025
@bors bors merged commit 243c5a3 into rust-lang:master May 5, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 5, 2025
Copy link

github-actions bot commented May 5, 2025

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 0eb0b8c (parent) -> 243c5a3 (this PR)

Test differences

Show 20 test diffs

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

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 243c5a35e18b2634892fe7091d5ee888a18f77f5 --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. x86_64-apple-1: 6425.5s -> 9397.1s (46.2%)
  2. aarch64-apple: 3642.7s -> 4591.7s (26.1%)
  3. dist-apple-various: 6382.7s -> 7696.3s (20.6%)
  4. dist-x86_64-apple: 10259.5s -> 9063.0s (-11.7%)
  5. x86_64-msvc-ext2: 5740.7s -> 6314.5s (10.0%)
  6. x86_64-msvc-ext1: 7141.8s -> 7759.9s (8.7%)
  7. x86_64-msvc-2: 6636.0s -> 7207.2s (8.6%)
  8. dist-arm-linux: 4992.4s -> 4577.4s (-8.3%)
  9. x86_64-apple-2: 5604.6s -> 5147.1s (-8.2%)
  10. dist-powerpc-linux: 5288.0s -> 5681.2s (7.4%)
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.

@Zoxc Zoxc deleted the next-disambiguator branch May 5, 2025 15:15
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (243c5a3): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (primary 0.7%, secondary -2.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.2% [0.4%, 2.5%] 11
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.8%, -0.5%] 3
Improvements ✅
(secondary)
-2.5% [-2.6%, -2.4%] 2
All ❌✅ (primary) 0.7% [-1.8%, 2.5%] 14

Cycles

Results (primary 0.2%, secondary 2.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.4%, 0.6%] 16
Regressions ❌
(secondary)
2.2% [1.5%, 2.9%] 2
Improvements ✅
(primary)
-1.2% [-2.4%, -0.5%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-2.4%, 0.6%] 20

Binary size

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

Bootstrap: 768.8s -> 770.492s (0.22%)
Artifact size: 365.42 MiB -> 365.47 MiB (0.01%)

@Zoxc
Copy link
Contributor Author

Zoxc commented May 7, 2025

Looks like my assumption in resolve_bound_vars was incorrect and lifetimes inside opaque nodes can appear when lowering to HIR, which causes #140731.

I'm not quite sure what the purpose of the remapped lifetime def paths are, but perhaps these should be synthetic to avoid conflicts as they do look like some form of desugaring. cc @cjgillot

Another fix could be to pass on DisambiguatorState from lowering, but cloning that could be expensive.

@oli-obk
Copy link
Contributor

oli-obk commented May 7, 2025

but cloning that could be expensive.

why would it be cloned?

But yea, just giving them a unique DefPathData should be simpler

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. PG-exploit-mitigations Project group: Exploit mitigations 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.

9 participants