From 1458d8126843fc750909b39f4d00b586d4cd1439 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:10:36 +0000 Subject: [PATCH] refactor(visit): add `#[inline]` to empty functions (#4330) 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. --- crates/oxc_ast/src/generated/visit.rs | 4 ++++ crates/oxc_ast/src/generated/visit_mut.rs | 4 ++++ tasks/ast_codegen/src/generators/visit.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/crates/oxc_ast/src/generated/visit.rs b/crates/oxc_ast/src/generated/visit.rs index b953314fc94e6..79a63005754d4 100644 --- a/crates/oxc_ast/src/generated/visit.rs +++ b/crates/oxc_ast/src/generated/visit.rs @@ -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>) {} + #[inline] fn leave_scope(&mut self) {} #[inline] diff --git a/crates/oxc_ast/src/generated/visit_mut.rs b/crates/oxc_ast/src/generated/visit_mut.rs index d0961c65f275d..37343df6f46fe 100644 --- a/crates/oxc_ast/src/generated/visit_mut.rs +++ b/crates/oxc_ast/src/generated/visit_mut.rs @@ -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>) {} + #[inline] fn leave_scope(&mut self) {} #[inline] diff --git a/tasks/ast_codegen/src/generators/visit.rs b/tasks/ast_codegen/src/generators/visit.rs index 67a988dcaee45..a912c5941022c 100644 --- a/tasks/ast_codegen/src/generators/visit.rs +++ b/tasks/ast_codegen/src/generators/visit.rs @@ -122,12 +122,16 @@ fn generate_visit(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>) {} + #[inline] fn leave_scope(&mut self) {} endl!();