1
1
use crate :: borrow_check:: location:: { LocationIndex , LocationTable } ;
2
+ use crate :: dataflow:: indexes:: MovePathIndex ;
3
+ use crate :: dataflow:: move_paths:: { LookupResult , MoveData } ;
2
4
use crate :: util:: liveness:: { categorize, DefUse } ;
3
- use rustc:: mir:: visit:: { PlaceContext , Visitor } ;
4
- use rustc:: mir:: { Body , Local , Location } ;
5
+ use rustc:: mir:: visit:: { MutatingUseContext , PlaceContext , Visitor } ;
6
+ use rustc:: mir:: { Body , Local , Location , Place } ;
5
7
use rustc:: ty:: subst:: Kind ;
6
8
use rustc:: ty:: Ty ;
7
9
8
10
use super :: TypeChecker ;
9
11
10
12
type VarPointRelations = Vec < ( Local , LocationIndex ) > ;
13
+ type MovePathPointRelations = Vec < ( MovePathIndex , LocationIndex ) > ;
11
14
12
- struct LivenessPointFactsExtractor < ' me > {
15
+ struct UseFactsExtractor < ' me > {
13
16
var_defined : & ' me mut VarPointRelations ,
14
17
var_used : & ' me mut VarPointRelations ,
15
18
location_table : & ' me LocationTable ,
19
+ var_drop_used : & ' me mut VarPointRelations ,
20
+ move_data : & ' me MoveData < ' me > ,
21
+ path_accessed_at : & ' me mut MovePathPointRelations ,
16
22
}
17
23
18
24
// A Visitor to walk through the MIR and extract point-wise facts
19
- impl LivenessPointFactsExtractor < ' _ > {
25
+ impl UseFactsExtractor < ' _ > {
20
26
fn location_to_index ( & self , location : Location ) -> LocationIndex {
21
27
self . location_table . mid_index ( location)
22
28
}
@@ -30,15 +36,50 @@ impl LivenessPointFactsExtractor<'_> {
30
36
debug ! ( "LivenessFactsExtractor::insert_use()" ) ;
31
37
self . var_used . push ( ( local, self . location_to_index ( location) ) ) ;
32
38
}
39
+
40
+ fn insert_drop_use ( & mut self , local : Local , location : Location ) {
41
+ debug ! ( "LivenessFactsExtractor::insert_drop_use()" ) ;
42
+ self . var_drop_used . push ( ( local, self . location_to_index ( location) ) ) ;
43
+ }
44
+
45
+ fn insert_path_access ( & mut self , path : MovePathIndex , location : Location ) {
46
+ debug ! ( "LivenessFactsExtractor::insert_path_access({:?}, {:?})" , path, location) ;
47
+ self . path_accessed_at . push ( ( path, self . location_to_index ( location) ) ) ;
48
+ }
49
+
50
+ fn place_to_mpi ( & self , place : & Place < ' _ > ) -> Option < MovePathIndex > {
51
+ match self . move_data . rev_lookup . find ( place. as_ref ( ) ) {
52
+ LookupResult :: Exact ( mpi) => Some ( mpi) ,
53
+ LookupResult :: Parent ( mmpi) => mmpi,
54
+ }
55
+ }
33
56
}
34
57
35
- impl Visitor < ' tcx > for LivenessPointFactsExtractor < ' _ > {
58
+ impl Visitor < ' tcx > for UseFactsExtractor < ' _ > {
36
59
fn visit_local ( & mut self , & local: & Local , context : PlaceContext , location : Location ) {
37
60
match categorize ( context) {
38
61
Some ( DefUse :: Def ) => self . insert_def ( local, location) ,
39
62
Some ( DefUse :: Use ) => self . insert_use ( local, location) ,
63
+ Some ( DefUse :: Drop ) => self . insert_drop_use ( local, location) ,
64
+ _ => ( ) ,
65
+ }
66
+ }
67
+
68
+ fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , location : Location ) {
69
+ self . super_place ( place, context, location) ;
70
+ match context {
71
+ PlaceContext :: NonMutatingUse ( _) => {
72
+ if let Some ( mpi) = self . place_to_mpi ( place) {
73
+ self . insert_path_access ( mpi, location) ;
74
+ }
75
+ }
76
+
77
+ PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow ) => {
78
+ if let Some ( mpi) = self . place_to_mpi ( place) {
79
+ self . insert_path_access ( mpi, location) ;
80
+ }
81
+ }
40
82
_ => ( ) ,
41
- // NOTE: Drop handling is now done in trace()
42
83
}
43
84
}
44
85
}
@@ -54,23 +95,27 @@ fn add_var_uses_regions(typeck: &mut TypeChecker<'_, 'tcx>, local: Local, ty: Ty
54
95
} ) ;
55
96
}
56
97
57
- pub ( super ) fn populate_var_liveness_facts (
98
+ pub ( super ) fn populate_access_facts (
58
99
typeck : & mut TypeChecker < ' _ , ' tcx > ,
59
- mir : & Body < ' tcx > ,
100
+ body : & Body < ' tcx > ,
60
101
location_table : & LocationTable ,
102
+ move_data : & MoveData < ' _ > ,
61
103
) {
62
104
debug ! ( "populate_var_liveness_facts()" ) ;
63
105
64
106
if let Some ( facts) = typeck. borrowck_context . all_facts . as_mut ( ) {
65
- LivenessPointFactsExtractor {
107
+ UseFactsExtractor {
66
108
var_defined : & mut facts. var_defined ,
67
109
var_used : & mut facts. var_used ,
110
+ var_drop_used : & mut facts. var_drop_used ,
111
+ path_accessed_at : & mut facts. path_accessed_at ,
68
112
location_table,
113
+ move_data,
69
114
}
70
- . visit_body ( mir ) ;
115
+ . visit_body ( body ) ;
71
116
}
72
117
73
- for ( local, local_decl) in mir . local_decls . iter_enumerated ( ) {
118
+ for ( local, local_decl) in body . local_decls . iter_enumerated ( ) {
74
119
add_var_uses_regions ( typeck, local, local_decl. ty ) ;
75
120
}
76
121
}
0 commit comments