Closed
Description
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 inrustc_middle::hir::ModuleItems
; - fill
body_owners
in the two queries' visitors; - use
hir_crate_items(()).body_owners
intcx.hir().{,par_}body_owners
instead of iterating ontcx.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 aLocalDefId
as a parameter; - refactor
tcx.hir().enclosing_body_owner
to return aLocalDefId
.