mirror of
https://github.com/swc-project/swc.git
synced 2024-12-28 08:04:43 +03:00
refactor(es/transforms): Remove concurrent
(#4808)
This commit is contained in:
parent
8f48d0fdaf
commit
a487fc1d28
@ -18,7 +18,6 @@ bench = false
|
||||
|
||||
[features]
|
||||
compat = ["swc_ecma_transforms_compat"]
|
||||
concurrent = []
|
||||
module = ["swc_ecma_transforms_module"]
|
||||
multi-module-decorator = ["swc_ecma_transforms_proposal/multi-module"]
|
||||
optimization = ["swc_ecma_transforms_optimization"]
|
||||
@ -28,7 +27,7 @@ typescript = ["swc_ecma_transforms_typescript"]
|
||||
|
||||
[dependencies]
|
||||
swc_atoms = {version = "0.2.0", path = "../swc_atoms"}
|
||||
swc_common = { version = "0.18.0", path = "../swc_common"}
|
||||
swc_common = {version = "0.18.0", path = "../swc_common"}
|
||||
swc_ecma_ast = {version = "0.78.0", path = "../swc_ecma_ast"}
|
||||
swc_ecma_transforms_base = {version = "0.85.0", path = "../swc_ecma_transforms_base"}
|
||||
swc_ecma_transforms_compat = {version = "0.100.0", path = "../swc_ecma_transforms_compat", optional = true}
|
||||
|
@ -1,32 +0,0 @@
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_visit::{Fold, VisitMut};
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct ExampleVisitMut;
|
||||
|
||||
impl Parallel for ExampleVisitMut {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for ExampleVisitMut {}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct ExampleFold;
|
||||
|
||||
impl Parallel for ExampleFold {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl Fold for ExampleFold {}
|
@ -12,13 +12,6 @@ version = "0.100.0"
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[features]
|
||||
concurrent = [
|
||||
"rayon",
|
||||
"swc_ecma_transforms_base/concurrent",
|
||||
"swc_ecma_utils/concurrent",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.7.4"
|
||||
arrayvec = "0.7.2"
|
||||
|
@ -1,8 +1,6 @@
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::{collections::AHashSet, Spanned};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::quote_str;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -13,16 +11,7 @@ pub fn duplicate_keys() -> impl Fold + VisitMut {
|
||||
|
||||
struct DuplicateKeys;
|
||||
|
||||
impl Parallel for DuplicateKeys {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for DuplicateKeys {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_common::util::take::Take;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::{private_ident, IdentUsageFinder};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -31,14 +29,6 @@ pub fn function_name() -> impl 'static + Copy + Fold + VisitMut {
|
||||
#[derive(Clone, Copy)]
|
||||
struct FnName;
|
||||
|
||||
impl Parallel for FnName {
|
||||
fn create(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
struct Rename {
|
||||
name: Option<Ident>,
|
||||
}
|
||||
@ -53,7 +43,6 @@ fn prepare(i: Ident) -> Ident {
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for FnName {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use swc_common::{util::take::Take, Span, Spanned};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::{helper, perf::Parallel};
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_transforms_base::helper;
|
||||
use swc_ecma_utils::ExprFactory;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -37,16 +36,7 @@ pub fn instance_of() -> impl Fold + VisitMut {
|
||||
}
|
||||
struct InstanceOf;
|
||||
|
||||
impl Parallel for InstanceOf {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
InstanceOf
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for InstanceOf {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_common::util::take::Take;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::quote_ident;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -48,16 +46,7 @@ pub fn shorthand() -> impl 'static + Fold + VisitMut {
|
||||
#[derive(Clone, Copy)]
|
||||
struct Shorthand;
|
||||
|
||||
impl Parallel for Shorthand {
|
||||
fn create(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for Shorthand {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::DUMMY_SP;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::{quote_ident, ExprFactory};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -28,16 +26,7 @@ pub fn sticky_regex() -> impl 'static + Fold + VisitMut {
|
||||
|
||||
struct StickyRegex;
|
||||
|
||||
impl Parallel for StickyRegex {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
StickyRegex
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for StickyRegex {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -4,8 +4,7 @@ use serde::Deserialize;
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{util::take::Take, BytePos, Spanned, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::{helper, perf::Parallel};
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_transforms_base::helper;
|
||||
use swc_ecma_utils::{
|
||||
is_literal, prepend_stmts, private_ident, quote_ident, undefined, ExprFactory, StmtLike,
|
||||
};
|
||||
@ -35,18 +34,7 @@ pub struct Config {
|
||||
pub mutable_template: bool,
|
||||
}
|
||||
|
||||
impl Parallel for TemplateLiteral {
|
||||
fn create(&self) -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn merge(&mut self, other: Self) {
|
||||
self.added.extend(other.added);
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for TemplateLiteral {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use swc_atoms::js_word;
|
||||
use swc_common::{util::take::Take, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::{helper, perf::Parallel};
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_transforms_base::helper;
|
||||
use swc_ecma_utils::{quote_str, ExprFactory};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -16,16 +15,6 @@ pub fn typeof_symbol() -> impl VisitMut + Fold {
|
||||
struct TypeOfSymbol;
|
||||
|
||||
#[swc_trace]
|
||||
impl Parallel for TypeOfSymbol {
|
||||
fn merge(&mut self, _: Self) {}
|
||||
|
||||
fn create(&self) -> Self {
|
||||
TypeOfSymbol
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for TypeOfSymbol {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -3,11 +3,8 @@ use std::{iter, mem};
|
||||
use serde::Deserialize;
|
||||
use swc_common::{chain, util::take::Take, Mark, Spanned, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::{
|
||||
helper, helper_expr,
|
||||
perf::{Check, Parallel},
|
||||
};
|
||||
use swc_ecma_transforms_macros::{fast_path, parallel};
|
||||
use swc_ecma_transforms_base::{helper, helper_expr, perf::Check};
|
||||
use swc_ecma_transforms_macros::fast_path;
|
||||
use swc_ecma_utils::{
|
||||
alias_ident_for, alias_if_required, is_literal, private_ident, quote_ident, var::VarCollector,
|
||||
ExprFactory, StmtLike,
|
||||
@ -1061,16 +1058,7 @@ struct ObjectSpread {
|
||||
c: Config,
|
||||
}
|
||||
|
||||
impl Parallel for ObjectSpread {
|
||||
fn create(&self) -> Self {
|
||||
ObjectSpread { c: self.c }
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for ObjectSpread {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_common::{util::take::Take, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::{alias_ident_for, prepend_stmt};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
use swc_trace_macro::swc_trace;
|
||||
@ -46,18 +44,6 @@ impl Operators {
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
impl Parallel for Operators {
|
||||
fn create(&self) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn merge(&mut self, other: Self) {
|
||||
self.vars.extend(other.vars);
|
||||
}
|
||||
}
|
||||
|
||||
#[swc_trace]
|
||||
#[parallel]
|
||||
impl VisitMut for Operators {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_atoms::{js_word, JsWord};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_visit::{
|
||||
as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith,
|
||||
};
|
||||
@ -13,15 +11,6 @@ pub fn reserved_words() -> impl 'static + Fold + VisitMut {
|
||||
#[derive(Clone, Copy)]
|
||||
struct EsReservedWord;
|
||||
|
||||
impl Parallel for EsReservedWord {
|
||||
fn create(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for EsReservedWord {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -29,10 +29,9 @@ pub fn expand(attr: TokenStream, mut item: ItemImpl) -> ItemImpl {
|
||||
mode,
|
||||
"module_items",
|
||||
explode,
|
||||
64,
|
||||
)));
|
||||
item.items.push(ImplItem::Method(make_par_visit_method(
|
||||
mode, "stmts", explode, 64,
|
||||
mode, "stmts", explode,
|
||||
)));
|
||||
|
||||
item
|
||||
@ -85,12 +84,11 @@ fn explode_hook_method_name(explode: bool, suffix: &str) -> Option<Ident> {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_par_visit_method(
|
||||
mode: Mode,
|
||||
suffix: &str,
|
||||
explode: bool,
|
||||
threshold: usize,
|
||||
) -> ImplItemMethod {
|
||||
fn make_par_visit_method(mode: Mode, suffix: &str, explode: bool) -> ImplItemMethod {
|
||||
if !explode {
|
||||
panic!("#[parallel] is deparecated and currently explode is only supported")
|
||||
}
|
||||
|
||||
let method_name = Ident::new(&format!("{}_{}", mode.prefix(), suffix), Span::call_site());
|
||||
let hook = post_visit_hook(mode, suffix);
|
||||
let explode_method_name = explode_hook_method_name(explode, suffix);
|
||||
@ -99,7 +97,6 @@ fn make_par_visit_method(
|
||||
(Mode::Fold, Some(explode_method_name)) => q!(
|
||||
Vars {
|
||||
NodeType: node_type(suffix),
|
||||
threshold,
|
||||
method_name,
|
||||
hook,
|
||||
explode_method_name,
|
||||
@ -110,62 +107,6 @@ fn make_par_visit_method(
|
||||
use swc_ecma_transforms_base::perf::{ParExplode, Parallel};
|
||||
use swc_ecma_visit::FoldWith;
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
if nodes.len() >= threshold {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let (visitor, mut nodes) = ::swc_common::GLOBALS.with(|globals| {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.with(|helpers| {
|
||||
HANDLER.with(|handler| {
|
||||
nodes
|
||||
.into_par_iter()
|
||||
.map(|node| {
|
||||
::swc_common::GLOBALS.set(&globals, || {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.set(
|
||||
helpers,
|
||||
|| {
|
||||
HANDLER.set(handler, || {
|
||||
let mut visitor =
|
||||
Parallel::create(&*self);
|
||||
let node = node.fold_with(&mut visitor);
|
||||
let mut nodes = Vec::with_capacity(4);
|
||||
|
||||
ParExplode::explode_method_name(
|
||||
&mut visitor,
|
||||
&mut nodes,
|
||||
);
|
||||
|
||||
nodes.push(node);
|
||||
|
||||
(visitor, nodes)
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.reduce(
|
||||
|| (Parallel::create(&*self), vec![]),
|
||||
|mut a, b| {
|
||||
Parallel::merge(&mut a.0, b.0);
|
||||
|
||||
a.1.extend(b.1);
|
||||
|
||||
a
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
Parallel::merge(self, visitor);
|
||||
|
||||
{
|
||||
hook;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
let mut buf = Vec::with_capacity(nodes.len());
|
||||
|
||||
for node in nodes {
|
||||
@ -189,7 +130,6 @@ fn make_par_visit_method(
|
||||
(Mode::Fold, None) => q!(
|
||||
Vars {
|
||||
NodeType: node_type(suffix),
|
||||
threshold,
|
||||
method_name,
|
||||
hook,
|
||||
},
|
||||
@ -199,64 +139,6 @@ fn make_par_visit_method(
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_visit::FoldWith;
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
if nodes.len() >= threshold {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let (visitor, mut nodes) = ::swc_common::GLOBALS.with(|globals| {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.with(|helpers| {
|
||||
HANDLER.with(|handler| {
|
||||
nodes
|
||||
.into_par_iter()
|
||||
.map(|node| {
|
||||
::swc_common::GLOBALS.set(&globals, || {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.set(
|
||||
helpers,
|
||||
|| {
|
||||
HANDLER.set(handler, || {
|
||||
let mut visitor =
|
||||
Parallel::create(&*self);
|
||||
let node = node.fold_with(&mut visitor);
|
||||
|
||||
(visitor, node)
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.fold(
|
||||
|| (Parallel::create(&*self), vec![]),
|
||||
|mut a, b| {
|
||||
Parallel::merge(&mut a.0, b.0);
|
||||
|
||||
a.1.push(b.1);
|
||||
|
||||
a
|
||||
},
|
||||
)
|
||||
.reduce(
|
||||
|| (Parallel::create(&*self), vec![]),
|
||||
|mut a, b| {
|
||||
Parallel::merge(&mut a.0, b.0);
|
||||
|
||||
a.1.extend(b.1);
|
||||
|
||||
a
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
Parallel::merge(self, visitor);
|
||||
|
||||
{
|
||||
hook;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
let mut nodes = nodes.fold_children_with(self);
|
||||
{
|
||||
hook;
|
||||
@ -271,7 +153,6 @@ fn make_par_visit_method(
|
||||
(Mode::VisitMut, Some(explode_method_name)) => q!(
|
||||
Vars {
|
||||
NodeType: node_type(suffix),
|
||||
threshold,
|
||||
method_name,
|
||||
hook,
|
||||
explode_method_name
|
||||
@ -284,65 +165,6 @@ fn make_par_visit_method(
|
||||
use swc_ecma_transforms_base::perf::{ParExplode, Parallel};
|
||||
use swc_ecma_visit::VisitMutWith;
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
if nodes.len() >= threshold {
|
||||
::swc_common::GLOBALS.with(|globals| {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.with(|helpers| {
|
||||
HANDLER.with(|handler| {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let (visitor, new_nodes) = take(nodes)
|
||||
.into_par_iter()
|
||||
.map(|mut node| {
|
||||
::swc_common::GLOBALS.set(&globals, || {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.set(
|
||||
helpers,
|
||||
|| {
|
||||
HANDLER.set(handler, || {
|
||||
let mut visitor =
|
||||
Parallel::create(&*self);
|
||||
node.visit_mut_with(&mut visitor);
|
||||
|
||||
let mut nodes = Vec::with_capacity(4);
|
||||
|
||||
ParExplode::explode_method_name(
|
||||
&mut visitor,
|
||||
&mut nodes,
|
||||
);
|
||||
|
||||
nodes.push(node);
|
||||
|
||||
(visitor, nodes)
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.reduce(
|
||||
|| (Parallel::create(&*self), vec![]),
|
||||
|mut a, b| {
|
||||
Parallel::merge(&mut a.0, b.0);
|
||||
|
||||
a.1.extend(b.1);
|
||||
|
||||
a
|
||||
},
|
||||
);
|
||||
|
||||
Parallel::merge(self, visitor);
|
||||
|
||||
{
|
||||
hook;
|
||||
}
|
||||
|
||||
*nodes = new_nodes;
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let mut buf = Vec::with_capacity(nodes.len());
|
||||
|
||||
for mut node in take(nodes) {
|
||||
@ -365,7 +187,6 @@ fn make_par_visit_method(
|
||||
(Mode::VisitMut, None) => q!(
|
||||
Vars {
|
||||
NodeType: node_type(suffix),
|
||||
threshold,
|
||||
method_name,
|
||||
hook,
|
||||
},
|
||||
@ -375,52 +196,6 @@ fn make_par_visit_method(
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_visit::VisitMutWith;
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
if nodes.len() >= threshold {
|
||||
::swc_common::GLOBALS.with(|globals| {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.with(|helpers| {
|
||||
HANDLER.with(|handler| {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let visitor = nodes
|
||||
.into_par_iter()
|
||||
.map(|node| {
|
||||
::swc_common::GLOBALS.set(&globals, || {
|
||||
swc_ecma_transforms_base::helpers::HELPERS.set(
|
||||
helpers,
|
||||
|| {
|
||||
HANDLER.set(handler, || {
|
||||
let mut visitor =
|
||||
Parallel::create(&*self);
|
||||
node.visit_mut_with(&mut visitor);
|
||||
|
||||
visitor
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.reduce(
|
||||
|| Parallel::create(&*self),
|
||||
|mut a, b| {
|
||||
Parallel::merge(&mut a, b);
|
||||
|
||||
a
|
||||
},
|
||||
);
|
||||
|
||||
Parallel::merge(self, visitor);
|
||||
|
||||
{
|
||||
hook;
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
nodes.visit_mut_children_with(self);
|
||||
{
|
||||
hook;
|
||||
|
@ -5,8 +5,6 @@ use swc_common::{
|
||||
EqIgnoreSpan,
|
||||
};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::collect_decls;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
|
||||
@ -56,15 +54,6 @@ struct InlineGlobals {
|
||||
bindings: Lrc<AHashSet<Id>>,
|
||||
}
|
||||
|
||||
impl Parallel for InlineGlobals {
|
||||
fn create(&self) -> Self {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for InlineGlobals {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -3,8 +3,6 @@ use std::usize;
|
||||
use serde_json::Value;
|
||||
use swc_common::{util::take::Take, Spanned, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::{calc_literal_cost, member_expr, ExprFactory};
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
|
||||
@ -38,23 +36,12 @@ struct JsonParse {
|
||||
pub min_cost: usize,
|
||||
}
|
||||
|
||||
impl Parallel for JsonParse {
|
||||
fn create(&self) -> Self {
|
||||
JsonParse {
|
||||
min_cost: self.min_cost,
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
impl Default for JsonParse {
|
||||
fn default() -> Self {
|
||||
JsonParse { min_cost: 1024 }
|
||||
}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for JsonParse {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_common::DUMMY_SP;
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::quote_ident;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut};
|
||||
|
||||
@ -20,15 +18,6 @@ struct JsxSelf {
|
||||
dev: bool,
|
||||
}
|
||||
|
||||
impl Parallel for JsxSelf {
|
||||
fn create(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for JsxSelf {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use swc_common::{sync::Lrc, SourceMap, DUMMY_SP};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_transforms_base::perf::Parallel;
|
||||
use swc_ecma_transforms_macros::parallel;
|
||||
use swc_ecma_utils::quote_ident;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut};
|
||||
|
||||
@ -19,15 +17,6 @@ struct JsxSrc {
|
||||
dev: bool,
|
||||
}
|
||||
|
||||
impl Parallel for JsxSrc {
|
||||
fn create(&self) -> Self {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
fn merge(&mut self, _: Self) {}
|
||||
}
|
||||
|
||||
#[parallel]
|
||||
impl VisitMut for JsxSrc {
|
||||
noop_visit_mut_type!();
|
||||
|
||||
|
@ -2360,34 +2360,6 @@ where
|
||||
self.add(&node.local);
|
||||
}
|
||||
|
||||
fn visit_module_items(&mut self, nodes: &[ModuleItem]) {
|
||||
#[cfg(feature = "concurrent")]
|
||||
if nodes.len() > 16 {
|
||||
use rayon::prelude::*;
|
||||
let set = nodes
|
||||
.par_iter()
|
||||
.map(|node| {
|
||||
let mut v = BindingCollector {
|
||||
only: self.only,
|
||||
bindings: Default::default(),
|
||||
is_pat_decl: self.is_pat_decl,
|
||||
};
|
||||
node.visit_with(&mut v);
|
||||
v.bindings
|
||||
})
|
||||
.reduce(AHashSet::default, |mut a, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
self.bindings.extend(set);
|
||||
return;
|
||||
}
|
||||
|
||||
for node in nodes {
|
||||
node.visit_children_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_param(&mut self, node: &Param) {
|
||||
let old = self.is_pat_decl;
|
||||
self.is_pat_decl = true;
|
||||
@ -2405,34 +2377,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_stmts(&mut self, nodes: &[Stmt]) {
|
||||
#[cfg(feature = "concurrent")]
|
||||
if nodes.len() > 16 {
|
||||
use rayon::prelude::*;
|
||||
let set = nodes
|
||||
.par_iter()
|
||||
.map(|node| {
|
||||
let mut v = BindingCollector {
|
||||
only: self.only,
|
||||
bindings: Default::default(),
|
||||
is_pat_decl: self.is_pat_decl,
|
||||
};
|
||||
node.visit_with(&mut v);
|
||||
v.bindings
|
||||
})
|
||||
.reduce(AHashSet::default, |mut a, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
self.bindings.extend(set);
|
||||
return;
|
||||
}
|
||||
|
||||
for node in nodes {
|
||||
node.visit_children_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_var_declarator(&mut self, node: &VarDeclarator) {
|
||||
let old = self.is_pat_decl;
|
||||
self.is_pat_decl = true;
|
||||
|
Loading…
Reference in New Issue
Block a user