-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Description
AST->HIR lowering assigns a HirId to most nodes in the HIR tree. The HirId consists of an OwnerId, which tells to which item (function, trait, associated function...) a node belongs to, and an ItemLocalId which is its index inside that OwnerId.
ItemLocalIds are assigned in the order they are created during lowering, by a simple counter. As a consequence, their values when looking at the HIR tree do not follow a consistent order. Making that order consistent may help simplifying some code that needs to visit HIR when it may just iterate on ItemLocalIds.
Steps:
- in
rustc_passes::hir_id_validator, add a check that theItemLocalIdof the parent of each node has a lower value that theItemLocalIdof the node itself; - change
rustc_ast_lowering, in particular calls tolower_node_idandnext_iduntil the tests pass.
Bonus: manage to get the order of ItemLocalIds be the order in which a HIR visitor (defined in rustc_hir::intravisit) visits all the HirIds.
I recommend using -Zunpretty=hir-tree to debug. Please contact me on zulip for any question.