mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(es/minifier): Fix ordering issue of analyzer (#6150)
**Description:** This is the groundwork for a parallel analyzer. This PR fixes the ordering issue of the analyzer so that the analyzer works identically regardless of the visit order. This patch contains some improvements because previously, we mixed `.and_modify()` and `.or_default()`.
This commit is contained in:
parent
4e079b221d
commit
6d0ca05cb5
@ -1,9 +1,8 @@
|
|||||||
//// [classDeclarationLoop.ts]
|
//// [classDeclarationLoop.ts]
|
||||||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
|
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
|
||||||
for(var _loop = function(i) {
|
for(var _loop = function(i) {
|
||||||
var C = function C() {
|
arr.push(function C() {
|
||||||
"use strict";
|
"use strict";
|
||||||
_class_call_check(this, C), this.prop = i;
|
_class_call_check(this, C), this.prop = i;
|
||||||
};
|
});
|
||||||
arr.push(C);
|
|
||||||
}, arr = [], i = 0; i < 10; ++i)_loop(i);
|
}, arr = [], i = 0; i < 10; ++i)_loop(i);
|
||||||
|
@ -68,7 +68,7 @@ where
|
|||||||
v.data
|
v.data
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct VarUsageInfo {
|
pub(crate) struct VarUsageInfo {
|
||||||
pub inline_prevented: bool,
|
pub inline_prevented: bool,
|
||||||
|
|
||||||
@ -143,6 +143,46 @@ pub(crate) struct VarUsageInfo {
|
|||||||
pub used_recursively: bool,
|
pub used_recursively: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for VarUsageInfo {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
inline_prevented: Default::default(),
|
||||||
|
ref_count: Default::default(),
|
||||||
|
cond_init: Default::default(),
|
||||||
|
declared: Default::default(),
|
||||||
|
declared_count: Default::default(),
|
||||||
|
declared_as_fn_param: Default::default(),
|
||||||
|
declared_as_fn_decl: Default::default(),
|
||||||
|
declared_as_fn_expr: Default::default(),
|
||||||
|
assign_count: Default::default(),
|
||||||
|
mutation_by_call_count: Default::default(),
|
||||||
|
usage_count: Default::default(),
|
||||||
|
reassigned_with_assignment: Default::default(),
|
||||||
|
reassigned_with_var_decl: Default::default(),
|
||||||
|
mutated: Default::default(),
|
||||||
|
has_property_access: Default::default(),
|
||||||
|
has_property_mutation: Default::default(),
|
||||||
|
exported: Default::default(),
|
||||||
|
used_above_decl: Default::default(),
|
||||||
|
is_fn_local: true,
|
||||||
|
executed_multiple_time: Default::default(),
|
||||||
|
used_in_cond: Default::default(),
|
||||||
|
var_kind: Default::default(),
|
||||||
|
var_initialized: Default::default(),
|
||||||
|
declared_as_catch_param: Default::default(),
|
||||||
|
no_side_effect_for_member_access: Default::default(),
|
||||||
|
used_as_callee: Default::default(),
|
||||||
|
used_as_arg: Default::default(),
|
||||||
|
indexed_with_dynamic_key: Default::default(),
|
||||||
|
pure_fn: Default::default(),
|
||||||
|
infects: Default::default(),
|
||||||
|
used_in_non_child_fn: Default::default(),
|
||||||
|
accessed_props: Default::default(),
|
||||||
|
used_recursively: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl VarUsageInfo {
|
impl VarUsageInfo {
|
||||||
pub fn is_mutated_only_by_one_call(&self) -> bool {
|
pub fn is_mutated_only_by_one_call(&self) -> bool {
|
||||||
self.assign_count == 0 && self.mutation_by_call_count == 1
|
self.assign_count == 0 && self.mutation_by_call_count == 1
|
||||||
|
@ -153,10 +153,8 @@ impl Storage for ProgramData {
|
|||||||
// debug!(has_init = has_init, "declare_decl(`{}`)", i);
|
// debug!(has_init = has_init, "declare_decl(`{}`)", i);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let v = self
|
let v = self.vars.entry(i.to_id()).or_default();
|
||||||
.vars
|
|
||||||
.entry(i.to_id())
|
|
||||||
.and_modify(|v| {
|
|
||||||
if has_init && (v.declared || v.var_initialized) {
|
if has_init && (v.declared || v.var_initialized) {
|
||||||
trace_op!("declare_decl(`{}`): Already declared", i);
|
trace_op!("declare_decl(`{}`): Already declared", i);
|
||||||
|
|
||||||
@ -165,20 +163,17 @@ impl Storage for ProgramData {
|
|||||||
v.assign_count += 1;
|
v.assign_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is not delcared yet, so this is the first declaration.
|
||||||
|
if !v.declared {
|
||||||
|
v.var_kind = kind;
|
||||||
|
v.no_side_effect_for_member_access = ctx.in_decl_with_no_side_effect_for_member_access;
|
||||||
|
}
|
||||||
|
|
||||||
if v.used_in_non_child_fn {
|
if v.used_in_non_child_fn {
|
||||||
v.is_fn_local = false;
|
v.is_fn_local = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
v.var_initialized |= has_init;
|
v.var_initialized |= has_init;
|
||||||
})
|
|
||||||
.or_insert_with(|| VarUsageInfo {
|
|
||||||
is_fn_local: true,
|
|
||||||
var_kind: kind,
|
|
||||||
var_initialized: has_init,
|
|
||||||
no_side_effect_for_member_access: ctx.in_decl_with_no_side_effect_for_member_access,
|
|
||||||
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
v.declared_count += 1;
|
v.declared_count += 1;
|
||||||
v.declared = true;
|
v.declared = true;
|
||||||
|
@ -14843,8 +14843,7 @@
|
|||||||
0 === V && (V = 5);
|
0 === V && (V = 5);
|
||||||
}
|
}
|
||||||
function Uj(a) {
|
function Uj(a) {
|
||||||
var b = eg();
|
return gg(99, dk.bind(null, a, eg())), null;
|
||||||
return gg(99, dk.bind(null, a, b)), null;
|
|
||||||
}
|
}
|
||||||
function dk(a, b) {
|
function dk(a, b) {
|
||||||
do Oj();
|
do Oj();
|
||||||
|
@ -26501,8 +26501,7 @@
|
|||||||
return t > (e = e.childExpirationTime) ? t : e;
|
return t > (e = e.childExpirationTime) ? t : e;
|
||||||
}
|
}
|
||||||
function ie(e) {
|
function ie(e) {
|
||||||
var t = to();
|
return tu(99, it.bind(null, e, to())), null;
|
||||||
return tu(99, it.bind(null, e, t)), null;
|
|
||||||
}
|
}
|
||||||
function it(e, t) {
|
function it(e, t) {
|
||||||
if (ir(), (48 & nx) != 0) throw Error(d(327));
|
if (ir(), (48 & nx) != 0) throw Error(d(327));
|
||||||
|
@ -8072,8 +8072,7 @@
|
|||||||
0 === workInProgressRootExitStatus && (workInProgressRootExitStatus = 5);
|
0 === workInProgressRootExitStatus && (workInProgressRootExitStatus = 5);
|
||||||
}
|
}
|
||||||
function commitRoot(root) {
|
function commitRoot(root) {
|
||||||
var renderPriorityLevel = getCurrentPriorityLevel();
|
return runWithPriority$1(99, commitRootImpl.bind(null, root, getCurrentPriorityLevel())), null;
|
||||||
return runWithPriority$1(99, commitRootImpl.bind(null, root, renderPriorityLevel)), null;
|
|
||||||
}
|
}
|
||||||
function commitRootImpl(root, renderPriorityLevel) {
|
function commitRootImpl(root, renderPriorityLevel) {
|
||||||
do flushPassiveEffects();
|
do flushPassiveEffects();
|
||||||
|
Loading…
Reference in New Issue
Block a user