@@ -11,101 +11,88 @@ use rustc_middle::ty::TyCtxt;
1111use rustc_mir_dataflow:: impls:: { EverInitializedPlaces , MaybeUninitializedPlaces } ;
1212use rustc_mir_dataflow:: ResultsVisitable ;
1313use rustc_mir_dataflow:: { self , fmt:: DebugWithContext , GenKill } ;
14- use rustc_mir_dataflow:: { Analysis , Direction , Results } ;
14+ use rustc_mir_dataflow:: { Analysis , AnalysisDomain , Results } ;
1515use std:: fmt;
1616
1717use crate :: { places_conflict, BorrowSet , PlaceConflictBias , PlaceExt , RegionInferenceContext } ;
1818
19- /// A tuple with named fields that can hold either the results or the transient state of the
20- /// dataflow analyses used by the borrow checker.
21- #[ derive( Debug ) ]
22- pub struct BorrowckAnalyses < B , U , E > {
23- pub borrows : B ,
24- pub uninits : U ,
25- pub ever_inits : E ,
26- }
27-
2819/// The results of the dataflow analyses used by the borrow checker.
29- pub type BorrowckResults < ' mir , ' tcx > = BorrowckAnalyses <
30- Results < ' tcx , Borrows < ' mir , ' tcx > > ,
31- Results < ' tcx , MaybeUninitializedPlaces < ' mir , ' tcx > > ,
32- Results < ' tcx , EverInitializedPlaces < ' mir , ' tcx > > ,
33- > ;
20+ pub struct BorrowckResults < ' mir , ' tcx > {
21+ pub ( crate ) borrows : Results < ' tcx , Borrows < ' mir , ' tcx > > ,
22+ pub ( crate ) uninits : Results < ' tcx , MaybeUninitializedPlaces < ' mir , ' tcx > > ,
23+ pub ( crate ) ever_inits : Results < ' tcx , EverInitializedPlaces < ' mir , ' tcx > > ,
24+ }
3425
3526/// The transient state of the dataflow analyses used by the borrow checker.
36- pub type BorrowckFlowState < ' mir , ' tcx > =
37- <BorrowckResults < ' mir , ' tcx > as ResultsVisitable < ' tcx > >:: FlowState ;
38-
39- macro_rules! impl_visitable {
40- ( $(
41- $T: ident { $( $field: ident : $A: ident ) ,* $( , ) ? }
42- ) * ) => { $(
43- impl <' tcx, $( $A) ,* , D : Direction > ResultsVisitable <' tcx> for $T<$( Results <' tcx, $A> ) ,* >
44- where
45- $( $A: Analysis <' tcx, Direction = D >, ) *
46- {
47- type Direction = D ;
48- type FlowState = $T<$( $A:: Domain ) ,* >;
27+ #[ derive( Debug ) ]
28+ pub struct BorrowckFlowState < ' mir , ' tcx > {
29+ pub ( crate ) borrows : <Borrows < ' mir , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
30+ pub ( crate ) uninits : <MaybeUninitializedPlaces < ' mir , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
31+ pub ( crate ) ever_inits : <EverInitializedPlaces < ' mir , ' tcx > as AnalysisDomain < ' tcx > >:: Domain ,
32+ }
4933
50- fn new_flow_state( & self , body: & mir:: Body <' tcx>) -> Self :: FlowState {
51- $T {
52- $( $field: self . $field. analysis. bottom_value( body) ) ,*
53- }
54- }
34+ impl < ' mir , ' tcx > ResultsVisitable < ' tcx > for BorrowckResults < ' mir , ' tcx > {
35+ // All three analyses are forward, but we have to use just one here.
36+ type Direction = <Borrows < ' mir , ' tcx > as AnalysisDomain < ' tcx > >:: Direction ;
37+ type FlowState = BorrowckFlowState < ' mir , ' tcx > ;
5538
56- fn reset_to_block_entry (
57- & self ,
58- state : & mut Self :: FlowState ,
59- block : BasicBlock ,
60- ) {
61- $ ( state . $field . clone_from ( & self . $field . entry_set_for_block ( block ) ) ; ) *
62- }
39+ fn new_flow_state ( & self , body : & mir :: Body < ' tcx > ) -> Self :: FlowState {
40+ BorrowckFlowState {
41+ borrows : self . borrows . analysis . bottom_value ( body ) ,
42+ uninits : self . uninits . analysis . bottom_value ( body ) ,
43+ ever_inits : self . ever_inits . analysis . bottom_value ( body ) ,
44+ }
45+ }
6346
64- fn reconstruct_before_statement_effect(
65- & mut self ,
66- state: & mut Self :: FlowState ,
67- stmt: & mir:: Statement <' tcx>,
68- loc: Location ,
69- ) {
70- $( self . $field. analysis
71- . apply_before_statement_effect( & mut state. $field, stmt, loc) ; ) *
72- }
47+ fn reset_to_block_entry ( & self , state : & mut Self :: FlowState , block : BasicBlock ) {
48+ state. borrows . clone_from ( & self . borrows . entry_set_for_block ( block) ) ;
49+ state. uninits . clone_from ( & self . uninits . entry_set_for_block ( block) ) ;
50+ state. ever_inits . clone_from ( & self . ever_inits . entry_set_for_block ( block) ) ;
51+ }
7352
74- fn reconstruct_statement_effect(
75- & mut self ,
76- state: & mut Self :: FlowState ,
77- stmt: & mir:: Statement <' tcx>,
78- loc: Location ,
79- ) {
80- $( self . $field. analysis
81- . apply_statement_effect( & mut state. $field, stmt, loc) ; ) *
82- }
53+ fn reconstruct_before_statement_effect (
54+ & mut self ,
55+ state : & mut Self :: FlowState ,
56+ stmt : & mir:: Statement < ' tcx > ,
57+ loc : Location ,
58+ ) {
59+ self . borrows . analysis . apply_before_statement_effect ( & mut state. borrows , stmt, loc) ;
60+ self . uninits . analysis . apply_before_statement_effect ( & mut state. uninits , stmt, loc) ;
61+ self . ever_inits . analysis . apply_before_statement_effect ( & mut state. ever_inits , stmt, loc) ;
62+ }
8363
84- fn reconstruct_before_terminator_effect(
85- & mut self ,
86- state: & mut Self :: FlowState ,
87- term: & mir:: Terminator <' tcx>,
88- loc: Location ,
89- ) {
90- $( self . $field. analysis
91- . apply_before_terminator_effect( & mut state. $field, term, loc) ; ) *
92- }
64+ fn reconstruct_statement_effect (
65+ & mut self ,
66+ state : & mut Self :: FlowState ,
67+ stmt : & mir:: Statement < ' tcx > ,
68+ loc : Location ,
69+ ) {
70+ self . borrows . analysis . apply_statement_effect ( & mut state. borrows , stmt, loc) ;
71+ self . uninits . analysis . apply_statement_effect ( & mut state. uninits , stmt, loc) ;
72+ self . ever_inits . analysis . apply_statement_effect ( & mut state. ever_inits , stmt, loc) ;
73+ }
9374
94- fn reconstruct_terminator_effect(
95- & mut self ,
96- state: & mut Self :: FlowState ,
97- term: & mir:: Terminator <' tcx>,
98- loc: Location ,
99- ) {
100- $( self . $field. analysis
101- . apply_terminator_effect( & mut state. $field, term, loc) ; ) *
102- }
103- }
104- ) * }
105- }
75+ fn reconstruct_before_terminator_effect (
76+ & mut self ,
77+ state : & mut Self :: FlowState ,
78+ term : & mir:: Terminator < ' tcx > ,
79+ loc : Location ,
80+ ) {
81+ self . borrows . analysis . apply_before_terminator_effect ( & mut state. borrows , term, loc) ;
82+ self . uninits . analysis . apply_before_terminator_effect ( & mut state. uninits , term, loc) ;
83+ self . ever_inits . analysis . apply_before_terminator_effect ( & mut state. ever_inits , term, loc) ;
84+ }
10685
107- impl_visitable ! {
108- BorrowckAnalyses { borrows: B , uninits: U , ever_inits: E }
86+ fn reconstruct_terminator_effect (
87+ & mut self ,
88+ state : & mut Self :: FlowState ,
89+ term : & mir:: Terminator < ' tcx > ,
90+ loc : Location ,
91+ ) {
92+ self . borrows . analysis . apply_terminator_effect ( & mut state. borrows , term, loc) ;
93+ self . uninits . analysis . apply_terminator_effect ( & mut state. uninits , term, loc) ;
94+ self . ever_inits . analysis . apply_terminator_effect ( & mut state. ever_inits , term, loc) ;
95+ }
10996}
11097
11198rustc_index:: newtype_index! {
@@ -598,7 +585,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
598585
599586 fn before_terminator_effect (
600587 & mut self ,
601- trans : & mut impl GenKill < Self :: Idx > ,
588+ trans : & mut Self :: Domain ,
602589 _terminator : & mir:: Terminator < ' tcx > ,
603590 location : Location ,
604591 ) {
@@ -625,7 +612,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
625612
626613 fn call_return_effect (
627614 & mut self ,
628- _trans : & mut impl GenKill < Self :: Idx > ,
615+ _trans : & mut Self :: Domain ,
629616 _block : mir:: BasicBlock ,
630617 _return_places : CallReturnPlaces < ' _ , ' tcx > ,
631618 ) {
0 commit comments