Skip to content

Add DenseMap - #164740

Draft
susitsm wants to merge 4 commits into
rust-lang:mainfrom
susitsm:dense-map
Draft

susitsm wants to merge 4 commits into
rust-lang:mainfrom
susitsm:dense-map

Conversation

@susitsm

@susitsm susitsm commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Adds DenseMap, DenseMapRef and DenseKey as alternatives for IndexVec, IndexSlice and Idx and replaces Idx with DensKey for SyntaxContext, LocalExpnId, LocalDefId, OwnerId

Motivation: IndexVec allows iteration, which should not be allowed for some index types, as it can result in nondeterminism.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 22, 2026
@susitsm

susitsm commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@aerooneqq this surfaced 2 places (1, 2), I think mostly for debugging output, where iteration order should be considered for LocalExpnId and SyntaxContext. Do you have an easy fix?

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-gnu-llvm-22-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |
note: required by a bound in `vec_cache::VecCache`
   --> compiler/rustc_data_structures/src/vec_cache.rs:225:24
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    |                        ^^^^^^^^ required by this bound in `VecCache`

error[E0599]: the method `lookup` exists for struct `vec_cache::VecCache<u32, u32, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:44:23
    |
 44 |         assert!(cache.lookup(&key).is_none());
    |                       ^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u32, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `lookup` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0277]: the trait bound `u32: DenseKey` is not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:50:16
    |
 50 |     let cache: VecCache<u32, u32, u32> = VecCache::default();
    |                ^^^^^^^^^^^^^^^^^^^^^^^ the trait `DenseKey` is not implemented for `u32`
    |
note: required by a bound in `vec_cache::VecCache`
   --> compiler/rustc_data_structures/src/vec_cache.rs:225:24
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    |                        ^^^^^^^^ required by this bound in `VecCache`

error[E0599]: the method `complete` exists for struct `vec_cache::VecCache<u32, u32, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:51:11
    |
 51 |     cache.complete(0, 1, 2);
    |           ^^^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u32, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `complete` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0599]: the method `lookup` exists for struct `vec_cache::VecCache<u32, u32, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:52:22
    |
 52 |     assert_eq!(cache.lookup(&0), Some((1, 2)));
    |                      ^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u32, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `lookup` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0277]: the trait bound `u32: DenseKey` is not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:57:16
    |
 57 |     let cache: VecCache<u32, u8, u32> = VecCache::default();
    |                ^^^^^^^^^^^^^^^^^^^^^^ the trait `DenseKey` is not implemented for `u32`
    |
note: required by a bound in `vec_cache::VecCache`
   --> compiler/rustc_data_structures/src/vec_cache.rs:225:24
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    |                        ^^^^^^^^ required by this bound in `VecCache`

error[E0599]: the method `complete` exists for struct `vec_cache::VecCache<u32, u8, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:73:15
    |
 73 |         cache.complete(key, shift, key);
    |               ^^^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u8, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `complete` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0599]: the method `lookup` exists for struct `vec_cache::VecCache<u32, u8, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:74:26
    |
 74 |         assert_eq!(cache.lookup(&key), Some((shift, key)));
    |                          ^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u8, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `lookup` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0277]: the trait bound `u32: DenseKey` is not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:80:16
    |
 80 |     let cache: VecCache<u32, u32, u32> = VecCache::default();
    |                ^^^^^^^^^^^^^^^^^^^^^^^ the trait `DenseKey` is not implemented for `u32`
    |
note: required by a bound in `vec_cache::VecCache`
   --> compiler/rustc_data_structures/src/vec_cache.rs:225:24
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    |                        ^^^^^^^^ required by this bound in `VecCache`

error[E0599]: the method `complete` exists for reference `&vec_cache::VecCache<u32, u32, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:85:23
    |
 85 |                 cache.complete(idx, idx, idx);
    |                       ^^^^^^^^ method cannot be called on `&vec_cache::VecCache<u32, u32, u32>` due to unsatisfied trait bounds
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

error[E0599]: the method `lookup` exists for struct `vec_cache::VecCache<u32, u32, u32>`, but its trait bounds were not satisfied
   --> compiler/rustc_data_structures/src/vec_cache/tests.rs:91:26
    |
 91 |         assert_eq!(cache.lookup(&idx), Some((idx, idx)));
    |                          ^^^^^^ method cannot be called on `vec_cache::VecCache<u32, u32, u32>` due to unsatisfied trait bounds
    |
   ::: compiler/rustc_data_structures/src/vec_cache.rs:225:1
    |
225 | pub struct VecCache<K: DenseKey, V, I> {
    | -------------------------------------- method `lookup` not found for this struct
    |
note: trait bound `u32: DenseKey` was not satisfied
   --> compiler/rustc_data_structures/src/vec_cache.rs:307:13
    |
305 | impl<K, V, I> VecCache<K, V, I>
    |               -----------------
306 | where
307 |     K: Eq + DenseKey + Copy + Debug,
    |             ^^^^^^^^ unsatisfied trait bound introduced here

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
[RUSTC-TIMING] rustc_data_structures test:true 3.810

@aerooneqq

aerooneqq commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Do you have an easy fix?

Sort by stable hashes maybe? Recently we merged (#163668) the remapping for syntax contexts and local expansions which sorts them by stable hash, as this is used in pretty print only this sort should not cause perf troubles.

@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #164757) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

4 participants