Skip to content
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

Refactor HIR item-like traversal (part 1) #95655

Merged
merged 18 commits into from Apr 17, 2022

Conversation

kckeiks
Copy link
Contributor

@kckeiks kckeiks commented Apr 4, 2022

Issue #95004

  • Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
  • use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
  • use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz mi9uel9@gmail.com

cc @cjgillot

@rust-highfive
Copy link
Collaborator

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 4, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2022
@cjgillot cjgillot self-assigned this Apr 4, 2022
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Thanks @kckeiks. This is a good start. I have a few remarks/questions.

compiler/rustc_middle/src/query/mod.rs Outdated Show resolved Hide resolved

fn visit_item(&mut self, item: &'hir Item<'hir>) {
self.items.push(item.item_id());
intravisit::walk_item(self, item)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you keep filling submodules? It may prove useful to implement for_each_module.

Copy link
Contributor Author

@kckeiks kckeiks Apr 4, 2022

Choose a reason for hiding this comment

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

Yes, I can update this method. I think for_each_module is already there.

pub fn for_each_module(self, f: impl Fn(LocalDefId)) {

Actually, that one starts from the root mod so I may have to do something else here.

Copy link
Contributor

@cjgillot cjgillot Apr 5, 2022

Choose a reason for hiding this comment

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

I mean: for_each_module currently walks hir_module_items recursively. par_for_each_module does this in recursive form. Having hir_crate_items.submodules as the list of all the modules in the crate will make those two functions simple loops over it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean. I will update for_each_module now that I'm collecting modules.


return ModuleItems {
submodules: submodules.into_boxed_slice(),
items: items.into_boxed_slice(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the code, I'm not sure that items starts with CRATE_DEF_ID. It should.

Copy link
Contributor Author

@kckeiks kckeiks Apr 4, 2022

Choose a reason for hiding this comment

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

Now that you mention it, looking at where the walk begins in walk_toplevel_module, it seems like CRATE_DEF_ID does not get added to items. Am I reading that right?

@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov assigned cjgillot and unassigned cjgillot and petrochenkov Apr 4, 2022
@kckeiks kckeiks force-pushed the create-hir-crate-items-query branch from b474ba5 to 292637c Compare April 5, 2022 02:13
@rust-log-analyzer

This comment has been minimized.

@kckeiks kckeiks force-pushed the create-hir-crate-items-query branch from 292637c to 4db16f0 Compare April 5, 2022 15:56
@rust-log-analyzer

This comment has been minimized.

@kckeiks kckeiks force-pushed the create-hir-crate-items-query branch from 4db16f0 to f213ed6 Compare April 5, 2022 17:34
@rust-log-analyzer

This comment has been minimized.

@kckeiks kckeiks force-pushed the create-hir-crate-items-query branch from f213ed6 to 6ef0f16 Compare April 5, 2022 18:54
@kckeiks
Copy link
Contributor Author

kckeiks commented Apr 5, 2022

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)

Updated clippy test.

@cjgillot
Copy link
Contributor

cjgillot commented Apr 5, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 5, 2022
@bors
Copy link
Contributor

bors commented Apr 5, 2022

⌛ Trying commit 6ef0f16d6da22d5508d0299f654368ce263ff2f2 with merge 269a8ae2d5d9ee215834795c69b97483f02b20bf...

@bors
Copy link
Contributor

bors commented Apr 5, 2022

☀️ Try build successful - checks-actions
Build commit: 269a8ae2d5d9ee215834795c69b97483f02b20bf (269a8ae2d5d9ee215834795c69b97483f02b20bf)

@rust-timer
Copy link
Collaborator

Queued 269a8ae2d5d9ee215834795c69b97483f02b20bf with parent f262ca1, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (269a8ae2d5d9ee215834795c69b97483f02b20bf): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 14 15 1 0 15
mean2 0.2% 0.3% -0.4% N/A 0.2%
max 0.3% 0.3% -0.4% N/A -0.4%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 5, 2022
@kckeiks
Copy link
Contributor Author

kckeiks commented Apr 6, 2022

@cjgillot I imagine that the performance regression comes from the traversal that the visitor does in hir_crate_items.

@kckeiks kckeiks force-pushed the create-hir-crate-items-query branch from 36043bf to 88108bd Compare April 9, 2022 20:04
@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2022
@bors
Copy link
Contributor

bors commented Apr 10, 2022

⌛ Trying commit 88108bd with merge be80ce668cc66c6c4748400d6a1d7fe5bf440436...

@bors
Copy link
Contributor

bors commented Apr 10, 2022

☀️ Try build successful - checks-actions
Build commit: be80ce668cc66c6c4748400d6a1d7fe5bf440436 (be80ce668cc66c6c4748400d6a1d7fe5bf440436)

@rust-timer
Copy link
Collaborator

Queued be80ce668cc66c6c4748400d6a1d7fe5bf440436 with parent f7b4824, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (be80ce668cc66c6c4748400d6a1d7fe5bf440436): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 24 27 0 0 24
mean2 0.3% 0.7% N/A N/A 0.3%
max 0.5% 1.3% N/A N/A 0.5%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2022
@cjgillot
Copy link
Contributor

This PR is the first in a series that should significantly reduce full-HIR traversal by queries. This is expected to bring improvements to incremental compilation, by decreasing result invalidation. This first PR creates the infrastructure for this change, as a new query hir_crate_items. This query does traverse the full HIR to record all definitions in order of appearance, so is quite slow to compute. The overall regression is 0.5% on primary benchmarks, this should be compensated when follow-up PRs land.
@rustbot label: +perf-regression-triaged

@bors r+

@bors
Copy link
Contributor

bors commented Apr 17, 2022

📌 Commit 88108bd has been approved by cjgillot

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Apr 17, 2022
@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 Apr 17, 2022
@bors
Copy link
Contributor

bors commented Apr 17, 2022

⌛ Testing commit 88108bd with merge edba282...

@bors
Copy link
Contributor

bors commented Apr 17, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing edba282 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 17, 2022
@bors bors merged commit edba282 into rust-lang:master Apr 17, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 17, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (edba282): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: mixed results
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 33 32 0 3 33
mean2 0.3% 0.7% N/A -1.0% 0.3%
max 0.4% 1.6% N/A -1.0% 0.4%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 21, 2022
… r=cjgillot

Refactor HIR item-like traversal (part 1)

Issue  rust-lang#95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>

cc `@cjgillot`
@kckeiks kckeiks mentioned this pull request Jun 11, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

None yet

8 participants