oxc-project / oxc-project/backlog

Improve `oxc_traverse`

Open
#128 0 comments 0 reactions 1 assignee View on GitHub

@overlookmotel is already working on this.

Since May 8, 2024.

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

Description

Various improvements to make to oxc_traverse:

  • Implement ScopeFlags (ctx.scope()).
  • Reduce the size of ancestor.rs by using generics instead of repetition for *Without* types.
  • Add TraverseCtx::has_ancestor method where closure returns true or false
    (or maybe Some(true), Some(false) or None)
  • Check that TraverseCtx::find_ancestor can return an ancestor node that it found.
  • Set enum discriminants for Ancestor so that is_* can use bitwise ops + retag_stack can write 1 byte only.
    • Compiler does not auto-optimize matches!() in is_* functions. Need to do it manually.
    • See overlookmotel/ancestor_type branch.
    • Need to handle big endian systems where bytes are in reverse order.
      • That's easy, but how to run tests on big endian? Miri?
  • Implement Debug for Ancestor and *Without* types
    • Implement intermediate as_ref method which creates a struct of references, which Debug can use.
  • Improve API for Ancestor::is_via_*
  • API to read siblings in a Vec (see oxc-project/backlog#138).
  • API to get which index current node is in a Vec (see oxc-project/backlog#138).
  • API to allow mutating other branches of AST
    • I think all that's required is to:
      • Pass &mut TraverseCtx to enter_* and exit_*
      • Add parent_mut, ancestor_mut methods to TraverseCtx
      • Add span_mut, directives_mut etc to all *Without* types
    • Mutable borrow on TraverseCtx and Ancestor prevents creating more than 1 mut ref at a time
    • Mutable borrow on TraverseCtx unfortunately also blocks calling ctx.alloc().
      • Can solve that with e.g. ctx.ancestry.parent_mut() + ctx.ast.alloc() - separate properties
        can be mut borrowed at same time.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.