Skip to content

Use LocalDefId as an index in metadata encoding - #163321

Open
aerooneqq wants to merge 1 commit into
rust-lang:mainfrom
aerooneqq:local-def-index
Open

aerooneqq wants to merge 1 commit into
rust-lang:mainfrom
aerooneqq:local-def-index

Conversation

@aerooneqq

@aerooneqq aerooneqq commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

The goal of this PR to eliminate encoding of a raw DefIndex, instead we should encode something (LocalDefId) that certainly indicates that index belongs to the local crate. The implementation of DefIndex encoding should always panic to prevent accidental remappings of non-local DefIndexes in #162809.

So the plan is as follows:

  • Use LocalDefId as a writing index in tables for metadata encoding, use LocalDefId instead of DefIndex everywhere, specialize encode/decode methods to correctly process it,
  • Replace implementation of encode_def_index in EncodeContext with panic, so we never remap and encode def index,
  • Make tables' keys two-sided: we can read and write using different index types, in this case we will write using LocalDefId and read using DefIndex (done in Allow using different index types when reading and writing to tables #163447).

Blocked by #162900.

r? @petrochenkov

@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 Sep 25, 2026
@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 Sep 25, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Create `LocalDefIndex` for metadata encoding
@rust-bors

rust-bors Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2fa5a47 (2fa5a472bd28122b86b69706e673d2b3704e5c27)
Base parent: 4e701dc (4e701dc6ba63a40c908a173df269a55e1fd6297e)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2fa5a47): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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.8% [0.8%, 0.9%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

Results (primary -1.6%, secondary 3.8%)

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

Binary size

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

Bootstrap: 488.984s -> 488.935s (-0.01%)
Artifact size: 406.31 MiB -> 406.32 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 25, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_hir_id/src/definitions.rs
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 28, 2026
…ata, r=petrochenkov

Allow using different index types when reading and writing to tables

Make tables of metadata two-sided: one can write with one index type and read with another, as long as both those types are indexes. That will be used in rust-lang#163321 when we will have `LocalDefIndex` or similar type.

r? @petrochenkov
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 28, 2026
…ata, r=petrochenkov

Allow using different index types when reading and writing to tables

Make tables of metadata two-sided: one can write with one index type and read with another, as long as both those types are indexes. That will be used in rust-lang#163321 when we will have `LocalDefIndex` or similar type.

r? @petrochenkov
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 29, 2026
…ata, r=petrochenkov

Allow using different index types when reading and writing to tables

Make tables of metadata two-sided: one can write with one index type and read with another, as long as both those types are indexes. That will be used in rust-lang#163321 when we will have `LocalDefIndex` or similar type.

r? @petrochenkov
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 29, 2026
…ata, r=petrochenkov

Allow using different index types when reading and writing to tables

Make tables of metadata two-sided: one can write with one index type and read with another, as long as both those types are indexes. That will be used in rust-lang#163321 when we will have `LocalDefIndex` or similar type.

r? @petrochenkov
@rust-bors

This comment has been minimized.

@aerooneqq
aerooneqq force-pushed the local-def-index branch 2 times, most recently from d3319be to 68c2396 Compare September 29, 2026 10:11
@rustbot rustbot added the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Sep 29, 2026
@rust-log-analyzer

This comment has been minimized.

@aerooneqq

Copy link
Copy Markdown
Contributor Author

After some experiments with LocalDefIndex and LocalDefId it seems that LocalDefId is a better option, so now waiting for #162900 to merge and after that this will be ready.

@aerooneqq aerooneqq changed the title Create LocalDefIndex for metadata encoding Use LocalDefId as an index in metadata encoding Sep 29, 2026
@rust-bors

rust-bors Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@aerooneqq

Copy link
Copy Markdown
Contributor Author

Removed default decode_local_def_id impl and specialization for DefKey encoding.
@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 Oct 7, 2026

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bors delegate+

r=me,petrochenkov with changes applied and commits squashed

View changes since this review

Comment thread compiler/rustc_span/src/lib.rs Outdated
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 7, 2026
@rust-bors

rust-bors Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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

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

View changes since this delegation.

@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 Oct 7, 2026
@rustbot

rustbot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

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

@aerooneqq

Copy link
Copy Markdown
Contributor Author

@bors squash msg="Use LocalDefId instead of DefIndex in metadata encoding"

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔨 3 commits were squashed into b92cb3e.

@rust-bors
rust-bors Bot force-pushed the local-def-index branch from a32d487 to b92cb3e Compare October 7, 2026 08:37
@aerooneqq

Copy link
Copy Markdown
Contributor Author

@bors r=oli-obk,petrochenkov

@rust-bors

rust-bors Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b92cb3e has been tentatively approved by oli-obk,petrochenkov

It will be put into the queue for this repository once PR CI succeeds.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 7, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 8, 2026
…nkov

Use `LocalDefId` as an index in metadata encoding



The goal of this PR to eliminate encoding of a raw `DefIndex`, instead we should encode something (`LocalDefId`) that certainly indicates that index belongs to the local crate. The implementation of `DefIndex` encoding should always panic to prevent accidental remappings of non-local `DefIndex`es in #162809. 

So the plan is as follows:

- Use `LocalDefId` as a writing index in tables for metadata encoding, use `LocalDefId` instead of `DefIndex` everywhere, specialize encode/decode methods to correctly process it,
- Replace implementation of `encode_def_index` in `EncodeContext` with panic, so we never remap and encode def index,
- Make tables' keys two-sided: we can read and write using different index types, in this case we will write using `LocalDefId` and read using `DefIndex` (done in #163447).

Blocked by #162900.

r? @petrochenkov
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-aarch64-freebsd failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 8, 2026
@rust-bors

rust-bors Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

💔 Test for fcbcce8 failed: CI. Failed job:

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors retry

@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 Oct 8, 2026
@rust-bors

rust-bors Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Testing commit b92cb3e with merge 65efa19...

Workflow: https://github.com/rust-lang/rust/actions/runs/37763351175

rust-bors Bot pushed a commit that referenced this pull request Oct 8, 2026
…nkov

Use `LocalDefId` as an index in metadata encoding



The goal of this PR to eliminate encoding of a raw `DefIndex`, instead we should encode something (`LocalDefId`) that certainly indicates that index belongs to the local crate. The implementation of `DefIndex` encoding should always panic to prevent accidental remappings of non-local `DefIndex`es in #162809. 

So the plan is as follows:

- Use `LocalDefId` as a writing index in tables for metadata encoding, use `LocalDefId` instead of `DefIndex` everywhere, specialize encode/decode methods to correctly process it,
- Replace implementation of `encode_def_index` in `EncodeContext` with panic, so we never remap and encode def index,
- Make tables' keys two-sided: we can read and write using different index types, in this case we will write using `LocalDefId` and read using `DefIndex` (done in #163447).

Blocked by #162900.

r? @petrochenkov

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

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) 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.

8 participants