Skip to content

Commit

Permalink
fix(es/minifier): Fix infection analysis of sequential inliner (#6053)
Browse files Browse the repository at this point in the history
**Description:**

This PR fixes the callee issue by fixing the infection analyzer.

**Related issue:**

 - Closes #6047
  • Loading branch information
kdy1 committed Oct 6, 2022
1 parent 62dd127 commit d65fba1
Show file tree
Hide file tree
Showing 40 changed files with 571 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ console.log(A, void 0);
export { };
//// [/f.ts]
import { C } from "./a";
C.One, console.log(C.Two, C.Two);
C.One;
var c = C.Two, d = C.Two;
console.log(c, d);
//// [/g.ts]
console.log(void 0, void 0);
export { };
Expand Down
7 changes: 5 additions & 2 deletions crates/swc_ecma_minifier/src/alias/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ mod ctx;
pub(crate) struct AliasConfig {
pub marks: Option<Marks>,
pub ignore_nested: bool,
/// TODO(kdy1): This field is used for sequential inliner.
/// It should be renamed to some correct name.
pub need_all: bool,

This comment has been minimized.

Copy link
@konradekk

konradekk Oct 6, 2022

just some guesses: keep_separate, keep_together, collect_all (usages), track_all (usages)?

}

pub(crate) trait InfectableNode {
Expand Down Expand Up @@ -200,15 +203,15 @@ impl Visit for InfectionCollector<'_> {
fn visit_member_expr(&mut self, n: &MemberExpr) {
{
let ctx = Ctx {
track_expr_ident: false,
track_expr_ident: self.config.need_all,
..self.ctx
};
n.obj.visit_with(&mut *self.with_ctx(ctx));
}

{
let ctx = Ctx {
track_expr_ident: false,
track_expr_ident: self.config.need_all,
..self.ctx
};
n.prop.visit_with(&mut *self.with_ctx(ctx));
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ where
AliasConfig {
marks: Some(self.marks),
ignore_nested: false,
need_all: true,
},
) {
if let Some(usage) = self.data.vars.get_mut(&i) {
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ where
AliasConfig {
marks: Some(self.marks),
ignore_nested: true,
need_all: true,
},
)
}),
Expand All @@ -1011,6 +1012,7 @@ where
AliasConfig {
marks: Some(self.marks),
ignore_nested: true,
need_all: true,
},
))
} else {
Expand Down
14 changes: 7 additions & 7 deletions crates/swc_ecma_minifier/tests/benches-full/d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
for(; tz[m - 1] > x1;)tz.pop(), --m;
var bin, bins = Array(m + 1);
for(i = 0; i <= m; ++i)(bin = bins[i] = []).x0 = i > 0 ? tz[i - 1] : x0, bin.x1 = i < m ? tz[i] : x1;
for(i = 0; i < n; ++i)x0 <= (x = values[i]) && x <= x1 && bins[bisectRight(tz, x, 0, m)].push(data[i]);
for(i = 0; i < n; ++i)x = values[i], x0 <= x && x <= x1 && bins[bisectRight(tz, x, 0, m)].push(data[i]);
return bins;
}
return histogram.value = function(_) {
Expand Down Expand Up @@ -4577,11 +4577,11 @@
phi * radians$1
]);
if (p0) {
var normal = cartesianCross(p0, p), inflection = cartesianCross([
var normal = cartesianCross(p0, p), equatorial = [
normal[1],
-normal[0],
0
], normal);
], inflection = cartesianCross(equatorial, normal);
cartesianNormalizeInPlace(inflection);
var phii, delta = lambda - lambda2, sign = delta > 0 ? 1 : -1, lambdai = (inflection = spherical(inflection))[0] * degrees$2 * sign, antimeridian = abs$2(delta) > 180;
antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda) ? (phii = inflection[1] * degrees$2) > phi1 && (phi1 = phii) : antimeridian ^ (sign * lambda2 < (lambdai = (lambdai + 360) % 360 - 180) && lambdai < sign * lambda) ? (phii = -inflection[1] * degrees$2) < phi0 && (phi0 = phii) : (phi < phi0 && (phi0 = phi), phi > phi1 && (phi1 = phi)), antimeridian ? lambda < lambda2 ? angle(lambda0$1, lambda) > angle(lambda0$1, lambda1) && (lambda1 = lambda) : angle(lambda, lambda1) > angle(lambda0$1, lambda1) && (lambda0$1 = lambda) : lambda1 >= lambda0$1 ? (lambda < lambda0$1 && (lambda0$1 = lambda), lambda > lambda1 && (lambda1 = lambda)) : lambda > lambda2 ? angle(lambda0$1, lambda) > angle(lambda0$1, lambda1) && (lambda1 = lambda) : angle(lambda, lambda1) > angle(lambda0$1, lambda1) && (lambda0$1 = lambda);
Expand Down Expand Up @@ -6685,7 +6685,7 @@
var transform, untransform, unknown, piecewise, output, input, domain = unit, range = unit, interpolate$1 = interpolate, clamp = identity$6;
function rescale() {
var a, b, t, n = Math.min(domain.length, range.length);
return clamp !== identity$6 && ((a = domain[0]) > (b = domain[n - 1]) && (t = a, a = b, b = t), clamp = function(x) {
return clamp !== identity$6 && (a = domain[0], b = domain[n - 1], a > b && (t = a, a = b, b = t), clamp = function(x) {
return Math.max(a, Math.min(b, x));
}), piecewise = n > 2 ? polymap : bimap, output = input = null, scale;
}
Expand Down Expand Up @@ -9582,7 +9582,7 @@
},
find: function(x, y, radius) {
var dx, dy, d2, node, closest, i = 0, n = nodes.length;
for(null == radius ? radius = 1 / 0 : radius *= radius, i = 0; i < n; ++i)(d2 = (dx = x - (node = nodes[i]).x) * dx + (dy = y - node.y) * dy) < radius && (closest = node, radius = d2);
for(null == radius ? radius = 1 / 0 : radius *= radius, i = 0; i < n; ++i)node = nodes[i], (d2 = (dx = x - node.x) * dx + (dy = y - node.y) * dy) < radius && (closest = node, radius = d2);
return closest;
},
on: function(name, _) {
Expand Down Expand Up @@ -9757,7 +9757,7 @@
if (phi1 = lambda1 = -(lambda0$1 = phi0 = 1 / 0), ranges = [], geoStream(feature, boundsStream), n = ranges.length) {
for(ranges.sort(rangeCompare), i = 1, merged = [
a = ranges[0]
]; i < n; ++i)rangeContains(a, (b = ranges[i])[0]) || rangeContains(a, b[1]) ? (angle(a[0], b[1]) > angle(a[0], a[1]) && (a[1] = b[1]), angle(b[0], a[1]) > angle(a[0], a[1]) && (a[0] = b[0])) : merged.push(a = b);
]; i < n; ++i)b = ranges[i], rangeContains(a, b[0]) || rangeContains(a, b[1]) ? (angle(a[0], b[1]) > angle(a[0], a[1]) && (a[1] = b[1]), angle(b[0], a[1]) > angle(a[0], a[1]) && (a[0] = b[0])) : merged.push(a = b);
for(deltaMax = -1 / 0, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i)b = merged[i], (delta = angle(a[1], b[0])) > deltaMax && (deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1]);
}
return ranges = range$1 = null, lambda0$1 === 1 / 0 || phi0 === 1 / 0 ? [
Expand Down Expand Up @@ -10165,7 +10165,7 @@
return sortValues(arcs[i], arcs[j]);
}) : null != sort && index.sort(function(i, j) {
return sort(data[i], data[j]);
}), i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1)a1 = a0 + ((v = arcs[j = index[i]]) > 0 ? v * k : 0) + pa, arcs[j] = {
}), i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1)v = arcs[j = index[i]], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
data: data[j],
index: i,
value: v,
Expand Down

1 comment on commit d65fba1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: d65fba1 Previous: 36d467e Ratio
es/full/minify/libraries/antd 1947993696 ns/iter (± 63219512) 2216789026 ns/iter (± 693498529) 0.88
es/full/minify/libraries/d3 386147302 ns/iter (± 12932743) 425049209 ns/iter (± 47486669) 0.91
es/full/minify/libraries/echarts 1558655987 ns/iter (± 61909697) 1773982314 ns/iter (± 279931368) 0.88
es/full/minify/libraries/jquery 92020873 ns/iter (± 3383754) 140130318 ns/iter (± 152426022) 0.66
es/full/minify/libraries/lodash 140714902 ns/iter (± 10016678) 138607785 ns/iter (± 19132290) 1.02
es/full/minify/libraries/moment 57052134 ns/iter (± 2601345) 68179377 ns/iter (± 221625912) 0.84
es/full/minify/libraries/react 20372859 ns/iter (± 1844716) 25083300 ns/iter (± 20981185) 0.81
es/full/minify/libraries/terser 296549906 ns/iter (± 21346058) 471237378 ns/iter (± 278760121) 0.63
es/full/minify/libraries/three 536828296 ns/iter (± 44775035) 609616345 ns/iter (± 1322579166) 0.88
es/full/minify/libraries/typescript 3521607016 ns/iter (± 169638800) 3810238075 ns/iter (± 185500070) 0.92
es/full/minify/libraries/victory 809157952 ns/iter (± 68307913) 794146310 ns/iter (± 60803821) 1.02
es/full/minify/libraries/vue 142169357 ns/iter (± 15623321) 172950775 ns/iter (± 29811686) 0.82
es/full/codegen/es3 33867 ns/iter (± 1000) 34636 ns/iter (± 17192) 0.98
es/full/codegen/es5 33767 ns/iter (± 2023) 34573 ns/iter (± 2450) 0.98
es/full/codegen/es2015 33889 ns/iter (± 3629) 34244 ns/iter (± 3230) 0.99
es/full/codegen/es2016 34648 ns/iter (± 2768) 34255 ns/iter (± 7039) 1.01
es/full/codegen/es2017 33841 ns/iter (± 2922) 34240 ns/iter (± 2001) 0.99
es/full/codegen/es2018 33797 ns/iter (± 6660) 34447 ns/iter (± 3002) 0.98
es/full/codegen/es2019 34331 ns/iter (± 7694) 34565 ns/iter (± 2560) 0.99
es/full/codegen/es2020 33813 ns/iter (± 563) 34858 ns/iter (± 30026) 0.97
es/full/all/es3 207421605 ns/iter (± 39893428) 244922906 ns/iter (± 47114429) 0.85
es/full/all/es5 198959695 ns/iter (± 25940098) 231206053 ns/iter (± 98191294) 0.86
es/full/all/es2015 154907698 ns/iter (± 9539175) 193414564 ns/iter (± 39363762) 0.80
es/full/all/es2016 154884859 ns/iter (± 15983923) 186808269 ns/iter (± 21106218) 0.83
es/full/all/es2017 156548110 ns/iter (± 14974471) 188178283 ns/iter (± 17453419) 0.83
es/full/all/es2018 152083592 ns/iter (± 16740783) 180927442 ns/iter (± 13230953) 0.84
es/full/all/es2019 149614349 ns/iter (± 9523247) 183270143 ns/iter (± 11898906) 0.82
es/full/all/es2020 139844741 ns/iter (± 5116408) 167960692 ns/iter (± 167684963) 0.83
es/full/parser 734882 ns/iter (± 25302) 761771 ns/iter (± 94663) 0.96
es/full/base/fixer 26058 ns/iter (± 429) 27066 ns/iter (± 23854) 0.96
es/full/base/resolver_and_hygiene 93856 ns/iter (± 1566) 114467 ns/iter (± 238503) 0.82
serialization of ast node 213 ns/iter (± 3) 218 ns/iter (± 11) 0.98
serialization of serde 220 ns/iter (± 3) 223 ns/iter (± 36) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.