Skip to content

delegation: fix def path hash collision, add per parent disambiguators#153955

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aerooneqq:def-path-hash-collision
Apr 17, 2026
Merged

delegation: fix def path hash collision, add per parent disambiguators#153955
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aerooneqq:def-path-hash-collision

Conversation

@aerooneqq
Copy link
Copy Markdown
Contributor

@aerooneqq aerooneqq commented Mar 16, 2026

View all comments

This PR addresses the following delegation issues:

Fixes #153410. Part of #118212.

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 Mar 16, 2026
Comment thread tests/ui/delegation/generics/trait-impl-wrong-args-count.stderr
Comment thread tests/ui/delegation/generics/def-id-isnt-local-ice-143498.rs
Comment thread tests/ui/delegation/generics/def-id-isnt-local-ice-143498.rs Outdated
Comment thread tests/ui/delegation/generics/def-id-isnt-local-ice-143498.rs
Comment thread compiler/rustc_resolve/src/def_collector.rs Outdated
@petrochenkov
Copy link
Copy Markdown
Contributor

petrochenkov commented Mar 16, 2026

This is all pretty awful.
A number of other def ids / def paths are also created during AST lowering, but they don't require keeping per-node disambiguator tables around. Why is delegation so special in this regard?

What exactly definitions create collisions like this? Generic parameters?

As I understand the small per-node disambiguator tables partially duplicate content from the big table.
What prevents us from looking up the current disambiguators in the big table instead?

@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 Mar 16, 2026
@aerooneqq
Copy link
Copy Markdown
Contributor Author

aerooneqq commented Mar 17, 2026

A number of other def ids / def paths are also created during AST lowering, but they don't require keeping per-node disambiguator tables around. Why is delegation so special in this regard?

We generate new DefIds for each delegation generic param, as creation of DefId requires a name, we want to use names that are defined in a function being reused, for example for proper error messages. It is possible to create DefIds with, for example, sym::dummy name, but in this case error messages will be terrible. If we prefer to use names of generic params of the delegee, then we use names that are created by user, so they can clash with already used names in delegation.

The difference between delegation and other DefIds creation is that latter don't use user-defined names, as other cases of DefIds creation are DefPathData::DesugaredAnonymousLifetime which uses Some(kw::UnderscoreLifetime) as name and DefPathData::LateAnonConst which uses None as name.

Maybe we can create our own DefPathData variant and use it during creation of DefIds, but it still will need to hold the name of the param, as it is required for example in hir_ty_param_name. I am not sure that this is a correct option.

What exactly definitions create collisions like this? Generic parameters?

From our side yes, when we create generic params, their def path data can be either DefPathData::TypeNs(symbol) for DefKind::TyParam, DefPathData::ValueNs(symbol) for DefKind::ConstParam or DefPathData::LifetimeNs(symbol) for DefKind::LifetimeParam, so this def path data can have a collision with anything that have same def path created in scope of delegation LocalDefId during resolve stage.

What prevents us from looking up the current disambiguators in the big table instead?

Big table which is Resolver::disambiguator is not passed anywhere, as DefIds which are created during AST -> HIR lowering before this PR do not need it. Passing the whole disambiguator to lowering stage seems to be not the best option as it contains many unneeded information and it is not passed from Resolver to ResolverAstLowering now.

Internally DisambiguatorState uses UnordMap<(LocalDefId, DefPathData), u32> which prevents from fast lookups by LocalDefId only and changing it (for example to UnordMap<LocalDefId, UnordMap<DefPathData, u32>>) seemed to be out of scope of this PR.

Given this underlying structure I also didn't want to iterate over all map to find delegation-related key-values, and I also didn't want to expose the possibility of traversal of whole DisambiguatorState.

This left me with an option that I implemented in this PR: for each delegation we create additional disambiguator which follows the main one and then stored in delegation_infos map, for this purpose I exposed next operation on DisambiguatorState, which is also not that good, beacuase it was inlined in create_def function, thus only create_def could update it, but in the given conditions I think it is more-or-less OK solution.

@aerooneqq
Copy link
Copy Markdown
Contributor Author

@rustbot ready

To get feedback on the comments.

@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 Mar 17, 2026
@rust-bors

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the def-path-hash-collision branch from fbb4d60 to b9ef605 Compare March 19, 2026 09:51
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Copy Markdown
Contributor

petrochenkov commented Mar 19, 2026

This PR may be relevant:

It solved the collision problem by adding new DefPathData variants.

@petrochenkov
Copy link
Copy Markdown
Contributor

Blocked on #154049.
Can try the approach with new DefPathData variants in the meantime.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 19, 2026
@aerooneqq aerooneqq force-pushed the def-path-hash-collision branch from 5c0e8e9 to ef583eb Compare March 20, 2026 13:17
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 20, 2026

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

@rustbot rustbot added the PG-exploit-mitigations Project group: Exploit mitigations label Mar 20, 2026
@aerooneqq aerooneqq changed the title Fix delegation def path hash collision, fix ICE connected to dummy spans Fix delegation def path hash collision Mar 20, 2026
@aerooneqq aerooneqq marked this pull request as draft March 20, 2026 14:31
@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 Mar 20, 2026
@rust-bors

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the def-path-hash-collision branch from ef583eb to 5b48d28 Compare March 25, 2026 13:57
@petrochenkov petrochenkov added S-waiting-on-t-compiler Status: Awaiting decision from T-compiler and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) labels Apr 10, 2026
@aerooneqq aerooneqq force-pushed the def-path-hash-collision branch from 23a9f3b to 5d9cfeb Compare April 10, 2026 19:49
@rustbot rustbot added the PG-exploit-mitigations Project group: Exploit mitigations label Apr 10, 2026
@aerooneqq
Copy link
Copy Markdown
Contributor Author

Removed duplicated test for #143498.

@rust-bors

This comment has been minimized.

@petrochenkov
Copy link
Copy Markdown
Contributor

r=me after rebase.
@bors delegate+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 17, 2026

✌️ @aerooneqq, you can now approve this pull request!

If @petrochenkov told you to "r=me" after making some further change, then please make that change and post @bors r=petrochenkov.

@aerooneqq aerooneqq force-pushed the def-path-hash-collision branch from 5d9cfeb to 699eb29 Compare April 17, 2026 06:48
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 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.

@aerooneqq
Copy link
Copy Markdown
Contributor Author

@bors r=petrochenkov

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 17, 2026

📋 This PR cannot be approved because it currently has the following label: S-waiting-on-t-compiler.

@petrochenkov petrochenkov removed the S-waiting-on-t-compiler Status: Awaiting decision from T-compiler label Apr 17, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 17, 2026

📌 Commit 699eb29 has been approved by petrochenkov

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 Apr 17, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 17, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 17, 2026

☀️ Test successful - CI
Approved by: petrochenkov
Duration: 3h 23m 6s
Pushing 4dbafc3 to main...

@github-actions
Copy link
Copy Markdown
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 27dbdb5 (parent) -> 4dbafc3 (this PR)

Test differences

Show 21 test diffs

Stage 1

  • [ui] tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs: [missing] -> pass (J0)

Additionally, 19 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 4dbafc340b0f8e9ff9e95974d0ceef81ae2652c8 --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. i686-gnu-nopt-2: 1h 44m -> 2h 14m (+28.5%)
  2. dist-i686-msvc: 1h 51m -> 2h 18m (+24.2%)
  3. x86_64-gnu-aux: 1h 55m -> 2h 21m (+22.8%)
  4. dist-powerpc64-linux-gnu: 1h 33m -> 1h 14m (-19.8%)
  5. dist-powerpc64le-linux-musl: 1h 34m -> 1h 17m (-18.9%)
  6. tidy: 3m 8s -> 2m 40s (-14.7%)
  7. x86_64-gnu-llvm-22-2: 1h 41m -> 1h 29m (-11.4%)
  8. dist-x86_64-apple: 2h 5m -> 1h 52m (-10.0%)
  9. armhf-gnu: 1h 38m -> 1h 28m (-9.8%)
  10. x86_64-gnu-debug: 2h 3m -> 1h 52m (-9.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.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4dbafc3): comparison URL.

Overall result: ❌ regressions - please read:

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.2% [0.2%, 0.2%] 3
Regressions ❌
(secondary)
0.3% [0.0%, 0.4%] 20
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 3

Max RSS (memory usage)

Results (primary 0.4%, secondary 0.8%)

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

mean range count
Regressions ❌
(primary)
1.3% [0.7%, 2.0%] 5
Regressions ❌
(secondary)
2.3% [1.3%, 3.3%] 5
Improvements ✅
(primary)
-1.7% [-2.0%, -1.4%] 2
Improvements ✅
(secondary)
-1.8% [-3.1%, -1.0%] 3
All ❌✅ (primary) 0.4% [-2.0%, 2.0%] 7

Cycles

Results (primary 2.3%, secondary 2.5%)

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

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
5.6% [3.4%, 9.0%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.1%] 2
All ❌✅ (primary) 2.3% [2.3%, 2.3%] 1

Binary size

Results (primary 0.1%, 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.1% [0.0%, 0.3%] 52
Regressions ❌
(secondary)
0.2% [0.0%, 0.9%] 34
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.3%] 52

Bootstrap: 490.301s -> 493.358s (0.62%)
Artifact size: 394.23 MiB -> 394.12 MiB (-0.03%)

@oli-obk
Copy link
Copy Markdown
Contributor

oli-obk commented Apr 17, 2026

I didn't see this. I don't like that this was done in a manner that didn't need input from us.

Disambiguators are not visible except in symbols. Why was this a problem?

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

Labels

F-fn_delegation `#![feature(fn_delegation)]` merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations 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.

[ICE]: found DefPathHash collision between DefPath

7 participants