@@ -3,7 +3,7 @@ use oxc_ast::ast::*;
3
3
use oxc_traverse:: { traverse_mut_with_ctx, ReusableTraverseCtx , Traverse , TraverseCtx } ;
4
4
5
5
mod collapse_variable_declarations;
6
- mod exploit_assigns;
6
+ // mod exploit_assigns;
7
7
mod normalize;
8
8
mod peephole_fold_constants;
9
9
mod peephole_minimize_conditions;
@@ -14,7 +14,7 @@ mod remove_syntax;
14
14
mod statement_fusion;
15
15
16
16
pub use collapse_variable_declarations:: CollapseVariableDeclarations ;
17
- pub use exploit_assigns:: ExploitAssigns ;
17
+ // pub use exploit_assigns::ExploitAssigns;
18
18
pub use normalize:: Normalize ;
19
19
pub use peephole_fold_constants:: PeepholeFoldConstants ;
20
20
pub use peephole_minimize_conditions:: PeepholeMinimizeConditions ;
@@ -30,56 +30,20 @@ pub trait CompressorPass<'a>: Traverse<'a> {
30
30
fn build ( & mut self , program : & mut Program < ' a > , ctx : & mut ReusableTraverseCtx < ' a > ) ;
31
31
}
32
32
33
- // See `peepholeOptimizationsOnce`
34
-
35
- // For pass:
36
- // ```
37
- // if (options.collapseVariableDeclarations) {
38
- // passes.maybeAdd(exploitAssign);
39
- // passes.maybeAdd(collapseVariableDeclarations);
40
- // }
41
- // ```
42
- pub struct CollapsePass {
43
- _x0_exploit_assigns : ExploitAssigns ,
44
- x1_collapse_variable_declarations : CollapseVariableDeclarations ,
45
- }
46
-
47
- impl CollapsePass {
48
- pub fn new ( ) -> Self {
49
- Self {
50
- _x0_exploit_assigns : ExploitAssigns :: new ( ) ,
51
- x1_collapse_variable_declarations : CollapseVariableDeclarations :: new ( ) ,
52
- }
53
- }
54
- }
55
-
56
- impl < ' a > CompressorPass < ' a > for CollapsePass {
57
- fn build ( & mut self , program : & mut Program < ' a > , ctx : & mut ReusableTraverseCtx < ' a > ) {
58
- traverse_mut_with_ctx ( self , program, ctx) ;
59
- }
60
- }
61
-
62
- impl < ' a > Traverse < ' a > for CollapsePass {
63
- fn exit_statements ( & mut self , stmts : & mut Vec < ' a , Statement < ' a > > , ctx : & mut TraverseCtx < ' a > ) {
64
- self . x1_collapse_variable_declarations . exit_statements ( stmts, ctx) ;
65
- }
66
- }
67
-
68
33
// See `latePeepholeOptimizations`
69
- pub struct LatePeepholeOptimizations {
34
+ pub struct PeepholeOptimizations {
70
35
x0_statement_fusion : StatementFusion ,
71
36
x1_collapse_variable_declarations : CollapseVariableDeclarations ,
72
37
x2_peephole_remove_dead_code : PeepholeRemoveDeadCode ,
73
- // TODO: MinimizeExitPoints
74
38
x3_peephole_minimize_conditions : PeepholeMinimizeConditions ,
75
39
x4_peephole_substitute_alternate_syntax : PeepholeSubstituteAlternateSyntax ,
76
40
x5_peephole_replace_known_methods : PeepholeReplaceKnownMethods ,
77
41
x6_peephole_fold_constants : PeepholeFoldConstants ,
42
+ x7_collapse_variable_declarations : CollapseVariableDeclarations ,
78
43
}
79
44
80
- impl LatePeepholeOptimizations {
81
- pub fn new ( options : CompressOptions ) -> Self {
82
- let in_fixed_loop = true ;
45
+ impl PeepholeOptimizations {
46
+ pub fn new ( in_fixed_loop : bool , options : CompressOptions ) -> Self {
83
47
Self {
84
48
x0_statement_fusion : StatementFusion :: new ( ) ,
85
49
x1_collapse_variable_declarations : CollapseVariableDeclarations :: new ( ) ,
@@ -91,6 +55,7 @@ impl LatePeepholeOptimizations {
91
55
) ,
92
56
x5_peephole_replace_known_methods : PeepholeReplaceKnownMethods :: new ( ) ,
93
57
x6_peephole_fold_constants : PeepholeFoldConstants :: new ( ) ,
58
+ x7_collapse_variable_declarations : CollapseVariableDeclarations :: new ( ) ,
94
59
}
95
60
}
96
61
@@ -102,6 +67,7 @@ impl LatePeepholeOptimizations {
102
67
self . x4_peephole_substitute_alternate_syntax . changed = false ;
103
68
self . x5_peephole_replace_known_methods . changed = false ;
104
69
self . x6_peephole_fold_constants . changed = false ;
70
+ self . x7_collapse_variable_declarations . changed = false ;
105
71
}
106
72
107
73
fn changed ( & self ) -> bool {
@@ -112,6 +78,7 @@ impl LatePeepholeOptimizations {
112
78
|| self . x4_peephole_substitute_alternate_syntax . changed
113
79
|| self . x5_peephole_replace_known_methods . changed
114
80
|| self . x6_peephole_fold_constants . changed
81
+ || self . x7_collapse_variable_declarations . changed
115
82
}
116
83
117
84
pub fn run_in_loop < ' a > (
@@ -135,13 +102,13 @@ impl LatePeepholeOptimizations {
135
102
}
136
103
}
137
104
138
- impl < ' a > CompressorPass < ' a > for LatePeepholeOptimizations {
105
+ impl < ' a > CompressorPass < ' a > for PeepholeOptimizations {
139
106
fn build ( & mut self , program : & mut Program < ' a > , ctx : & mut ReusableTraverseCtx < ' a > ) {
140
107
traverse_mut_with_ctx ( self , program, ctx) ;
141
108
}
142
109
}
143
110
144
- impl < ' a > Traverse < ' a > for LatePeepholeOptimizations {
111
+ impl < ' a > Traverse < ' a > for PeepholeOptimizations {
145
112
fn exit_program ( & mut self , program : & mut Program < ' a > , ctx : & mut TraverseCtx < ' a > ) {
146
113
self . x0_statement_fusion . exit_program ( program, ctx) ;
147
114
self . x2_peephole_remove_dead_code . exit_program ( program, ctx) ;
@@ -155,6 +122,7 @@ impl<'a> Traverse<'a> for LatePeepholeOptimizations {
155
122
self . x1_collapse_variable_declarations . exit_statements ( stmts, ctx) ;
156
123
self . x2_peephole_remove_dead_code . exit_statements ( stmts, ctx) ;
157
124
self . x3_peephole_minimize_conditions . exit_statements ( stmts, ctx) ;
125
+ self . x7_collapse_variable_declarations . exit_statements ( stmts, ctx) ;
158
126
}
159
127
160
128
fn exit_statement ( & mut self , stmt : & mut Statement < ' a > , ctx : & mut TraverseCtx < ' a > ) {
@@ -203,90 +171,6 @@ impl<'a> Traverse<'a> for LatePeepholeOptimizations {
203
171
}
204
172
}
205
173
206
- // See `createPeepholeOptimizationsPass`
207
- pub struct PeepholeOptimizations {
208
- // TODO: MinimizeExitPoints
209
- x2_peephole_minimize_conditions : PeepholeMinimizeConditions ,
210
- x3_peephole_substitute_alternate_syntax : PeepholeSubstituteAlternateSyntax ,
211
- x4_peephole_replace_known_methods : PeepholeReplaceKnownMethods ,
212
- x5_peephole_remove_dead_code : PeepholeRemoveDeadCode ,
213
- x6_peephole_fold_constants : PeepholeFoldConstants ,
214
- }
215
-
216
- impl PeepholeOptimizations {
217
- pub fn new ( options : CompressOptions ) -> Self {
218
- let in_fixed_loop = false ;
219
- Self {
220
- x2_peephole_minimize_conditions : PeepholeMinimizeConditions :: new ( in_fixed_loop) ,
221
- x3_peephole_substitute_alternate_syntax : PeepholeSubstituteAlternateSyntax :: new (
222
- options,
223
- in_fixed_loop,
224
- ) ,
225
- x4_peephole_replace_known_methods : PeepholeReplaceKnownMethods :: new ( ) ,
226
- x5_peephole_remove_dead_code : PeepholeRemoveDeadCode :: new ( ) ,
227
- x6_peephole_fold_constants : PeepholeFoldConstants :: new ( ) ,
228
- }
229
- }
230
- }
231
-
232
- impl < ' a > CompressorPass < ' a > for PeepholeOptimizations {
233
- fn build ( & mut self , program : & mut Program < ' a > , ctx : & mut ReusableTraverseCtx < ' a > ) {
234
- traverse_mut_with_ctx ( self , program, ctx) ;
235
- }
236
- }
237
-
238
- impl < ' a > Traverse < ' a > for PeepholeOptimizations {
239
- fn exit_program ( & mut self , program : & mut Program < ' a > , ctx : & mut TraverseCtx < ' a > ) {
240
- self . x5_peephole_remove_dead_code . exit_program ( program, ctx) ;
241
- }
242
-
243
- fn exit_statements ( & mut self , stmts : & mut Vec < ' a , Statement < ' a > > , ctx : & mut TraverseCtx < ' a > ) {
244
- self . x2_peephole_minimize_conditions . exit_statements ( stmts, ctx) ;
245
- self . x5_peephole_remove_dead_code . exit_statements ( stmts, ctx) ;
246
- }
247
-
248
- fn exit_statement ( & mut self , stmt : & mut Statement < ' a > , ctx : & mut TraverseCtx < ' a > ) {
249
- self . x2_peephole_minimize_conditions . exit_statement ( stmt, ctx) ;
250
- self . x5_peephole_remove_dead_code . exit_statement ( stmt, ctx) ;
251
- }
252
-
253
- fn exit_return_statement ( & mut self , stmt : & mut ReturnStatement < ' a > , ctx : & mut TraverseCtx < ' a > ) {
254
- self . x3_peephole_substitute_alternate_syntax . exit_return_statement ( stmt, ctx) ;
255
- }
256
-
257
- fn exit_variable_declaration (
258
- & mut self ,
259
- decl : & mut VariableDeclaration < ' a > ,
260
- ctx : & mut TraverseCtx < ' a > ,
261
- ) {
262
- self . x3_peephole_substitute_alternate_syntax . exit_variable_declaration ( decl, ctx) ;
263
- }
264
-
265
- fn exit_expression ( & mut self , expr : & mut Expression < ' a > , ctx : & mut TraverseCtx < ' a > ) {
266
- self . x2_peephole_minimize_conditions . exit_expression ( expr, ctx) ;
267
- self . x3_peephole_substitute_alternate_syntax . exit_expression ( expr, ctx) ;
268
- self . x4_peephole_replace_known_methods . exit_expression ( expr, ctx) ;
269
- self . x5_peephole_remove_dead_code . exit_expression ( expr, ctx) ;
270
- self . x6_peephole_fold_constants . exit_expression ( expr, ctx) ;
271
- }
272
-
273
- fn enter_call_expression ( & mut self , expr : & mut CallExpression < ' a > , ctx : & mut TraverseCtx < ' a > ) {
274
- self . x3_peephole_substitute_alternate_syntax . enter_call_expression ( expr, ctx) ;
275
- }
276
-
277
- fn exit_call_expression ( & mut self , expr : & mut CallExpression < ' a > , ctx : & mut TraverseCtx < ' a > ) {
278
- self . x3_peephole_substitute_alternate_syntax . exit_call_expression ( expr, ctx) ;
279
- }
280
-
281
- fn exit_property_key ( & mut self , key : & mut PropertyKey < ' a > , ctx : & mut TraverseCtx < ' a > ) {
282
- self . x3_peephole_substitute_alternate_syntax . exit_property_key ( key, ctx) ;
283
- }
284
-
285
- fn exit_catch_clause ( & mut self , catch : & mut CatchClause < ' a > , ctx : & mut TraverseCtx < ' a > ) {
286
- self . x3_peephole_substitute_alternate_syntax . exit_catch_clause ( catch, ctx) ;
287
- }
288
- }
289
-
290
174
pub struct DeadCodeElimination {
291
175
x1_peephole_fold_constants : PeepholeFoldConstants ,
292
176
x2_peephole_remove_dead_code : PeepholeRemoveDeadCode ,
0 commit comments