8000 Add a warning to LateContext::get_def_path by blyxyas · Pull Request #142593 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Conversation

blyxyas
Copy link
Member
@blyxyas blyxyas commented Jun 16, 2025

Preventing anyone from doing the same error as rust-lang/rust-clippy#15043 fixed

@rustbot
Copy link
Collaborator
rustbot commented Jun 16, 2025

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
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 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 Jun 16, 2025
}

/// Gets the absolute path of `def_id` as a vector of `Symbol`.
/// Note that this is kinda expensive because it has to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Note that this is kinda expensive because it has to
///
/// Note that this is kinda expensive because it has to

/// Note that this is kinda expensive because it has to
/// travel the tree and pretty-print. Use sparingly (or find a
/// way to only get the segments you're interested in, e.g. via
/// [`TyCtxt::crate_name`]).
Copy link
Member

Choose a reason for hiding this comment

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

or use a diagnostic item if the intention was to match an item by its path.

@compiler-errors
Copy link
Member

I'm not sure how this connects to rust-lang/clippy#15030. That looks like some test harness problem?

@compiler-errors
Copy link
Member

I'm also somewhat skeptical that this function is that notable. Grabbing the symbols for every segment in a def path doesn't seem like that much work in the grand scheme of things. Of course, if this is being done in a tight loop it may be expensive, but we use similar a to compute symbol names and stuff even on the good path.

Can you explain more about what led you to this function being expensive?

@blyxyas
Copy link
Member Author
blyxyas commented Jun 16, 2025

Oops, I meant rust-lang/rust-clippy#15043, 15030 is the one I'm working on right now. I'll edit that.

In our case, get_def_path was the 3rd heaviest function, we used it in a semi-tight loop, but still, it was accounting for more time than late_lint_mod.

Can you explain more about what led you to this function being expensive?

The call graph is like this:

get_def_path -> AbsolutePathPrinter::default_print_def_path -> core::fmt::write -> <Ty as core::fmt::Display>::fmt -> <FmtPrinter as Printer>::print_type -> ... -> rustc_interface::passes::early_lint_checks -> Running the early lint checks, somehow?

I haven't really looked into why pretty-printing a type would execute early lint checks. Maybe it has something to do with the pretty-printer calling tcx.visible_parent_map.

Graph


As to the necessity of this little warning, I've looked very briefly into other uses of get_def_path and a lot seem to be optimizable away with other, cheaper and more specific functions. So at least warning the user to think about alternatives I think it's necessary.

@blyxyas blyxyas force-pushed the improve-docs-itty-bitty-change branch from 3537451 to 6d04085 Compare June 17, 2025 00:07
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator
bors commented Jun 22, 2025

📌 Commit 6d04085 has been approved by compiler-errors

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-review Status: Awaiting review from the assignee but also interested parties. labels Jun 22, 2025
bors added a commit that referenced this pull request Jun 22, 2025
Rollup of 10 pull requests

Successful merges:

 - #142458 (Merge unboxed trait object error suggestion into regular dyn incompat error)
 - #142593 (Add a warning to LateContext::get_def_path)
 - #142594 (Add DesugaringKind::FormatLiteral)
 - #142740 (Clean-up `FnCtxt::is_destruct_assignment_desugaring`)
 - #142780 (Port `#[must_use]` to new attribute parsing infrastructure)
 - #142798 (Don't fail to parse a struct if a semicolon is used to separate fields)
 - #142856 (Add a few inline directives in rustc_serialize.)
 - #142868 (remove few allow(dead_code))
 - #142874 (cranelift: fix target feature name typo: "fxsr")
 - #142877 (Document why tidy checks if `eslint` is installed via `npm`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cab65ef into rust-lang:master Jun 22, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 22, 2025
rust-timer added a commit that referenced this pull request Jun 22, 2025
Rollup merge of #142593 - blyxyas:improve-docs-itty-bitty-change, r=compiler-errors

Add a warning to LateContext::get_def_path

Preventing anyone from doing the same error as rust-lang/rust-clippy#15043 fixed
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-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.

5 participants

0