Skip to content

Commit f7afe7e

Browse files
authoredAug 7, 2023
refactor(es/minifier): Support stable rustc (#7734)
1 parent 14906e2 commit f7afe7e

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed
 

‎crates/swc_ecma_minifier/src/compress/optimize/iife.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl Optimizer<'_> {
635635
}
636636
}
637637

638-
trace_op!("iife: Empry function");
638+
trace_op!("iife: Empty function");
639639

640640
let body = f.function.body.as_mut().unwrap();
641641
if body.stmts.is_empty() && call.args.is_empty() {
@@ -724,7 +724,7 @@ impl Optimizer<'_> {
724724
// Abort on eval.
725725
// See https://github.com/swc-project/swc/pull/6478
726726
//
727-
// We completetly abort on eval, because we cannot know whether a variable in
727+
// We completely abort on eval, because we cannot know whether a variable in
728728
// upper scope will be afftected by eval.
729729
// https://github.com/swc-project/swc/issues/6628
730730
if self.data.top.has_eval_call {
@@ -1077,11 +1077,14 @@ impl Optimizer<'_> {
10771077

10781078
Expr::Arrow(ArrowExpr {
10791079
params,
1080-
body: box BlockStmtOrExpr::Expr(body),
1080+
body,
10811081
is_async: false,
10821082
is_generator: false,
10831083
..
1084-
}) => params.iter().all(|p| p.is_ident()) && self.can_be_inlined_for_iife(body),
1084+
}) if body.is_expr() => {
1085+
params.iter().all(|p| p.is_ident())
1086+
&& self.can_be_inlined_for_iife(body.as_expr().unwrap())
1087+
}
10851088

10861089
_ => false,
10871090
}

‎crates/swc_ecma_minifier/src/compress/pure/arrows.rs

+26-29
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,32 @@ impl Pure<'_> {
131131
return;
132132
}
133133

134-
if let Expr::Arrow(
135-
m @ ArrowExpr {
136-
body: box BlockStmtOrExpr::BlockStmt(..),
137-
..
138-
},
139-
) = &mut *kv.value
140-
{
141-
*p = Prop::Method(MethodProp {
142-
key: kv.key.take(),
143-
function: Box::new(Function {
144-
params: m
145-
.params
146-
.take()
147-
.into_iter()
148-
.map(|pat| Param {
149-
span: DUMMY_SP,
150-
decorators: Default::default(),
151-
pat,
152-
})
153-
.collect(),
154-
decorators: Default::default(),
155-
span: m.span,
156-
body: m.body.take().block_stmt(),
157-
is_generator: m.is_generator,
158-
is_async: m.is_async,
159-
type_params: Default::default(),
160-
return_type: Default::default(),
161-
}),
162-
});
134+
match &mut *kv.value {
135+
Expr::Arrow(m) if m.body.is_block_stmt() => {
136+
*p = Prop::Method(MethodProp {
137+
key: kv.key.take(),
138+
function: Box::new(Function {
139+
params: m
140+
.params
141+
.take()
142+
.into_iter()
143+
.map(|pat| Param {
144+
span: DUMMY_SP,
145+
decorators: Default::default(),
146+
pat,
147+
})
148+
.collect(),
149+
decorators: Default::default(),
150+
span: m.span,
151+
body: m.body.take().block_stmt(),
152+
is_generator: m.is_generator,
153+
is_async: m.is_async,
154+
type_params: Default::default(),
155+
return_type: Default::default(),
156+
}),
157+
});
158+
}
159+
_ => (),
163160
}
164161
}
165162
}

‎crates/swc_ecma_minifier/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#![allow(clippy::only_used_in_recursion)]
3737
#![allow(unstable_name_collisions)]
3838
#![allow(clippy::match_like_matches_macro)]
39-
#![feature(box_patterns)]
4039

4140
use once_cell::sync::Lazy;
4241
use swc_common::{comments::Comments, pass::Repeated, sync::Lrc, SourceMap, SyntaxContext};

‎crates/swc_ecma_minifier/src/pass/global_defs.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,32 @@ fn should_replace(pred: &Expr, node: &Expr) -> bool {
101101
return true;
102102
}
103103

104-
match (pred, node) {
104+
fn match_node(node: &Expr) -> Option<(&Expr, &MemberProp)> {
105+
match node {
106+
Expr::Member(MemberExpr {
107+
obj: node_obj,
108+
prop: nodes,
109+
..
110+
}) => Some((node_obj, nodes)),
111+
112+
Expr::OptChain(OptChainExpr { base, .. }) => {
113+
let base = base.as_member()?;
114+
Some((&base.obj, &base.prop))
115+
}
116+
117+
_ => None,
118+
}
119+
}
120+
121+
match (pred, match_node(node)) {
105122
// super?. is invalid
106123
(
107124
Expr::Member(MemberExpr {
108125
obj: pred_obj,
109126
prop: pred,
110127
..
111128
}),
112-
Expr::Member(MemberExpr {
113-
obj: node_obj,
114-
prop: nodes,
115-
..
116-
})
117-
| Expr::OptChain(OptChainExpr {
118-
base:
119-
box OptChainBase::Member(MemberExpr {
120-
obj: node_obj,
121-
prop: nodes,
122-
..
123-
}),
124-
..
125-
}),
129+
Some((node_obj, nodes)),
126130
) if !(pred.is_computed() || nodes.is_computed()) => {
127131
if !pred.eq_ignore_span(nodes) {
128132
return false;

1 commit comments

Comments
 (1)

github-actions[bot] commented on Aug 8, 2023

@github-actions[bot]

Benchmark

Benchmark suite Current: f7afe7e Previous: b45649b Ratio
es/full/bugs-1 281321 ns/iter (± 5968) 289046 ns/iter (± 9887) 0.97
es/full/minify/libraries/antd 1329067799 ns/iter (± 48713937) 1303875518 ns/iter (± 7991386) 1.02
es/full/minify/libraries/d3 302126237 ns/iter (± 17439946) 278330200 ns/iter (± 1923912) 1.09
es/full/minify/libraries/echarts 1157971677 ns/iter (± 48533233) 1089477446 ns/iter (± 30216552) 1.06
es/full/minify/libraries/jquery 86568223 ns/iter (± 2243270) 86611396 ns/iter (± 682332) 1.00
es/full/minify/libraries/lodash 98720789 ns/iter (± 4060939) 101544180 ns/iter (± 516018) 0.97
es/full/minify/libraries/moment 50117419 ns/iter (± 137048) 50969121 ns/iter (± 140320) 0.98
es/full/minify/libraries/react 18125269 ns/iter (± 180447) 18159756 ns/iter (± 71324) 1.00
es/full/minify/libraries/terser 220061176 ns/iter (± 8045597) 223125922 ns/iter (± 3186361) 0.99
es/full/minify/libraries/three 413900000 ns/iter (± 20921342) 427985502 ns/iter (± 14919502) 0.97
es/full/minify/libraries/typescript 2686735875 ns/iter (± 88997927) 2806525547 ns/iter (± 59669927) 0.96
es/full/minify/libraries/victory 573452910 ns/iter (± 27853892) 651972308 ns/iter (± 19422214) 0.88
es/full/minify/libraries/vue 121088466 ns/iter (± 2065640) 128291180 ns/iter (± 1550186) 0.94
es/full/codegen/es3 35231 ns/iter (± 173) 35466 ns/iter (± 84) 0.99
es/full/codegen/es5 35087 ns/iter (± 83) 35414 ns/iter (± 80) 0.99
es/full/codegen/es2015 34994 ns/iter (± 449) 35392 ns/iter (± 87) 0.99
es/full/codegen/es2016 35160 ns/iter (± 87) 35422 ns/iter (± 58) 0.99
es/full/codegen/es2017 35088 ns/iter (± 290) 35492 ns/iter (± 154) 0.99
es/full/codegen/es2018 35051 ns/iter (± 2383) 35444 ns/iter (± 104) 0.99
es/full/codegen/es2019 34979 ns/iter (± 87) 35368 ns/iter (± 92) 0.99
es/full/codegen/es2020 35086 ns/iter (± 62) 35352 ns/iter (± 90) 0.99
es/full/all/es3 172946234 ns/iter (± 1415808) 174392827 ns/iter (± 1706049) 0.99
es/full/all/es5 166414629 ns/iter (± 2326594) 168417513 ns/iter (± 918337) 0.99
es/full/all/es2015 124863891 ns/iter (± 928348) 126191250 ns/iter (± 621224) 0.99
es/full/all/es2016 123338017 ns/iter (± 1067217) 125970915 ns/iter (± 609549) 0.98
es/full/all/es2017 121947569 ns/iter (± 847843) 124710291 ns/iter (± 745963) 0.98
es/full/all/es2018 121013051 ns/iter (± 1078862) 122113383 ns/iter (± 724426) 0.99
es/full/all/es2019 121101012 ns/iter (± 1229387) 121939001 ns/iter (± 692422) 0.99
es/full/all/es2020 115279697 ns/iter (± 932491) 117689753 ns/iter (± 569742) 0.98
es/full/parser 535115 ns/iter (± 10554) 535124 ns/iter (± 5360) 1.00
es/full/base/fixer 17817 ns/iter (± 60) 19442 ns/iter (± 97) 0.92
es/full/base/resolver_and_hygiene 80450 ns/iter (± 164) 84412 ns/iter (± 142) 0.95
serialization of serde 294 ns/iter (± 2) 299 ns/iter (± 0) 0.98
css/minify/libraries/bootstrap 29400853 ns/iter (± 472048) 28803795 ns/iter (± 30044) 1.02
css/visitor/compare/clone 1640511 ns/iter (± 4295) 1637166 ns/iter (± 2437) 1.00
css/visitor/compare/visit_mut_span 1773380 ns/iter (± 8606) 1776774 ns/iter (± 7402) 1.00
css/visitor/compare/visit_mut_span_panic 1841005 ns/iter (± 28174) 1860104 ns/iter (± 5634) 0.99
css/visitor/compare/fold_span 2592090 ns/iter (± 38871) 2604692 ns/iter (± 13475) 1.00
css/visitor/compare/fold_span_panic 2765629 ns/iter (± 14586) 2795901 ns/iter (± 14833) 0.99
css/lexer/bootstrap_5_1_3 4552997 ns/iter (± 2523) 4559234 ns/iter (± 13860) 1.00
css/lexer/foundation_6_7_4 3887923 ns/iter (± 3933) 3844395 ns/iter (± 7945) 1.01
css/lexer/tailwind_3_1_1 742633 ns/iter (± 539) 731853 ns/iter (± 899) 1.01
css/parser/bootstrap_5_1_3 19484292 ns/iter (± 355435) 19434040 ns/iter (± 26457) 1.00
css/parser/foundation_6_7_4 15627759 ns/iter (± 445378) 15663553 ns/iter (± 23564) 1.00
css/parser/tailwind_3_1_1 2968120 ns/iter (± 5160) 2994091 ns/iter (± 2535) 0.99
es/codegen/colors 718725 ns/iter (± 394348) 736894 ns/iter (± 402390) 0.98
es/codegen/large 3153893 ns/iter (± 1667225) 3144791 ns/iter (± 1665290) 1.00
es/codegen/with-parser/colors 46041 ns/iter (± 241) 45276 ns/iter (± 173) 1.02
es/codegen/with-parser/large 490926 ns/iter (± 1189) 489042 ns/iter (± 704) 1.00
es/minify/libraries/antd 1170515988 ns/iter (± 64457151) 1155131033 ns/iter (± 14712005) 1.01
es/minify/libraries/d3 266689165 ns/iter (± 12234294) 242835890 ns/iter (± 458466) 1.10
es/minify/libraries/echarts 922400421 ns/iter (± 40596738) 917438675 ns/iter (± 2549578) 1.01
es/minify/libraries/jquery 75076031 ns/iter (± 1818223) 74823913 ns/iter (± 223740) 1.00
es/minify/libraries/lodash 92306221 ns/iter (± 1843775) 89224151 ns/iter (± 255767) 1.03
es/minify/libraries/moment 45405180 ns/iter (± 815406) 44062903 ns/iter (± 44182) 1.03
es/minify/libraries/react 16791704 ns/iter (± 215234) 16190505 ns/iter (± 43341) 1.04
es/minify/libraries/terser 190539896 ns/iter (± 7897650) 189019957 ns/iter (± 338140) 1.01
es/minify/libraries/three 329478162 ns/iter (± 21964643) 325320404 ns/iter (± 627027) 1.01
es/minify/libraries/typescript 2381279060 ns/iter (± 53522311) 2296086673 ns/iter (± 6087438) 1.04
es/minify/libraries/victory 511605414 ns/iter (± 47916684) 478372947 ns/iter (± 1126017) 1.07
es/minify/libraries/vue 111973554 ns/iter (± 2911293) 108477009 ns/iter (± 163468) 1.03
es/visitor/compare/clone 1935703 ns/iter (± 5644) 1932669 ns/iter (± 53010) 1.00
es/visitor/compare/visit_mut_span 2294739 ns/iter (± 28913) 2282096 ns/iter (± 7793) 1.01
es/visitor/compare/visit_mut_span_panic 2335367 ns/iter (± 10646) 2314846 ns/iter (± 5963) 1.01
es/visitor/compare/fold_span 3351407 ns/iter (± 36066) 3325014 ns/iter (± 7673) 1.01
es/visitor/compare/fold_span_panic 3515511 ns/iter (± 39633) 3459309 ns/iter (± 7746) 1.02
es/lexer/colors 12969 ns/iter (± 18) 13527 ns/iter (± 33) 0.96
es/lexer/angular 6060905 ns/iter (± 20489) 6325888 ns/iter (± 9027) 0.96
es/lexer/backbone 788124 ns/iter (± 1312) 832493 ns/iter (± 520) 0.95
es/lexer/jquery 4459235 ns/iter (± 4891) 4682687 ns/iter (± 7724) 0.95
es/lexer/jquery mobile 6811130 ns/iter (± 12381) 7148672 ns/iter (± 6909) 0.95
es/lexer/mootools 3531517 ns/iter (± 9203) 3704304 ns/iter (± 8446) 0.95
es/lexer/underscore 663670 ns/iter (± 745) 688978 ns/iter (± 1129) 0.96
es/lexer/three 21313385 ns/iter (± 23262) 22106176 ns/iter (± 25376) 0.96
es/lexer/yui 3837078 ns/iter (± 4348) 3966716 ns/iter (± 1916) 0.97
es/parser/colors 27558 ns/iter (± 49) 27432 ns/iter (± 41) 1.00
es/parser/angular 13481042 ns/iter (± 56749) 13617178 ns/iter (± 57198) 0.99
es/parser/backbone 1997658 ns/iter (± 10882) 2013804 ns/iter (± 7687) 0.99
es/parser/jquery 10923636 ns/iter (± 188193) 11030759 ns/iter (± 27228) 0.99
es/parser/jquery mobile 17073134 ns/iter (± 598236) 16832324 ns/iter (± 51337) 1.01
es/parser/mootools 8421970 ns/iter (± 34904) 8489082 ns/iter (± 17765) 0.99
es/parser/underscore 1736959 ns/iter (± 8881) 1740223 ns/iter (± 8776) 1.00
es/parser/three 47375158 ns/iter (± 1493939) 46909997 ns/iter (± 109992) 1.01
es/parser/yui 8272077 ns/iter (± 57137) 8352723 ns/iter (± 27759) 0.99
es/preset-env/usage/builtin_type 136464 ns/iter (± 32428) 136349 ns/iter (± 32034) 1.00
es/preset-env/usage/property 16729 ns/iter (± 81) 16816 ns/iter (± 83) 0.99
es/resolver/typescript 90705316 ns/iter (± 2438652) 89026990 ns/iter (± 775939) 1.02
es/fixer/typescript 64263743 ns/iter (± 1037608) 63306562 ns/iter (± 645314) 1.02
es/hygiene/typescript 138723453 ns/iter (± 6747467) 129923733 ns/iter (± 870022) 1.07
es/resolver_with_hygiene/typescript 247739917 ns/iter (± 8874321) 241035057 ns/iter (± 914554) 1.03
es/visitor/base-perf/module_clone 60856 ns/iter (± 198) 59096 ns/iter (± 715) 1.03
es/visitor/base-perf/fold_empty 64054 ns/iter (± 915) 63189 ns/iter (± 201) 1.01
es/visitor/base-perf/fold_noop_impl_all 64393 ns/iter (± 238) 63148 ns/iter (± 146) 1.02
es/visitor/base-perf/fold_noop_impl_vec 64073 ns/iter (± 228) 63152 ns/iter (± 274) 1.01
es/visitor/base-perf/boxing_boxed_clone 82 ns/iter (± 0) 56 ns/iter (± 0) 1.46
es/visitor/base-perf/boxing_unboxed_clone 40 ns/iter (± 0) 40 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 134 ns/iter (± 0) 109 ns/iter (± 0) 1.23
es/visitor/base-perf/boxing_unboxed 90 ns/iter (± 0) 78 ns/iter (± 0) 1.15
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2479 ns/iter (± 31) 2526 ns/iter (± 25) 0.98
es/base/parallel/resolver/typescript 3911727560 ns/iter (± 302094983) 3902247200 ns/iter (± 268834364) 1.00
es/base/parallel/hygiene/typescript 1468477587 ns/iter (± 33320225) 1475092770 ns/iter (± 9535589) 1.00
misc/visitors/time-complexity/time 5 119 ns/iter (± 2) 142 ns/iter (± 1) 0.84
misc/visitors/time-complexity/time 10 357 ns/iter (± 5) 363 ns/iter (± 5) 0.98
misc/visitors/time-complexity/time 15 691 ns/iter (± 8) 701 ns/iter (± 28) 0.99
misc/visitors/time-complexity/time 20 1025 ns/iter (± 17) 1047 ns/iter (± 4) 0.98
misc/visitors/time-complexity/time 40 3503 ns/iter (± 66) 3590 ns/iter (± 41) 0.98
misc/visitors/time-complexity/time 60 8070 ns/iter (± 131) 7929 ns/iter (± 164) 1.02
es/full-target/es2016 238173 ns/iter (± 2142) 234940 ns/iter (± 810) 1.01
es/full-target/es2017 226224 ns/iter (± 4772) 224981 ns/iter (± 938) 1.01
es/full-target/es2018 212322 ns/iter (± 2384) 212048 ns/iter (± 861) 1.00
es2020_nullish_coalescing 68902 ns/iter (± 1365) 71072 ns/iter (± 414) 0.97
es2020_optional_chaining 81497 ns/iter (± 1340) 81731 ns/iter (± 196) 1.00
es2022_class_properties 118774 ns/iter (± 2240) 120395 ns/iter (± 1417) 0.99
es2018_object_rest_spread 75687 ns/iter (± 528) 74472 ns/iter (± 184) 1.02
es2019_optional_catch_binding 64129 ns/iter (± 929) 64142 ns/iter (± 273) 1.00
es2017_async_to_generator 64397 ns/iter (± 348) 63869 ns/iter (± 195) 1.01
es2016_exponentiation 67771 ns/iter (± 1091) 68270 ns/iter (± 109) 0.99
es2015_arrow 71065 ns/iter (± 901) 71339 ns/iter (± 261) 1.00
es2015_block_scoped_fn 67021 ns/iter (± 791) 68294 ns/iter (± 212) 0.98
es2015_block_scoping 123704 ns/iter (± 1649) 122703 ns/iter (± 360) 1.01

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

Please sign in to comment.