11use crate :: MirPass ;
22
3- use rustc_middle:: mir:: { BasicBlockData , Body , Statement , StatementKind , TerminatorKind } ;
3+ use rustc_middle:: mir:: {
4+ BasicBlock , BasicBlockData , Body , Statement , StatementKind , TerminatorKind ,
5+ } ;
46use rustc_middle:: ty:: TyCtxt ;
57
68pub struct CtfeLimit ;
@@ -9,28 +11,28 @@ impl<'tcx> MirPass<'tcx> for CtfeLimit {
911 #[ instrument( skip( self , _tcx, body) ) ]
1012 fn run_pass ( & self , _tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
1113 let doms = body. basic_blocks . dominators ( ) ;
12- let mut indices = Vec :: new ( ) ;
13- for ( node , node_data ) in body. basic_blocks . iter_enumerated ( ) {
14- if let TerminatorKind :: Call { .. } = node_data . terminator ( ) . kind {
15- indices . push ( node) ;
16- continue ;
17- }
18- // Back edges in a CFG indicate loops
19- for ( potential_dom , _ ) in body . basic_blocks . iter_enumerated ( ) {
20- if doms. is_reachable ( potential_dom )
21- && doms. is_reachable ( node)
22- && doms . is_dominated_by ( node , potential_dom )
23- && node_data
24- . terminator ( )
25- . successors ( )
26- . into_iter ( )
27- . any ( |succ| succ == potential_dom )
28- {
29- indices . push ( node ) ;
30- continue ;
31- }
32- }
33- }
14+ let indices: Vec < BasicBlock > =
15+ body. basic_blocks
16+ . iter_enumerated ( )
17+ . filter_map ( | ( node, node_data ) | {
18+ if matches ! ( node_data . terminator ( ) . kind , TerminatorKind :: Call { .. } ) ||
19+ // Back edges in a CFG indicate loops
20+ body . basic_blocks . iter_enumerated ( ) . any ( | ( potential_dom , _ ) | {
21+ doms . is_reachable ( potential_dom )
22+ && doms. is_reachable ( node )
23+ && doms. is_dominated_by ( node, potential_dom )
24+ && node_data
25+ . terminator ( )
26+ . successors ( )
27+ . into_iter ( )
28+ . any ( |succ| succ == potential_dom )
29+ } ) {
30+ Some ( node )
31+ } else {
32+ None
33+ }
34+ } )
35+ . collect ( ) ;
3436 for index in indices {
3537 insert_counter (
3638 body. basic_blocks_mut ( )
0 commit comments