1
1
use crate :: {
2
2
core:: token:: { AstToken , SymbolKind , Token } ,
3
- traverse:: { Parse , ParseContext } ,
3
+ traverse:: { adaptive_iter , Parse , ParseContext } ,
4
4
} ;
5
- use rayon:: iter:: { IntoParallelRefIterator , ParallelBridge , ParallelIterator } ;
5
+ use rayon:: iter:: { ParallelBridge , ParallelIterator } ;
6
6
use sway_ast:: {
7
7
expr:: LoopControlFlow , ty:: TyTupleDescriptor , Assignable , CodeBlockContents , ConfigurableField ,
8
8
Expr , ExprArrayDescriptor , ExprStructField , ExprTupleDescriptor , FnArg , FnArgs , FnSignature ,
@@ -16,23 +16,18 @@ use sway_types::{Ident, Span, Spanned};
16
16
17
17
pub fn parse ( lexed_program : & LexedProgram , ctx : & ParseContext ) {
18
18
insert_module_kind ( ctx, & lexed_program. root . tree . kind ) ;
19
- lexed_program
20
- . root
21
- . tree
22
- . items
23
- . par_iter ( )
24
- . for_each ( |item| item. value . parse ( ctx) ) ;
19
+ adaptive_iter ( & lexed_program. root . tree . items , |item| {
20
+ item. value . parse ( ctx) ;
21
+ } ) ;
25
22
26
23
lexed_program
27
24
. root
28
25
. submodules_recursive ( )
29
26
. for_each ( |( _, dep) | {
30
27
insert_module_kind ( ctx, & dep. module . tree . kind ) ;
31
- dep. module
32
- . tree
33
- . items
34
- . par_iter ( )
35
- . for_each ( |item| item. value . parse ( ctx) ) ;
28
+ adaptive_iter ( & dep. module . tree . items , |item| {
29
+ item. value . parse ( ctx) ;
30
+ } ) ;
36
31
} ) ;
37
32
}
38
33
@@ -157,7 +152,7 @@ impl Parse for Expr {
157
152
} => {
158
153
insert_keyword ( ctx, match_token. span ( ) ) ;
159
154
value. parse ( ctx) ;
160
- branches. get ( ) . iter ( ) . par_bridge ( ) . for_each ( |branch| {
155
+ adaptive_iter ( branches. get ( ) , |branch| {
161
156
branch. pattern . parse ( ctx) ;
162
157
branch. kind . parse ( ctx) ;
163
158
} ) ;
@@ -326,21 +321,15 @@ impl Parse for ItemTrait {
326
321
insert_keyword ( ctx, where_clause_opt. where_token . span ( ) ) ;
327
322
}
328
323
329
- self . trait_items
330
- . get ( )
331
- . par_iter ( )
332
- . for_each ( |annotated| match & annotated. value {
333
- sway_ast:: ItemTraitItem :: Fn ( fn_sig, _) => fn_sig. parse ( ctx) ,
334
- sway_ast:: ItemTraitItem :: Const ( item_const, _) => item_const. parse ( ctx) ,
335
- sway_ast:: ItemTraitItem :: Type ( item_type, _) => item_type. parse ( ctx) ,
336
- sway_ast:: ItemTraitItem :: Error ( _, _) => { }
337
- } ) ;
324
+ adaptive_iter ( self . trait_items . get ( ) , |annotated| match & annotated. value {
325
+ sway_ast:: ItemTraitItem :: Fn ( fn_sig, _) => fn_sig. parse ( ctx) ,
326
+ sway_ast:: ItemTraitItem :: Const ( item_const, _) => item_const. parse ( ctx) ,
327
+ sway_ast:: ItemTraitItem :: Type ( item_type, _) => item_type. parse ( ctx) ,
328
+ sway_ast:: ItemTraitItem :: Error ( _, _) => { }
329
+ } ) ;
338
330
339
331
if let Some ( trait_defs_opt) = & self . trait_defs_opt {
340
- trait_defs_opt
341
- . get ( )
342
- . par_iter ( )
343
- . for_each ( |item| item. value . parse ( ctx) ) ;
332
+ adaptive_iter ( trait_defs_opt. get ( ) , |item| item. value . parse ( ctx) ) ;
344
333
}
345
334
}
346
335
}
@@ -359,36 +348,27 @@ impl Parse for ItemImpl {
359
348
insert_keyword ( ctx, where_clause_opt. where_token . span ( ) ) ;
360
349
}
361
350
362
- self . contents
363
- . get ( )
364
- . par_iter ( )
365
- . for_each ( |item| match & item. value {
366
- ItemImplItem :: Fn ( fn_decl) => fn_decl. parse ( ctx) ,
367
- ItemImplItem :: Const ( const_decl) => const_decl. parse ( ctx) ,
368
- ItemImplItem :: Type ( type_decl) => type_decl. parse ( ctx) ,
369
- } ) ;
351
+ adaptive_iter ( self . contents . get ( ) , |item| match & item. value {
352
+ ItemImplItem :: Fn ( fn_decl) => fn_decl. parse ( ctx) ,
353
+ ItemImplItem :: Const ( const_decl) => const_decl. parse ( ctx) ,
354
+ ItemImplItem :: Type ( type_decl) => type_decl. parse ( ctx) ,
355
+ } ) ;
370
356
}
371
357
}
372
358
373
359
impl Parse for ItemAbi {
374
360
fn parse ( & self , ctx : & ParseContext ) {
375
361
insert_keyword ( ctx, self . abi_token . span ( ) ) ;
376
362
377
- self . abi_items
378
- . get ( )
379
- . par_iter ( )
380
- . for_each ( |annotated| match & annotated. value {
381
- sway_ast:: ItemTraitItem :: Fn ( fn_sig, _) => fn_sig. parse ( ctx) ,
382
- sway_ast:: ItemTraitItem :: Const ( item_const, _) => item_const. parse ( ctx) ,
383
- sway_ast:: ItemTraitItem :: Type ( item_type, _) => item_type. parse ( ctx) ,
384
- sway_ast:: ItemTraitItem :: Error ( _, _) => { }
385
- } ) ;
363
+ adaptive_iter ( self . abi_items . get ( ) , |annotated| match & annotated. value {
364
+ sway_ast:: ItemTraitItem :: Fn ( fn_sig, _) => fn_sig. parse ( ctx) ,
365
+ sway_ast:: ItemTraitItem :: Const ( item_const, _) => item_const. parse ( ctx) ,
366
+ sway_ast:: ItemTraitItem :: Type ( item_type, _) => item_type. parse ( ctx) ,
367
+ sway_ast:: ItemTraitItem :: Error ( _, _) => { }
368
+ } ) ;
386
369
387
370
if let Some ( abi_defs_opt) = self . abi_defs_opt . as_ref ( ) {
388
- abi_defs_opt
389
- . get ( )
390
- . par_iter ( )
391
- . for_each ( |item| item. value . parse ( ctx) ) ;
371
+ adaptive_iter ( abi_defs_opt. get ( ) , |item| item. value . parse ( ctx) ) ;
392
372
}
393
373
}
394
374
}
@@ -576,9 +556,9 @@ impl Parse for FnArg {
576
556
577
557
impl Parse for CodeBlockContents {
578
558
fn parse ( & self , ctx : & ParseContext ) {
579
- self . statements
580
- . par_iter ( )
581
- . for_each ( |statement| statement . parse ( ctx ) ) ;
559
+ adaptive_iter ( & self . statements , |statement| {
560
+ statement . parse ( ctx ) ;
561
+ } ) ;
582
562
if let Some ( expr) = self . final_expr_opt . as_ref ( ) {
583
563
expr. parse ( ctx) ;
584
564
}
0 commit comments