Skip to content

compiler: Document and reduce fn provides in hir crates #143394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

workingjubilee
Copy link
Member

I found it hard to follow all these tiny micro-indirections. Much like you shouldn't pass around &u32 if you can help it, you probably shouldn't use an indirection if the indirection overhead itself is literally bigger than the amount of data you are organizing. Generally a new fn provide amounts to around 3 LOC:

  • the signature with opening brace
  • the rustc_middle::query::Providers import
  • an end brace

I am not even counting the cost in time and thought to go find the other provide, read it, understand, "Ah, yes, these functions", and then go to those. Thus I say we should collapse indirections of provide for modules that only export 1~2 queries. For higher-count indirections, I left them as-is, as I don't understand the crate well enough to judge their worth.

Then I dropped a pointer to the actual module of interest for all these instances of the same function. I think documenting them is important because the comment that it relates to the query system makes it obvious that they have nothing to do with the rest of the module's logic and I can carry on ignoring them. Actively doing so is another cognitive cost, but much more minimal.

There is also a small correctness issue in that all of these functions are technically mutating state. It's not a huge deal, but it's still easier to check all these mutations do not overlap if we have less instances of fn provide to check.

@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2025

r? @spastorino

rustbot has assigned @spastorino.
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 Jul 3, 2025
@workingjubilee
Copy link
Member Author

It might also be the case that the inlining should be reversed until there are no more individual queries being assigned in the root fn provide of this crate. Either direction seems like one to head in.

@workingjubilee workingjubilee force-pushed the reorganize-hir-analysis-provide-fn branch from 0bcd31a to 1ac1d83 Compare July 3, 2025 19:16
@workingjubilee workingjubilee changed the title rustc_hir_analysis: Document and reduce number of fn provides compiler: Document and reduce number of fn provides in hir crates Jul 3, 2025
@workingjubilee workingjubilee changed the title compiler: Document and reduce number of fn provides in hir crates compiler: Document and reduce fn provides in hir crates Jul 3, 2025
@workingjubilee
Copy link
Member Author

There was one other one in hir_typeck that I simplified also.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

should probably pluralize the direct object in "Adds query fn to the [...]", since rn is a bit awkward, but I prefer "query implementations" bc that's more descriptive.

@compiler-errors
Copy link
Member

Update the comments, then r=me

@compiler-errors
Copy link
Member

Also please squash all the inlining commits, since they kinda all do the same thing

Many small indirections with 1-2 items actively hinders understanding.
Inlines various tiny submodule provides into
- hir_analysis::provide
- hir_analysis::check::provide
- hir_typeck::provide
@workingjubilee workingjubilee force-pushed the reorganize-hir-analysis-provide-fn branch from 1ac1d83 to 3b7f9f9 Compare July 3, 2025 20:50
@workingjubilee
Copy link
Member Author

Done~

@compiler-errors
Copy link
Member

thanks

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 3, 2025

📌 Commit 3b7f9f9 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 Jul 3, 2025
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