1
- use rustc_middle:: mir:: visit:: { MutatingUseContext , PlaceContext , Visitor } ;
2
- use rustc_middle:: mir:: { Body , Local , Location , Place } ;
1
+ use rustc_middle:: mir:: Local ;
3
2
use rustc_middle:: ty:: GenericArg ;
4
- use rustc_mir_dataflow:: move_paths:: { LookupResult , MoveData , MovePathIndex } ;
5
3
use tracing:: debug;
6
4
7
- use super :: TypeChecker ;
8
- use crate :: def_use:: { self , DefUse } ;
9
- use crate :: location:: { LocationIndex , LocationTable } ;
10
-
11
- type VarPointRelation = Vec < ( Local , LocationIndex ) > ;
12
- type PathPointRelation = Vec < ( MovePathIndex , LocationIndex ) > ;
13
-
14
- /// Emit polonius facts for variable defs, uses, drops, and path accesses.
15
- pub ( super ) fn emit_access_facts < ' a , ' tcx > (
16
- typeck : & mut TypeChecker < ' a , ' tcx > ,
17
- body : & Body < ' tcx > ,
18
- move_data : & MoveData < ' tcx > ,
19
- ) {
20
- if let Some ( facts) = typeck. all_facts . as_mut ( ) {
21
- debug ! ( "emit_access_facts()" ) ;
22
-
23
- let _prof_timer = typeck. infcx . tcx . prof . generic_activity ( "polonius_fact_generation" ) ;
24
- let location_table = typeck. location_table ;
25
-
26
- let mut extractor = AccessFactsExtractor {
27
- var_defined_at : & mut facts. var_defined_at ,
28
- var_used_at : & mut facts. var_used_at ,
29
- var_dropped_at : & mut facts. var_dropped_at ,
30
- path_accessed_at_base : & mut facts. path_accessed_at_base ,
31
- location_table,
32
- move_data,
33
- } ;
34
- extractor. visit_body ( body) ;
35
-
36
- for ( local, local_decl) in body. local_decls . iter_enumerated ( ) {
37
- debug ! (
38
- "add use_of_var_derefs_origin facts - local={:?}, type={:?}" ,
39
- local, local_decl. ty
40
- ) ;
41
- let universal_regions = & typeck. universal_regions ;
42
- typeck. infcx . tcx . for_each_free_region ( & local_decl. ty , |region| {
43
- let region_vid = universal_regions. to_region_vid ( region) ;
44
- facts. use_of_var_derefs_origin . push ( ( local, region_vid. into ( ) ) ) ;
45
- } ) ;
46
- }
47
- }
48
- }
5
+ use crate :: type_check:: TypeChecker ;
49
6
50
7
/// For every potentially drop()-touched region `region` in `local`'s type
51
- /// (`kind`), emit a Polonius `use_of_var_derefs_origin (local, origin)` fact.
8
+ /// (`kind`), emit a Polonius `drop_of_var_derefs_origin (local, origin)` fact.
52
9
pub ( super ) fn emit_drop_facts < ' tcx > (
53
10
typeck : & mut TypeChecker < ' _ , ' tcx > ,
54
11
local : Local ,
@@ -64,60 +21,3 @@ pub(super) fn emit_drop_facts<'tcx>(
64
21
} ) ;
65
22
}
66
23
}
67
-
68
- /// MIR visitor extracting point-wise facts about accesses.
69
- struct AccessFactsExtractor < ' a , ' tcx > {
70
- var_defined_at : & ' a mut VarPointRelation ,
71
- var_used_at : & ' a mut VarPointRelation ,
72
- location_table : & ' a LocationTable ,
73
- var_dropped_at : & ' a mut VarPointRelation ,
74
- move_data : & ' a MoveData < ' tcx > ,
75
- path_accessed_at_base : & ' a mut PathPointRelation ,
76
- }
77
-
78
- impl < ' tcx > AccessFactsExtractor < ' _ , ' tcx > {
79
- fn location_to_index ( & self , location : Location ) -> LocationIndex {
80
- self . location_table . mid_index ( location)
81
- }
82
- }
83
-
84
- impl < ' a , ' tcx > Visitor < ' tcx > for AccessFactsExtractor < ' a , ' tcx > {
85
- fn visit_local ( & mut self , local : Local , context : PlaceContext , location : Location ) {
86
- match def_use:: categorize ( context) {
87
- Some ( DefUse :: Def ) => {
88
- debug ! ( "AccessFactsExtractor - emit def" ) ;
89
- self . var_defined_at . push ( ( local, self . location_to_index ( location) ) ) ;
90
- }
91
- Some ( DefUse :: Use ) => {
92
- debug ! ( "AccessFactsExtractor - emit use" ) ;
93
- self . var_used_at . push ( ( local, self . location_to_index ( location) ) ) ;
94
- }
95
- Some ( DefUse :: Drop ) => {
96
- debug ! ( "AccessFactsExtractor - emit drop" ) ;
97
- self . var_dropped_at . push ( ( local, self . location_to_index ( location) ) ) ;
98
- }
99
- _ => ( ) ,
100
- }
101
- }
102
-
103
- fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , location : Location ) {
104
- self . super_place ( place, context, location) ;
105
-
106
- match context {
107
- PlaceContext :: NonMutatingUse ( _)
108
- | PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow ) => {
109
- let path = match self . move_data . rev_lookup . find ( place. as_ref ( ) ) {
110
- LookupResult :: Exact ( path) | LookupResult :: Parent ( Some ( path) ) => path,
111
- _ => {
112
- // There's no path access to emit.
113
- return ;
114
- }
115
- } ;
116
- debug ! ( "AccessFactsExtractor - emit path access ({path:?}, {location:?})" ) ;
117
- self . path_accessed_at_base . push ( ( path, self . location_to_index ( location) ) ) ;
118
- }
119
-
120
- _ => { }
121
- }
122
- }
123
- }
0 commit comments