-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Refactor HIR item-like traversal #95004
Copy link
Copy link
Open
Labels
A-HIRArea: The high-level intermediate representation (HIR)Area: The high-level intermediate representation (HIR)E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Metadata
Metadata
Assignees
Labels
A-HIRArea: The high-level intermediate representation (HIR)Area: The high-level intermediate representation (HIR)E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Type
Fields
Give feedbackNo fields configured for issues without a type.
HIR is globally traversed using the
tcx.hir().{,par_}visit_all_item_likes{,_in_module}family of functions. These functions create a lot of dependency edges (they call thehir_cratequery, or callhir_ownerfor each item-like). These dependencies are not always useful: many use sites only requireitems, and don't care for impl items, trait items or foreign items.This can be avoided by replacing those functions by a scheme based on
ItemIds. Actual user will be responsible for callingtcx.hir().itemto get the HIR. The amount of access to HIR will be further reduced by pre-filtering usingtcx.def_kindquery.Steps:
hir_crate_itemsquery which traversestcx.hir_crate(()).ownersto collect all the ids and return arustc_middle::hir::ModuleItems;tcx.hir_crate_itemsintcx.hir().itemsto return an iterator ofhir::ItemId;tcx.hir_crate_itemsto introduce atcx.hir().par_items(impl Fn(hir::ItemId))to traverse all items in parallel;tcx.hir().{,par_}visit_all_item_likeswithtcx.hir().par_itemsortcx.hir().items;when possible, create a fast path using
tcx.def_kind(item_id.def_id)before callingtcx.hir().item(item_id);tcx.hir().items_in_moduleandtcx.hir().par_items_in_modulewhich do the same thing withtcx.hir_module_itemsinstead oftcx.hir_crate_items;tcx.hir().visit_all_item_likes_in_modulewithtcx.hir().par_items_in_moduleortcx.hir().items_in_module;hir::ItemLikeVisitor.The steps starting with "gradually" can be split into several PRs.
I am available on zulip for any question.