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

perf(es/parser): Add feature named tracing-spans #9019

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/swc_ecma_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
26 changes: 13 additions & 13 deletions crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<I: Tokens> Parser<I> {
}

///`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<Box<Expr>> {
trace_cur!(self, parse_assignment_expr);

Expand Down Expand Up @@ -76,7 +76,7 @@ impl<I: Tokens> Parser<I> {
/// 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<Box<Expr>> {
trace_cur!(self, parse_assignment_expr_base);
let start = self.input.cur_span();
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<I: Tokens> Parser<I> {
}

/// 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<Box<Expr>> {
trace_cur!(self, parse_cond_expr);

Expand Down Expand Up @@ -245,7 +245,7 @@ impl<I: Tokens> Parser<I> {
}

/// 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<Box<Expr>> {
trace_cur!(self, parse_primary_expr);

Expand Down Expand Up @@ -493,7 +493,7 @@ impl<I: Tokens> Parser<I> {
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<Box<Expr>> {
trace_cur!(self, parse_array_lit);

Expand Down Expand Up @@ -535,7 +535,7 @@ impl<I: Tokens> Parser<I> {
}

/// `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<Box<Expr>> {
let ctx = Context {
should_not_lex_lt_or_gt_as_type: true,
Expand Down Expand Up @@ -678,15 +678,15 @@ impl<I: Tokens> Parser<I> {

/// 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<Box<Expr>> {
trace_cur!(self, parse_new_expr);

self.parse_member_expr_or_new_expr(true)
}

/// 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<Vec<ExprOrSpread>> {
trace_cur!(self, parse_args);

Expand Down Expand Up @@ -759,7 +759,7 @@ impl<I: Tokens> Parser<I> {
}

/// 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,
Expand Down Expand Up @@ -1091,7 +1091,7 @@ impl<I: Tokens> Parser<I> {
})
}

#[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,
Expand All @@ -1108,7 +1108,7 @@ impl<I: Tokens> Parser<I> {
}

/// 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,
Expand Down Expand Up @@ -1544,7 +1544,7 @@ impl<I: Tokens> Parser<I> {
}

/// 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<Box<Expr>> {
trace_cur!(self, parse_lhs_expr);

Expand Down Expand Up @@ -1681,7 +1681,7 @@ impl<I: Tokens> Parser<I> {
}

// 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<AssignTargetOrSpread>, Option<Span>)> {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<I: Tokens> Parser<I> {
}
}

#[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<Box<TsTypeParamInstantiation>> {
trace_cur!(self, try_parse_ts_type_args);
debug_assert!(self.input.syntax().typescript());
Expand Down Expand Up @@ -642,7 +642,7 @@ impl<I: Tokens> Parser<I> {
}
}

#[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,
Expand Down Expand Up @@ -1972,7 +1972,7 @@ impl<I: Tokens> Parser<I> {
}

/// `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<Option<Box<TsTypeAnn>>> {
if !cfg!(feature = "typescript") {
return Ok(None);
Expand Down
Loading