Skip to content

Gather body owners in hir_module_items and hir_crate_items #96341

Closed
@cjgillot

Description

@cjgillot

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.

Metadata

Metadata

Assignees

Labels

E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions