Skip to content

refactor: Use debug level tracing for ast related tracing #10411

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

Merged
merged 3 commits into from
Apr 29, 2025
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
16 changes: 16 additions & 0 deletions .changeset/smooth-parrots-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
swc_core: patch
swc_ecma_codegen: patch
swc_ecma_compat_es2015: patch
swc_ecma_compat_es2016: patch
swc_ecma_compat_es2017: patch
swc_ecma_compat_es2018: patch
swc_ecma_compat_es2020: patch
swc_ecma_minifier: patch
swc_ecma_parser: patch
swc_ecma_transforms_optimization: patch
swc_ecma_usage_analyzer: patch
swc_trace_macro: patch
---

fix: use debug level tracing for ast related tracing
4 changes: 2 additions & 2 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ impl MacroNode for Program {

#[node_impl]
impl MacroNode for Module {
#[tracing::instrument(skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn emit(&mut self, emitter: &mut Macro) -> Result {
emitter.emit_leading_comments_of_span(self.span(), false)?;

Expand Down Expand Up @@ -1443,7 +1443,7 @@ impl MacroNode for Module {

#[node_impl]
impl MacroNode for Script {
#[tracing::instrument(skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn emit(&mut self, emitter: &mut Macro) -> Result {
emitter.emit_leading_comments_of_span(self.span(), false)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_compat_es2015/src/classes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ impl Classes {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn inject_class_call_check(c: &mut Vec<Stmt>, name: Ident) {
let mut class_name_sym = name.clone();
class_name_sym.span = DUMMY_SP;
Expand All @@ -956,7 +956,7 @@ fn inject_class_call_check(c: &mut Vec<Stmt>, name: Ident) {
}

/// Returns true if no `super` is used before `super()` call.
#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn is_always_initialized(body: &[Stmt]) -> bool {
struct SuperFinder {
found: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ fn make_ref_ident(c: Config, decls: &mut Vec<VarDeclarator>, init: Option<Box<Ex
make_ref_ident_for_array(c, decls, init, None)
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn make_ref_ident_for_array(
c: Config,
decls: &mut Vec<VarDeclarator>,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/for_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl ForOf {
/// }
/// }
/// ```
#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn make_finally_block(
iterator_return: Box<Expr>,
normal_completion_ident: &Ident,
Expand Down
8 changes: 4 additions & 4 deletions crates/swc_ecma_compat_es2015/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ impl VisitMut for Generator {
}
}

#[tracing::instrument(skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn visit_mut_stmt(&mut self, node: &mut Stmt) {
match node {
Stmt::Break(b) => {
Expand Down Expand Up @@ -3089,7 +3089,7 @@ impl Generator {
});
}

#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "debug", skip(self))]
fn try_enter_label(&mut self, op_index: usize) {
if self.label_offsets.is_none() {
return;
Expand Down Expand Up @@ -3143,7 +3143,7 @@ impl Generator {
}

/// Tries to enter or leave a code block.
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "debug", skip(self))]
fn try_enter_or_leave_block(&mut self, op_index: usize) {
if let Some(blocks) = &self.blocks {
while self.block_index < self.block_actions.as_ref().unwrap().len()
Expand Down Expand Up @@ -3210,7 +3210,7 @@ impl Generator {

/// Writes an operation as a statement to the current label's statement
/// list.
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "debug", skip(self))]
fn write_operation(&mut self, op_index: usize) {
if cfg!(debug_assertions) {
debug!("Writing operation {}", op_index);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl Spread {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn expand_literal_args(
args: impl ExactSizeIterator<Item = Option<ExprOrSpread>>,
) -> Vec<Option<ExprOrSpread>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/typeof_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl VisitMut for TypeOfSymbol {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn is_non_symbol_literal(e: &Expr) -> bool {
match e {
Expr::Lit(Lit::Str(Str { value, .. })) => matches!(
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2016/src/exponentiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl VisitMut for Exponentiation {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn mk_call(span: Span, left: Box<Expr>, right: Box<Expr>) -> Expr {
// Math.pow()
CallExpr {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_compat_es2017/src/async_to_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl VisitMut for AsyncToGenerator {
/// Creates
///
/// `_async_to_generator(function*() {})()` from `async function() {}`;
#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn make_fn_ref(fn_state: &FnState, params: Vec<Param>, body: BlockStmt) -> Expr {
let helper = if fn_state.is_generator {
helper_expr!(PURE_SP, wrap_async_generator)
Expand Down Expand Up @@ -439,7 +439,7 @@ fn make_fn_ref(fn_state: &FnState, params: Vec<Param>, body: BlockStmt) -> Expr
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn could_potentially_throw(param: &[Param], unresolved_ctxt: SyntaxContext) -> bool {
for param in param {
debug_assert!(param.decorators.is_empty());
Expand Down Expand Up @@ -500,7 +500,7 @@ impl Check for ShouldWork {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn handle_await_for(stmt: &mut Stmt, is_async_generator: bool) {
let s = match stmt {
Stmt::ForOf(s @ ForOfStmt { is_await: true, .. }) => s.take(),
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_compat_es2018/src/object_rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl ObjectRest {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn object_without_properties(
obj: Box<Expr>,
excluded_props: Vec<Option<ExprOrSpread>>,
Expand Down Expand Up @@ -967,7 +967,7 @@ fn object_without_properties(
.into()
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn excluded_props(props: &[ObjectPatProp]) -> Vec<Option<ExprOrSpread>> {
props
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl VisitMut for NullishCoalescing {
}
}

#[tracing::instrument(level = "info", skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn make_cond(c: Config, span: Span, alias: &Ident, var_expr: Expr, init: Box<Expr>) -> Expr {
if c.no_document_all {
CondExpr {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_minifier/src/compress/optimize/iife.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Optimizer<'_> {
/// })(x);
/// })(7);
/// ```
#[cfg_attr(feature = "debug", tracing::instrument(skip(self, e)))]
#[cfg_attr(feature = "debug", tracing::instrument(level = "debug", skip(self, e)))]
pub(super) fn inline_args_of_iife(&mut self, e: &mut CallExpr) {
if self.options.inline == 0 && !self.options.reduce_vars && !self.options.reduce_fns {
return;
Expand Down Expand Up @@ -409,7 +409,7 @@ impl Optimizer<'_> {
}
}

#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
#[cfg_attr(feature = "debug", tracing::instrument(level = "debug", skip_all))]
pub(super) fn inline_vars_in_node<N>(&mut self, n: &mut N, mut vars: FxHashMap<Id, Box<Expr>>)
where
N: for<'aa> VisitMutWith<NormalMultiReplacer<'aa>>,
Expand Down
Loading
Loading