oxc-project / oxc-project/backlog

`TraverseAncestry::current_address` to get address of current node

Open
#140 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
7
Forks
0
PR merge metrics
No merged PRs in 30d

Description

See: https://github.com/oxc-project/oxc/pull/6881#discussion_r1816560516

We want to avoid implementing GetAddress for &T because it's error-prone. But often in transformer you only have a &T not a &Box<T> and want to get it's address (e.g. in a visitor like exit_function).

This is legitimate because the &mut T passed into visitor function is always a reference to value in the arena.

We could achieve this by:

  • Pushing Ancestor to the stack of ancestors before calling enter_* and pop it after calling exit_*.
  • TraverseAncestry::parent return not stack.last() but 1 ancestor before it.
  • TraverseAncestry::ancestor return the item at index last_index - level - 1 (not last_index - level).
  • TraverseAncestry::ancestors skip the last item on stack.
  • Always push to ancestors stack in all walk_* functions (I think we skip that for leaf nodes at present).

Then existing APIs behave as they do now, but TraverseAncestry::current_address can get the address of the current node with stack.last().address().

Problem: What about visitors for enums e.g. Expression? current_address would return the address of parent node, because enums don't get an Ancestor. Either:

  1. Live with it. or
  2. Move pushing to ancestor stack up into the walk_* functions for enums (a bit tricky, because some nodes don't always live within an enum).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked discussion and inspect the TraverseAncestry entry points: current_address, parent, ancestor, ancestors, the enter_* and exit_* callbacks, and the walk_* functions. The work is complete when current_address can identify the current node without changing existing ancestry behavior, with the enum-node case explicitly resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.