Skip to content

Commit

Permalink
refactor(visit): add #[inline] to empty functions (#4330)
Browse files Browse the repository at this point in the history
Add `#[inline]` to empty default implementations of `enter_node` etc. Hopefully compiler will inline them automatically within Oxc even cross-crate because we compile with LTO, but maybe not for external consumers who don't use LTO.
  • Loading branch information
overlookmotel committed Jul 17, 2024
1 parent 650615c commit 1458d81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ use walk::*;

/// Syntax tree traversal
pub trait Visit<'a>: Sized {
#[inline]
fn enter_node(&mut self, kind: AstKind<'a>) {}
#[inline]
fn leave_node(&mut self, kind: AstKind<'a>) {}

#[inline]
fn enter_scope(&mut self, flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {}
#[inline]
fn leave_scope(&mut self) {}

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ use walk_mut::*;

/// Syntax tree traversal
pub trait VisitMut<'a>: Sized {
#[inline]
fn enter_node(&mut self, kind: AstType) {}
#[inline]
fn leave_node(&mut self, kind: AstType) {}

#[inline]
fn enter_scope(&mut self, flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {}
#[inline]
fn leave_scope(&mut self) {}

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions tasks/ast_codegen/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ fn generate_visit<const MUT: bool>(ctx: &CodegenCtx) -> TokenStream {

/// Syntax tree traversal
pub trait #trait_name <'a>: Sized {
#[inline]
fn enter_node(&mut self, kind: #ast_kind_type #ast_kind_life) {}
#[inline]
fn leave_node(&mut self, kind: #ast_kind_type #ast_kind_life) {}

endl!();

#[inline]
fn enter_scope(&mut self, flags: ScopeFlags, scope_id: &Cell<Option<ScopeId>>) {}
#[inline]
fn leave_scope(&mut self) {}

endl!();
Expand Down

0 comments on commit 1458d81

Please sign in to comment.