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/visit): Introduce standard_only_* macros #9207

Merged
merged 65 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
783054d
Dep
kdy1 Jul 11, 2024
04ce3a9
cargo lockfile
kdy1 Jul 11, 2024
d227521
Visitor
kdy1 Jul 11, 2024
b076c47
cargo lockfile
kdy1 Jul 11, 2024
af051b2
Drop dep
kdy1 Jul 11, 2024
5715330
cargo lockfile
kdy1 Jul 11, 2024
067ac37
Add `visit_mut_only_standard`
kdy1 Jul 11, 2024
fdf7cc1
`standard_only_visit`
kdy1 Jul 11, 2024
b8c8d40
Replace
kdy1 Jul 11, 2024
c92f19a
Replace
kdy1 Jul 11, 2024
8903da5
replace
kdy1 Jul 11, 2024
f7d7799
standard-only
kdy1 Jul 11, 2024
fe9c9e3
replace
kdy1 Jul 11, 2024
fc4a5a3
replace
kdy1 Jul 11, 2024
f7dc82f
Improve macros
kdy1 Jul 11, 2024
62f445b
Improve macro
kdy1 Jul 11, 2024
2df2e50
More fix
kdy1 Jul 11, 2024
4515889
More fix
kdy1 Jul 11, 2024
c74f5cf
More fix
kdy1 Jul 11, 2024
ef17a72
More fix
kdy1 Jul 11, 2024
d7015a6
More fix
kdy1 Jul 11, 2024
78a3a22
More fix
kdy1 Jul 11, 2024
d9db7ec
More fix
kdy1 Jul 11, 2024
fc51a73
More fix
kdy1 Jul 11, 2024
e025f00
More fix
kdy1 Jul 11, 2024
48149ff
More fix
kdy1 Jul 11, 2024
8bb65f4
More fix
kdy1 Jul 11, 2024
31609a1
More fix
kdy1 Jul 11, 2024
2c1d06a
More fix
kdy1 Jul 11, 2024
36d492b
More fix
kdy1 Jul 11, 2024
98dec73
More fix
kdy1 Jul 11, 2024
ac460f6
More fix
kdy1 Jul 11, 2024
429a43e
More fix
kdy1 Jul 11, 2024
c859dcf
only
kdy1 Jul 11, 2024
16820be
fix
kdy1 Jul 11, 2024
22874bf
fix
kdy1 Jul 11, 2024
8d79beb
fix
kdy1 Jul 11, 2024
d32b584
dep
kdy1 Jul 11, 2024
f15d459
cargo lockfille
kdy1 Jul 11, 2024
281be90
Use ts
kdy1 Jul 11, 2024
eae9450
FIx TS+ module
kdy1 Jul 11, 2024
70e1434
Fix typescript pass
kdy1 Jul 11, 2024
5cdf7e6
Fix mark
kdy1 Jul 11, 2024
ad088f1
fix assertion
kdy1 Jul 11, 2024
95c9a4a
Update test refs
kdy1 Jul 11, 2024
3e69347
Remove dce-jsx
kdy1 Jul 11, 2024
7aba1ec
fix test
kdy1 Jul 11, 2024
d962ca3
fix test
kdy1 Jul 11, 2024
364a82d
fix more
kdy1 Jul 11, 2024
5cb3eea
Update test refs
kdy1 Jul 11, 2024
6f5ad6c
Fix mark
kdy1 Jul 11, 2024
e10de6a
Update test refs
kdy1 Jul 11, 2024
b73b1c1
Fix utils
kdy1 Jul 11, 2024
ae06062
REstore
kdy1 Jul 11, 2024
8bfecc5
FIx mark
kdy1 Jul 11, 2024
add0073
FIx mark
kdy1 Jul 11, 2024
53c7f61
Update test refs
kdy1 Jul 11, 2024
97569e0
`fixer`
kdy1 Jul 11, 2024
3bf6a9c
fix visitor
kdy1 Jul 11, 2024
ebea7aa
fix
kdy1 Jul 11, 2024
0c801f0
Fix swc loader
kdy1 Jul 11, 2024
3346013
Update test refs
kdy1 Jul 11, 2024
6ee4638
fix fixer
kdy1 Jul 11, 2024
db0a06b
fix
kdy1 Jul 11, 2024
a2f557c
Merge branch 'main' into issue-9204
kdy1 Jul 11, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/dbg-swc/src/util/minifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use swc_common::{FileName, SourceMap};
use swc_ecma_ast::*;
use swc_ecma_minifier::option::{CompressOptions, MangleOptions, MinifyOptions};
use swc_ecma_transforms_base::fixer::fixer;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith};

use super::{parse_js, print_js, wrap_task, ModuleRecord};

Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn get_esbuild_output(file: &Path, mangle: bool) -> Result<String> {
struct Normalizer {}

impl VisitMut for Normalizer {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_prop(&mut self, p: &mut Prop) {
p.visit_mut_children_with(self);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/benches/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn as_es(c: &swc::Compiler) -> Program {

program
.fold_with(&mut resolver(unresolved_mark, top_level_mark, true))
.fold_with(&mut typescript::strip(top_level_mark))
.fold_with(&mut typescript::strip(unresolved_mark, top_level_mark))
}

fn base_tr_group(c: &mut Criterion) {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use swc_ecma_transforms::{
pass::Optional,
resolver, Assumptions,
};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut, VisitMutWith};

use crate::config::{CompiledPaths, GlobalPassOption, JsMinifyOptions, ModuleConfig};

Expand Down Expand Up @@ -382,7 +382,7 @@ struct MinifierPass<'a> {
}

impl VisitMut for MinifierPass<'_> {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_module(&mut self, m: &mut Module) {
if let Some(options) = &self.options {
Expand Down
1 change: 1 addition & 0 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ impl Options {
),
},
comments.map(|v| v as _),
unresolved_mark,
top_level_mark
),
syntax.typescript()
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/src/dropped_comments_preserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use swc_common::{
BytePos, Span, DUMMY_SP,
};
use swc_ecma_ast::{Module, Script};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith};

/// Preserves comments that would otherwise be dropped.
///
Expand Down Expand Up @@ -36,7 +36,7 @@ struct DroppedCommentsPreserver {
type CommentEntries = Vec<(BytePos, Vec<Comment>)>;

impl VisitMut for DroppedCommentsPreserver {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_module(&mut self, module: &mut Module) {
module.visit_mut_children_with(self);
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/rust_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use swc_common::{comments::SingleThreadedComments, FileName};
use swc_ecma_ast::*;
use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax};
use swc_ecma_transforms::pass::noop;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, VisitMut};

struct PanicOnVisit;

impl VisitMut for PanicOnVisit {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_number(&mut self, n: &mut Number) {
panic!("Expected {:?}", n.value)
Expand Down
8 changes: 4 additions & 4 deletions crates/swc_bundler/src/bundler/chunk/cjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Error;
use swc_common::{collections::AHashMap, Span, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{quote_ident, ExprFactory};
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith};

use crate::{
bundler::{chunk::merge::Ctx, load::TransformedModule},
Expand Down Expand Up @@ -192,7 +192,7 @@ where
L: Load,
R: Resolve,
{
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_call_expr(&mut self, node: &mut CallExpr) {
node.visit_mut_children_with(self);
Expand Down Expand Up @@ -350,7 +350,7 @@ struct DefaultHandler {
}

impl VisitMut for DefaultHandler {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_expr(&mut self, e: &mut Expr) {
e.visit_mut_children_with(self);
Expand All @@ -375,7 +375,7 @@ struct Remapper {
}

impl VisitMut for Remapper {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_ident(&mut self, i: &mut Ident) {
if let Some(v) = self.vars.get(&i.to_id()).copied() {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/bundler/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use swc_atoms::JsWord;
use swc_common::{collections::ARandomState, FileName, SyntaxContext};
use swc_ecma_ast::*;
use swc_ecma_utils::find_pat_ids;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith};

use super::{
load::{Source, Specifier},
Expand Down Expand Up @@ -115,7 +115,7 @@ where
L: Load,
R: Resolve,
{
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_module_item(&mut self, item: &mut ModuleItem) {
match item {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/bundler/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use swc_common::{
};
use swc_ecma_ast::*;
use swc_ecma_utils::find_pat_ids;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith};

use super::Bundler;
use crate::{load::Load, resolve::Resolve};
Expand Down Expand Up @@ -368,7 +368,7 @@ where
L: Load,
R: Resolve,
{
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_export_named_specifier(&mut self, s: &mut ExportNamedSpecifier) {
let orig = match &s.orig {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/bundler/keywords.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::{collections::AHashMap, util::take::Take};
use swc_ecma_ast::*;
use swc_ecma_utils::private_ident;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut, VisitMutWith};

use crate::id::Id;

Expand Down Expand Up @@ -31,7 +31,7 @@ impl KeywordRenamer {
}

impl VisitMut for KeywordRenamer {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_binding_ident(&mut self, n: &mut BindingIdent) {
if let Some(new) = self.renamed(&n.id) {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/bundler/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use swc_ecma_ast::{
};
use swc_ecma_transforms_base::resolver;
use swc_ecma_visit::{
noop_visit_mut_type, noop_visit_type, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith,
noop_visit_type, standard_only_visit_mut, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith,
};

use super::{export::Exports, helpers::Helpers, Bundler};
Expand Down Expand Up @@ -486,7 +486,7 @@ impl Visit for Es6ModuleDetector {
#[derive(Clone, Copy)]
struct ClearMark;
impl VisitMut for ClearMark {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_ident(&mut self, ident: &mut Ident) {
ident.span.ctxt = SyntaxContext::empty();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/inline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::{collections::AHashMap, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_visit::{
noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, Visit, VisitMut,
noop_visit_type, standard_only_visit_mut, visit_mut_obj_and_computed, Visit, VisitMut,
VisitMutWith, VisitWith,
};

Expand Down Expand Up @@ -84,7 +84,7 @@ impl Visit for Analyzer<'_> {
}

impl VisitMut for Inliner {
noop_visit_mut_type!();
standard_only_visit_mut!();

visit_mut_obj_and_computed!();

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::hash::Hash;
use swc_common::{Span, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::ident::IdentLike;
use swc_ecma_visit::{noop_visit_mut_type, VisitMut};
use swc_ecma_visit::{standard_only_visit_mut, VisitMut};

#[cfg(feature = "concurrent")]
pub(crate) type Readonly<T> = std::sync::Arc<T>;
Expand Down Expand Up @@ -147,7 +147,7 @@ where
pub(crate) struct HygieneRemover;

impl VisitMut for HygieneRemover {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_span(&mut self, s: &mut Span) {
*s = s.with_ctxt(SyntaxContext::empty())
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_bundler/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Load for Loader {
emit_metadata: Default::default(),
use_define_for_class_fields: false,
}))
.fold_with(&mut strip(top_level_mark))
.fold_with(&mut strip(unresolved_mark, top_level_mark))
.fold_with(&mut react::<SingleThreadedComments>(
self.cm.clone(),
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Mark, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_compat_es2015::arrow;
use swc_ecma_utils::prepend_stmt;
use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, InjectVars};
use swc_ecma_visit::{standard_only_fold, Fold, FoldWith, InjectVars};
use swc_trace_macro::swc_trace;

/// Safari 10.3 had an issue where async arrow function expressions within any
Expand All @@ -26,7 +26,7 @@ struct AsyncArrowsInClass {
/// TODO: VisitMut
#[swc_trace]
impl Fold for AsyncArrowsInClass {
noop_fold_type!();
standard_only_fold!();

fn fold_class_method(&mut self, n: ClassMethod) -> ClassMethod {
self.in_class_method = true;
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use swc_ecma_ast::*;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith};
use swc_trace_macro::swc_trace;

/// Converts destructured parameters with default values to non-shorthand
Expand All @@ -16,7 +16,7 @@ struct EdgeDefaultParam {

#[swc_trace]
impl VisitMut for EdgeDefaultParam {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) {
self.in_arrow = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use swc_atoms::JsWord;
use swc_common::{collections::AHashSet, Span};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::hygiene::rename;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith};
use swc_trace_macro::swc_trace;

pub fn safari_id_destructuring_collision_in_function_expression() -> impl Fold + VisitMut {
Expand All @@ -31,7 +31,7 @@ impl SafariIdDestructuringCollisionInFunctionExpression {

#[swc_trace]
impl VisitMut for SafariIdDestructuringCollisionInFunctionExpression {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_assign_pat_prop(&mut self, n: &mut AssignPatProp) {
self.visit_mut_pat_id(&n.key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::DUMMY_SP;
use swc_ecma_ast::*;
use swc_ecma_utils::{prepend_stmt, private_ident, ExprFactory};
use swc_ecma_visit::{noop_fold_type, Fold, FoldWith};
use swc_ecma_visit::{standard_only_fold, Fold, FoldWith};
use swc_trace_macro::swc_trace;

// Converts destructured parameters with default values to non-shorthand syntax.
Expand Down Expand Up @@ -55,7 +55,7 @@ impl TemplateLiteralCaching {
/// TODO: VisitMut
#[swc_trace]
impl Fold for TemplateLiteralCaching {
noop_fold_type!();
standard_only_fold!();

fn fold_expr(&mut self, n: Expr) -> Expr {
let n = n.fold_children_with(self);
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_compat_common/src/regexp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::util::take::Take;
use swc_ecma_ast::{CallExpr, Expr, Lit, Regex};
use swc_ecma_utils::{quote_ident, ExprFactory};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith};

pub fn regexp(config: Config) -> impl Fold + VisitMut {
as_folder(RegExp { config })
Expand Down Expand Up @@ -32,7 +32,7 @@ struct RegExp {
}

impl VisitMut for RegExp {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_expr(&mut self, expr: &mut Expr) {
expr.visit_mut_children_with(self);
Expand Down
6 changes: 4 additions & 2 deletions crates/swc_ecma_compat_es2015/src/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use swc_ecma_utils::{
function::{init_this, FnEnvHoister},
prepend_stmt,
};
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith};
use swc_ecma_visit::{
as_folder, standard_only_visit_mut, Fold, InjectVars, VisitMut, VisitMutWith,
};
use swc_trace_macro::swc_trace;

/// Compile ES2015 arrow functions to ES5
Expand Down Expand Up @@ -72,7 +74,7 @@ struct Arrow {

#[swc_trace]
impl VisitMut for Arrow {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_class(&mut self, c: &mut Class) {
if c.super_class.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::{util::take::Take, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::IdentUsageFinder;
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
use swc_ecma_visit::{as_folder, standard_only_visit_mut, Fold, VisitMut, VisitMutWith};
use swc_trace_macro::swc_trace;

pub fn block_scoped_functions() -> impl Fold + VisitMut {
Expand All @@ -13,7 +13,7 @@ struct BlockScopedFns;

#[swc_trace]
impl VisitMut for BlockScopedFns {
noop_visit_mut_type!();
standard_only_visit_mut!();

fn visit_mut_function(&mut self, n: &mut Function) {
let Some(body) = &mut n.body else { return };
Expand Down
Loading
Loading