Skip to content

Use LocalDefId for more tcx method calls#154371

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
zetanumbers:typeck_root_def_id_local
Mar 28, 2026
Merged

Use LocalDefId for more tcx method calls#154371
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
zetanumbers:typeck_root_def_id_local

Conversation

@zetanumbers
Copy link
Copy Markdown
Contributor

@zetanumbers zetanumbers commented Mar 25, 2026

View all comments

r? @petrochenkov

Might bring perf improvements

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 25, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in need_type_info.rs

cc @lcnr

Some changes occurred in coverage instrumentation.

cc @Zalathar

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 25, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 25, 2026
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 25, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 25, 2026

☀️ Try build successful (CI)
Build commit: 3c6dc09 (3c6dc097fe81b4e758db660110dd84dc136cf8a5, parent: 8a703520e80d87d4423c01f9d4fbc9e5f6533a02)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (3c6dc09): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible 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 -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)
- - 0
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

Cycles

Results (secondary 4.4%)

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)
6.4% [4.9%, 10.1%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 482.838s -> 489.051s (1.29%)
Artifact size: 394.91 MiB -> 394.93 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 25, 2026
@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 26, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

As the benchmark shows, in general, duplicating methods into foo and foo_local doesn't make sense from performance point of view.
I suggest keeping the subset of DefId -> LocalDefId changes that improves the code (better readability, more clear invariants, etc), I'll mark the changes that I think are worth keeping.

/// For example, a closure has its own `LocalDefId`, but it is type-checked
/// with the containing item. Therefore, when we fetch the `typeck` of the closure,
/// for example, we really wind up fetching the `typeck` of the enclosing fn item.
pub fn typeck_root_def_id_local(self, def_id: LocalDefId) -> LocalDefId {
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Mar 26, 2026

Choose a reason for hiding this comment

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

The body can be changed to typeck_root_def_id(def_id.to_def_id()).expect_local().
(Because the copy-pasted version doesn't show perf benefits while being more complex.)

@petrochenkov
Copy link
Copy Markdown
Contributor

Most of the changes are worth keeping, actually.
@rustbot author

@rustbot rustbot 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 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

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

@zetanumbers zetanumbers force-pushed the typeck_root_def_id_local branch from ec7d272 to 62ec331 Compare March 27, 2026 12:40
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 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.

@zetanumbers
Copy link
Copy Markdown
Contributor Author

@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 Mar 27, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

r=me after addressing #154371 (comment).
@rustbot author

@rustbot rustbot 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 27, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

Okay, #154371 (comment) is not too important.
@bors r+ rollup=maybe

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 27, 2026

📌 Commit 62ec331 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 27, 2026
Rollup of 10 pull requests

Successful merges:

 - #154070 (Unstable book options parser)
 - #154371 (Use LocalDefId for more tcx method calls)
 - #154405 (Improve doc comment unicode guidance)
 - #154431 (Avoid ICE in explicit reference cast suggestion for unrelated leaf pr…)
 - #153528 (Fix LegacyKeyValueFormat report from docker build: mips)
 - #154246 (Add test for issue #101532: dead code warnings in const _)
 - #154421 (Rustdoc rejects html emits with json output)
 - #154428 (bootstrap: `-Zjson-target-spec` for synthetic targets)
 - #154437 (bootstrap.example.toml: Hint how to allow `build.warnings`)
 - #154454 (fix: [rustfmt] prevent panic when rewritng associated item delegations)

Failed merges:

 - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`)
rust-bors bot pushed a commit that referenced this pull request Mar 27, 2026
Rollup of 10 pull requests

Successful merges:

 - #154070 (Unstable book options parser)
 - #154371 (Use LocalDefId for more tcx method calls)
 - #154405 (Improve doc comment unicode guidance)
 - #154431 (Avoid ICE in explicit reference cast suggestion for unrelated leaf pr…)
 - #153528 (Fix LegacyKeyValueFormat report from docker build: mips)
 - #154246 (Add test for issue #101532: dead code warnings in const _)
 - #154421 (Rustdoc rejects html emits with json output)
 - #154428 (bootstrap: `-Zjson-target-spec` for synthetic targets)
 - #154437 (bootstrap.example.toml: Hint how to allow `build.warnings`)
 - #154454 (fix: [rustfmt] prevent panic when rewritng associated item delegations)

Failed merges:

 - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`)
@rust-bors rust-bors bot merged commit 9ba9194 into rust-lang:main Mar 28, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 28, 2026
rust-timer added a commit that referenced this pull request Mar 28, 2026
Rollup merge of #154371 - zetanumbers:typeck_root_def_id_local, r=petrochenkov

Use LocalDefId for more tcx method calls

r? @petrochenkov

Might bring perf improvements
@zetanumbers zetanumbers deleted the typeck_root_def_id_local branch March 28, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. 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