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
.
ItemLocalId
s 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 ItemLocalId
s.
Steps:
- in
rustc_passes::hir_id_validator
, add a check that theItemLocalId
of the parent of each node has a lower value that theItemLocalId
of the node itself; - change
rustc_ast_lowering
, in particular calls tolower_node_id
andnext_id
until the tests pass.
Bonus: manage to get the order of ItemLocalId
s be the order in which a HIR visitor (defined in rustc_hir::intravisit
) visits all the HirId
s.
I recommend using -Zunpretty=hir-tree
to debug. Please contact me on zulip for any question.