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

Gather body owners in hir_module_items and hir_crate_items #96341

Closed
cjgillot opened this issue Apr 23, 2022 · 4 comments
Closed

Gather body owners in hir_module_items and hir_crate_items #96341

cjgillot opened this issue Apr 23, 2022 · 4 comments
Assignees
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@cjgillot
Copy link
Contributor

cjgillot commented Apr 23, 2022

Functions, constants and statics have an associated hir::Body and are known as body owners. Typechecking and MIR generation work by iterating over all the body owners in the crate. This iteration traverses the full HIR.

The objective is to avoid repeated traversal of the full HIR by reusing the traversal done by hir_module_items and hir_crate_items query. The secondary objective is to reduce the number of queries that directly depend on the full HIR query (hir_crate).

Instructions:

  • create a body_owners: Box<[LocalDefId]> field in rustc_middle::hir::ModuleItems;
  • fill body_owners in the two queries' visitors;
  • use hir_crate_items(()).body_owners in tcx.hir().{,par_}body_owners instead of iterating on tcx.hir().krate().

The following steps are a possible cleanup to avoid a few back-and-forth conversions between LocalDefId and HirId:

  • refactor tcx.hir().{,maybe_}body_owned_by to take a LocalDefId as a parameter;
  • refactor tcx.hir().enclosing_body_owner to return a LocalDefId.
@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Apr 23, 2022
@kckeiks
Copy link
Contributor

kckeiks commented Apr 23, 2022

@rustbot claim

@bentongxyz
Copy link
Contributor

Hi, may I ask if this is currently being worked on? I would like to give it a try if not!
Thank you!

@kckeiks
Copy link
Contributor

kckeiks commented May 9, 2022

yes, it is being worked on.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 15, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 30, 2022
…, r=cjgillot

change maybe_body_owned_by to take local def id

Issue rust-lang#96341
r? `@cjgillot`
@Dylan-DPC
Copy link
Member

Completed by #96341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

4 participants