1
1
use rustc_middle:: mir:: visit:: { MutatingUseContext , PlaceContext , Visitor } ;
2
2
use rustc_middle:: mir:: { Body , Local , Location , Place } ;
3
3
use rustc_middle:: ty:: TyCtxt ;
4
- use rustc_mir_dataflow:: move_paths:: { LookupResult , MoveData , MovePathIndex } ;
4
+ use rustc_mir_dataflow:: move_paths:: { LookupResult , MoveData } ;
5
5
use tracing:: debug;
6
6
7
7
use crate :: def_use:: { self , DefUse } ;
8
8
use crate :: facts:: AllFacts ;
9
9
use crate :: location:: { LocationIndex , LocationTable } ;
10
10
use crate :: universal_regions:: UniversalRegions ;
11
11
12
- type VarPointRelation = Vec < ( Local , LocationIndex ) > ;
13
- type PathPointRelation = Vec < ( MovePathIndex , LocationIndex ) > ;
14
-
15
12
/// Emit polonius facts for variable defs, uses, drops, and path accesses.
16
13
pub ( crate ) fn emit_access_facts < ' tcx > (
14
+ facts : & mut AllFacts ,
17
15
tcx : TyCtxt < ' tcx > ,
18
16
body : & Body < ' tcx > ,
19
17
move_data : & MoveData < ' tcx > ,
20
18
universal_regions : & UniversalRegions < ' tcx > ,
21
19
location_table : & LocationTable ,
22
- all_facts : & mut Option < AllFacts > ,
23
20
) {
24
- let Some ( facts) = all_facts. as_mut ( ) else { return } ;
25
- let _prof_timer = tcx. prof . generic_activity ( "polonius_fact_generation" ) ;
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
- } ;
21
+ let mut extractor = AccessFactsExtractor { facts, move_data, location_table } ;
34
22
extractor. visit_body ( body) ;
35
23
36
24
for ( local, local_decl) in body. local_decls . iter_enumerated ( ) {
@@ -44,12 +32,9 @@ pub(crate) fn emit_access_facts<'tcx>(
44
32
45
33
/// MIR visitor extracting point-wise facts about accesses.
46
34
struct AccessFactsExtractor < ' a , ' tcx > {
47
- var_defined_at : & ' a mut VarPointRelation ,
48
- var_used_at : & ' a mut VarPointRelation ,
49
- location_table : & ' a LocationTable ,
50
- var_dropped_at : & ' a mut VarPointRelation ,
35
+ facts : & ' a mut AllFacts ,
51
36
move_data : & ' a MoveData < ' tcx > ,
52
- path_accessed_at_base : & ' a mut PathPointRelation ,
37
+ location_table : & ' a LocationTable ,
53
38
}
54
39
55
40
impl < ' tcx > AccessFactsExtractor < ' _ , ' tcx > {
@@ -63,15 +48,15 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
63
48
match def_use:: categorize ( context) {
64
49
Some ( DefUse :: Def ) => {
65
50
debug ! ( "AccessFactsExtractor - emit def" ) ;
66
- self . var_defined_at . push ( ( local, self . location_to_index ( location) ) ) ;
51
+ self . facts . var_defined_at . push ( ( local, self . location_to_index ( location) ) ) ;
67
52
}
68
53
Some ( DefUse :: Use ) => {
69
54
debug ! ( "AccessFactsExtractor - emit use" ) ;
70
- self . var_used_at . push ( ( local, self . location_to_index ( location) ) ) ;
55
+ self . facts . var_used_at . push ( ( local, self . location_to_index ( location) ) ) ;
71
56
}
72
57
Some ( DefUse :: Drop ) => {
73
58
debug ! ( "AccessFactsExtractor - emit drop" ) ;
74
- self . var_dropped_at . push ( ( local, self . location_to_index ( location) ) ) ;
59
+ self . facts . var_dropped_at . push ( ( local, self . location_to_index ( location) ) ) ;
75
60
}
76
61
_ => ( ) ,
77
62
}
@@ -91,7 +76,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
91
76
}
92
77
} ;
93
78
debug ! ( "AccessFactsExtractor - emit path access ({path:?}, {location:?})" ) ;
94
- self . path_accessed_at_base . push ( ( path, self . location_to_index ( location) ) ) ;
79
+ self . facts . path_accessed_at_base . push ( ( path, self . location_to_index ( location) ) ) ;
95
80
}
96
81
97
82
_ => { }
0 commit comments