11use rustc_middle:: mir:: visit:: { MutatingUseContext , PlaceContext , Visitor } ;
22use rustc_middle:: mir:: { Body , Local , Location , Place } ;
33use rustc_middle:: ty:: TyCtxt ;
4- use rustc_mir_dataflow:: move_paths:: { LookupResult , MoveData , MovePathIndex } ;
4+ use rustc_mir_dataflow:: move_paths:: { LookupResult , MoveData } ;
55use tracing:: debug;
66
77use crate :: def_use:: { self , DefUse } ;
88use crate :: facts:: AllFacts ;
99use crate :: location:: { LocationIndex , LocationTable } ;
1010use crate :: universal_regions:: UniversalRegions ;
1111
12- type VarPointRelation = Vec < ( Local , LocationIndex ) > ;
13- type PathPointRelation = Vec < ( MovePathIndex , LocationIndex ) > ;
14-
1512/// Emit polonius facts for variable defs, uses, drops, and path accesses.
1613pub ( crate ) fn emit_access_facts < ' tcx > (
14+ facts : & mut AllFacts ,
1715 tcx : TyCtxt < ' tcx > ,
1816 body : & Body < ' tcx > ,
1917 move_data : & MoveData < ' tcx > ,
2018 universal_regions : & UniversalRegions < ' tcx > ,
2119 location_table : & LocationTable ,
22- all_facts : & mut Option < AllFacts > ,
2320) {
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 } ;
3422 extractor. visit_body ( body) ;
3523
3624 for ( local, local_decl) in body. local_decls . iter_enumerated ( ) {
@@ -44,12 +32,9 @@ pub(crate) fn emit_access_facts<'tcx>(
4432
4533/// MIR visitor extracting point-wise facts about accesses.
4634struct 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 ,
5136 move_data : & ' a MoveData < ' tcx > ,
52- path_accessed_at_base : & ' a mut PathPointRelation ,
37+ location_table : & ' a LocationTable ,
5338}
5439
5540impl < ' tcx > AccessFactsExtractor < ' _ , ' tcx > {
@@ -63,15 +48,15 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
6348 match def_use:: categorize ( context) {
6449 Some ( DefUse :: Def ) => {
6550 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) ) ) ;
6752 }
6853 Some ( DefUse :: Use ) => {
6954 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) ) ) ;
7156 }
7257 Some ( DefUse :: Drop ) => {
7358 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) ) ) ;
7560 }
7661 _ => ( ) ,
7762 }
@@ -91,7 +76,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AccessFactsExtractor<'a, 'tcx> {
9176 }
9277 } ;
9378 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) ) ) ;
9580 }
9681
9782 _ => { }
0 commit comments