Skip to content

Assign HirIds in HIR traversal order #102522

Closed
@cjgillot

Description

@cjgillot

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 the ItemLocalId of the parent of each node has a lower value that the ItemLocalId of the node itself;
  • change rustc_ast_lowering, in particular calls to lower_node_id and next_id until 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-HIRArea: The high-level intermediate representation (HIR)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions