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.
Functions, constants and statics have an associated
hir::Bodyand 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_itemsandhir_crate_itemsquery. The secondary objective is to reduce the number of queries that directly depend on the full HIR query (hir_crate).Instructions:
body_owners: Box<[LocalDefId]>field inrustc_middle::hir::ModuleItems;body_ownersin the two queries' visitors;hir_crate_items(()).body_ownersintcx.hir().{,par_}body_ownersinstead of iterating ontcx.hir().krate().The following steps are a possible cleanup to avoid a few back-and-forth conversions between
LocalDefIdandHirId:tcx.hir().{,maybe_}body_owned_byto take aLocalDefIdas a parameter;tcx.hir().enclosing_body_ownerto return aLocalDefId.