Skip to content

Commit

Permalink
refactor(ast): get rid of unsafe transmutation in VisitMut trait. (#2764
Browse files Browse the repository at this point in the history
)

This will close #2745,

In this PR I attempt to fix this issue using a combination of ideas
discussed in the issue mentioned above, I've created this early draft so
people can pitch in if there is something I should consider doing.

The first goal of this PR is to resolve the issue with the possible
illegal references, As a result of my approach it would also end up with
a bunch of walk_* and walk_*_mut functions to help with the abstraction.
I want to eliminate enter_node and leave_node functions, but I still
haven't started working on it since I first want to familiarize myself
with all of its usage throughout the project. I'm hesitating to do it at
the moment, When we want to do this it would require quite a bit of
refactoring so we should make sure it is probably going to work and end
up being a better implementation.
  • Loading branch information
rzvxa committed Mar 23, 2024
1 parent d9b77d8 commit 813226b
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 266 deletions.
19 changes: 16 additions & 3 deletions crates/oxc_ast/src/ast_kind.rs
Expand Up @@ -3,9 +3,22 @@ use oxc_span::{Atom, GetSpan, Span};
#[allow(clippy::wildcard_imports)]
use crate::ast::*;

/// Untyped AST Node Kind
#[derive(Debug, Clone, Copy)]
pub enum AstKind<'a> {
macro_rules! ast_kinds {
{ $($ident:ident($type:ty),)* } => (
#[derive(Debug, Clone, Copy)]
pub enum AstType {
$($ident,)*
}

/// Untyped AST Node Kind
#[derive(Debug, Clone, Copy)]
pub enum AstKind<'a> {
$($ident($type),)*
}
)
}

ast_kinds! {
Program(&'a Program<'a>),
Directive(&'a Directive<'a>),
Hashbang(&'a Hashbang<'a>),
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/lib.rs
Expand Up @@ -20,13 +20,13 @@ mod span;
pub mod syntax_directed_operations;
mod trivia;
mod visit;
mod visit_mut;
pub mod visit_mut;

pub use num_bigint::BigUint;

pub use crate::{
ast_builder::AstBuilder,
ast_kind::AstKind,
ast_kind::{AstKind, AstType},
trivia::{Comment, CommentKind, Trivias, TriviasMap},
visit::Visit,
visit_mut::VisitMut,
Expand Down

0 comments on commit 813226b

Please sign in to comment.