2
2
3
3
// ignore-tidy-filelength
4
4
// tidy-alphabetical-start
5
+ #![ allow( dead_code) ]
5
6
#![ allow( internal_features) ]
6
7
#![ doc( rust_logo) ]
7
8
#![ feature( assert_matches) ]
@@ -24,12 +25,16 @@ use std::ops::{ControlFlow, Deref};
24
25
use borrow_set:: LocalsStateAtExit ;
25
26
use root_cx:: BorrowCheckRootCtxt ;
26
27
use rustc_abi:: FieldIdx ;
28
+ #[ cfg( test) ]
29
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
27
30
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
28
31
use rustc_data_structures:: graph:: dominators:: Dominators ;
29
32
use rustc_errors:: LintDiagnostic ;
30
33
use rustc_hir as hir;
31
34
use rustc_hir:: CRATE_HIR_ID ;
32
35
use rustc_hir:: def_id:: LocalDefId ;
36
+ #[ cfg( test) ]
37
+ use rustc_index:: bit_set:: DenseBitSet ;
33
38
use rustc_index:: bit_set:: MixedBitSet ;
34
39
use rustc_index:: { IndexSlice , IndexVec } ;
35
40
use rustc_infer:: infer:: {
@@ -45,8 +50,7 @@ use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}
45
50
use rustc_mir_dataflow:: move_paths:: {
46
51
InitIndex , InitLocation , LookupResult , MoveData , MovePathIndex ,
47
52
} ;
48
- use rustc_mir_dataflow:: { Analysis , ResultsVisitor } ;
49
- // use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor, visit_results};
53
+ use rustc_mir_dataflow:: { Analysis , Results , ResultsVisitor , visit_results} ;
50
54
use rustc_session:: lint:: builtin:: { TAIL_EXPR_DROP_ORDER , UNUSED_MUT } ;
51
55
use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
52
56
use smallvec:: SmallVec ;
@@ -605,64 +609,83 @@ fn do_mir_borrowck<'tcx>(
605
609
// );
606
610
// }
607
611
608
- // if body.basic_blocks.is_cfg_cyclic() {
609
- if body. basic_blocks . thir_had_loops . unwrap_or_else ( || body. basic_blocks . is_cfg_cyclic ( ) ) {
610
- // let (mut flow_analysis, flow_entry_states) =
611
- // get_flow_results(tcx, body, &move_data, &borrow_set, ®ioncx);
612
- // visit_results(
613
- // body,
614
- // traversal::reverse_postorder(body).map(|(bb, _)| bb),
615
- // &mut flow_analysis,
616
- // &flow_entry_states,
617
- // &mut mbcx,
618
- // );
619
-
620
- // let sccs = body.basic_blocks.sccs();
621
- // let mut single_block = 0; let mut single_successor = 0; let mut single_predecessor = 0;
622
- // for &scc in &sccs.queue {
623
- // if sccs.sccs[scc as usize].len() == 1 {
624
- // single_block += 1;
625
- // }
626
-
627
- // for block in sccs.sccs[scc as usize].iter().copied() {
628
- // if body[block].terminator().successors().count() == 1 {
629
- // single_successor += 1;
630
- // }
631
-
632
- // if body.basic_blocks.predecessors()[block].len() == 1 {
633
- // single_predecessor += 1;
634
- // }
635
- // }
636
- // }
637
-
638
- // eprintln!(
639
- // "CFG, {} blocks, SCCs: {}, single-block SCCs: {}, single-successor blocks: {}, single-predecessor blocks: {}, {:?}",
640
- // body.basic_blocks.len(),
641
- // sccs.component_count,
642
- // single_block,
643
- // single_successor,
644
- // single_predecessor,
645
- // body.span,
646
- // );
647
-
648
- let borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set) ;
649
- let uninits = MaybeUninitializedPlaces :: new ( tcx, body, & move_data) ;
650
- let ever_inits = EverInitializedPlaces :: new ( body, & move_data) ;
651
- compute_cyclic_dataflow ( body, borrows, uninits, ever_inits, & mut mbcx) ;
652
-
653
- // let (_, flow_entry_states) =
654
- // get_flow_results(tcx, body, &move_data, &borrow_set, ®ioncx);
655
- // compute_cyclic_dataflow(body, borrows, uninits, ever_inits, &mut mbcx, &flow_entry_states);
612
+ if body. basic_blocks . thir_had_loops != Some ( false ) {
613
+ // Cyclic
614
+ let ( mut flow_analysis, flow_entry_states) =
615
+ get_flow_results ( tcx, body, & move_data, & borrow_set, & regioncx) ;
616
+ visit_results (
617
+ body,
618
+ traversal:: reverse_postorder ( body) . map ( |( bb, _) | bb) ,
619
+ & mut flow_analysis,
620
+ & flow_entry_states,
621
+ & mut mbcx,
622
+ ) ;
656
623
} else {
657
- // compute_dataflow(tcx, body, &move_data, &borrow_set, ®ioncx, &mut mbcx);
658
-
624
+ // Acyclic
659
625
let borrows = Borrows :: new ( tcx, body, & regioncx, & borrow_set) ;
660
626
let uninits = MaybeUninitializedPlaces :: new ( tcx, body, & move_data) ;
661
627
let ever_inits = EverInitializedPlaces :: new ( body, & move_data) ;
662
628
let mut analysis = Borrowck { borrows, uninits, ever_inits } ;
663
629
compute_rpo_dataflow ( body, & mut analysis, & mut mbcx) ;
664
630
}
665
631
632
+ // if body.basic_blocks.thir_had_loops.unwrap_or_else(|| body.basic_blocks.is_cfg_cyclic()) {
633
+ // // let (mut flow_analysis, flow_entry_states) =
634
+ // // get_flow_results(tcx, body, &move_data, &borrow_set, ®ioncx);
635
+ // // visit_results(
636
+ // // body,
637
+ // // traversal::reverse_postorder(body).map(|(bb, _)| bb),
638
+ // // &mut flow_analysis,
639
+ // // &flow_entry_states,
640
+ // // &mut mbcx,
641
+ // // );
642
+
643
+ // // let sccs = body.basic_blocks.sccs();
644
+ // // let mut single_block = 0; let mut single_successor = 0; let mut single_predecessor = 0;
645
+ // // for &scc in &sccs.queue {
646
+ // // if sccs.sccs[scc as usize].len() == 1 {
647
+ // // single_block += 1;
648
+ // // }
649
+
650
+ // // for block in sccs.sccs[scc as usize].iter().copied() {
651
+ // // if body[block].terminator().successors().count() == 1 {
652
+ // // single_successor += 1;
653
+ // // }
654
+
655
+ // // if body.basic_blocks.predecessors()[block].len() == 1 {
656
+ // // single_predecessor += 1;
657
+ // // }
658
+ // // }
659
+ // // }
660
+
661
+ // // eprintln!(
662
+ // // "CFG, {} blocks, SCCs: {}, single-block SCCs: {}, single-successor blocks: {}, single-predecessor blocks: {}, {:?}",
663
+ // // body.basic_blocks.len(),
664
+ // // sccs.component_count,
665
+ // // single_block,
666
+ // // single_successor,
667
+ // // single_predecessor,
668
+ // // body.span,
669
+ // // );
670
+
671
+ // let borrows = Borrows::new(tcx, body, ®ioncx, &borrow_set);
672
+ // let uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data);
673
+ // let ever_inits = EverInitializedPlaces::new(body, &move_data);
674
+ // compute_cyclic_dataflow(body, borrows, uninits, ever_inits, &mut mbcx);
675
+
676
+ // // let (_, flow_entry_states) =
677
+ // // get_flow_results(tcx, body, &move_data, &borrow_set, ®ioncx);
678
+ // // compute_cyclic_dataflow(body, borrows, uninits, ever_inits, &mut mbcx, &flow_entry_states);
679
+ // } else {
680
+ // // compute_dataflow(tcx, body, &move_data, &borrow_set, ®ioncx, &mut mbcx);
681
+
682
+ // let borrows = Borrows::new(tcx, body, ®ioncx, &borrow_set);
683
+ // let uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data);
684
+ // let ever_inits = EverInitializedPlaces::new(body, &move_data);
685
+ // let mut analysis = Borrowck { borrows, uninits, ever_inits };
686
+ // compute_rpo_dataflow(body, &mut analysis, &mut mbcx);
687
+ // }
688
+
666
689
mbcx. report_move_errors ( ) ;
667
690
668
691
// For each non-user used mutable variable, check if it's been assigned from
@@ -695,7 +718,7 @@ fn do_mir_borrowck<'tcx>(
695
718
} ;
696
719
697
720
#[ cfg( test) ]
698
- if body. basic_blocks . len ( ) > 5000 {
721
+ if body. basic_blocks . len ( ) > 5000 && false {
699
722
eprintln ! ( "borrow stats, locals: {}, loans: {}" , body. local_decls. len( ) , borrow_set. len( ) ) ;
700
723
eprintln ! ( "nuutila duration: {} ns" , mbcx. duration) ;
701
724
eprintln ! ( "predecessor duration: {} ns" , mbcx. duration2) ;
@@ -2529,6 +2552,7 @@ fn do_mir_borrowck<'tcx>(
2529
2552
result
2530
2553
}
2531
2554
2555
+ #[ cfg( test) ]
2532
2556
fn compute_cyclic_dataflow < ' mir , ' tcx > (
2533
2557
body : & Body < ' tcx > ,
2534
2558
borrows : Borrows < ' mir , ' tcx > ,
@@ -3802,7 +3826,6 @@ fn compute_dataflow<'a, 'tcx>(
3802
3826
}
3803
3827
}
3804
3828
3805
- #[ cfg( test) ]
3806
3829
fn get_flow_results < ' a , ' tcx > (
3807
3830
tcx : TyCtxt < ' tcx > ,
3808
3831
body : & ' a Body < ' tcx > ,
0 commit comments