From 3bf31148ba5058323ee89bb2ca74b641c52c0669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 4 Jun 2024 18:51:25 +0900 Subject: [PATCH] perf(es/parser): Add feature named `tracing-spans` (#9019) --- crates/swc_ecma_parser/Cargo.toml | 9 ++++--- crates/swc_ecma_parser/src/parser/expr.rs | 26 +++++++++---------- .../swc_ecma_parser/src/parser/typescript.rs | 6 ++--- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/crates/swc_ecma_parser/Cargo.toml b/crates/swc_ecma_parser/Cargo.toml index 64d847b64135..32a45538b8d1 100644 --- a/crates/swc_ecma_parser/Cargo.toml +++ b/crates/swc_ecma_parser/Cargo.toml @@ -18,10 +18,11 @@ bench = false [features] # Used for debugging -debug = [] -default = ["typescript", "stacker"] -typescript = [] -verify = ["swc_ecma_visit"] +debug = ["tracing-spans"] +default = ["typescript", "stacker"] +tracing-spans = [] +typescript = [] +verify = ["swc_ecma_visit"] [dependencies] either = { workspace = true } diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index 230512c94a98..adfe50c77988 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -34,7 +34,7 @@ impl Parser { } ///`parseMaybeAssign` (overridden) - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_assignment_expr(&mut self) -> PResult> { trace_cur!(self, parse_assignment_expr); @@ -76,7 +76,7 @@ impl Parser { /// operators like `+=`. /// /// `parseMaybeAssign` - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_assignment_expr_base(&mut self) -> PResult> { trace_cur!(self, parse_assignment_expr_base); let start = self.input.cur_span(); @@ -208,7 +208,7 @@ impl Parser { } /// Spec: 'ConditionalExpression' - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_cond_expr(&mut self) -> PResult> { trace_cur!(self, parse_cond_expr); @@ -245,7 +245,7 @@ impl Parser { } /// Parse a primary expression or arrow function - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_primary_expr(&mut self) -> PResult> { trace_cur!(self, parse_primary_expr); @@ -493,7 +493,7 @@ impl Parser { syntax_error!(self, self.input.cur_span(), SyntaxError::TS1109) } - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_array_lit(&mut self) -> PResult> { trace_cur!(self, parse_array_lit); @@ -535,7 +535,7 @@ impl Parser { } /// `is_new_expr`: true iff we are parsing production 'NewExpression'. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_member_expr_or_new_expr(&mut self, is_new_expr: bool) -> PResult> { let ctx = Context { should_not_lex_lt_or_gt_as_type: true, @@ -678,7 +678,7 @@ impl Parser { /// Parse `NewExpression`. /// This includes `MemberExpression`. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_new_expr(&mut self) -> PResult> { trace_cur!(self, parse_new_expr); @@ -686,7 +686,7 @@ impl Parser { } /// Parse `Arguments[Yield, Await]` - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_args(&mut self, is_dynamic_import: bool) -> PResult> { trace_cur!(self, parse_args); @@ -759,7 +759,7 @@ impl Parser { } /// Parse paren expression or arrow function expression. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_paren_expr_or_arrow_fn( &mut self, can_be_arrow: bool, @@ -1091,7 +1091,7 @@ impl Parser { }) } - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_subscripts( &mut self, mut obj: Callee, @@ -1108,7 +1108,7 @@ impl Parser { } /// returned bool is true if this method should be called again. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] fn parse_subscript( &mut self, start: BytePos, @@ -1544,7 +1544,7 @@ impl Parser { } /// Parse call, dot, and `[]`-subscript expressions. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_lhs_expr(&mut self) -> PResult> { trace_cur!(self, parse_lhs_expr); @@ -1681,7 +1681,7 @@ impl Parser { } // Returns (args_or_pats, trailing_comma) - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_args_or_pats( &mut self, ) -> PResult<(Vec, Option)> { diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs index dc960d7c38be..b02fa7d5c2dc 100644 --- a/crates/swc_ecma_parser/src/parser/typescript.rs +++ b/crates/swc_ecma_parser/src/parser/typescript.rs @@ -570,7 +570,7 @@ impl Parser { } } - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn try_parse_ts_type_args(&mut self) -> Option> { trace_cur!(self, try_parse_ts_type_args); debug_assert!(self.input.syntax().typescript()); @@ -642,7 +642,7 @@ impl Parser { } } - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn parse_ts_type_ann( &mut self, eat_colon: bool, @@ -1972,7 +1972,7 @@ impl Parser { } /// `tsTryParseTypeAnnotation` - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + #[cfg_attr(feature = "tracing-spans", tracing::instrument(skip_all))] pub(super) fn try_parse_ts_type_ann(&mut self) -> PResult>> { if !cfg!(feature = "typescript") { return Ok(None);