Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve oxc_traverse #3209

Open
11 tasks
overlookmotel opened this issue May 8, 2024 · 0 comments
Open
11 tasks

Improve oxc_traverse #3209

overlookmotel opened this issue May 8, 2024 · 0 comments
Assignees
Labels
A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Comments

@overlookmotel
Copy link
Collaborator

overlookmotel commented May 8, 2024

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 ancestor_type2 branch (on my local machine).
    • 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.
  • API to get which index current node is in a Vec.
  • 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.
  • Move Span to constant position in all structs, for fast lookup?
@overlookmotel overlookmotel added the C-bug Category - Bug label May 8, 2024
@overlookmotel overlookmotel assigned Boshen and overlookmotel and unassigned Boshen May 8, 2024
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-transformer Area - Transformer / Transpiler and removed C-bug Category - Bug labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior
Projects
None yet
Development

No branches or pull requests

2 participants