3
3
use rustc_middle:: mir:: visit:: Visitor ;
4
4
use rustc_middle:: mir:: {
5
5
Body , Local , Location , Place , PlaceRef , ProjectionElem , Rvalue , Statement , StatementKind ,
6
- Terminator , TerminatorKind , UserTypeProjection ,
6
+ Terminator , TerminatorKind ,
7
7
} ;
8
- use rustc_middle:: ty:: { TyCtxt , Variance } ;
8
+ use rustc_middle:: ty:: TyCtxt ;
9
9
10
10
use crate :: { borrow_set:: BorrowSet , facts:: AllFacts , location:: LocationTable , places_conflict} ;
11
11
12
- pub ( super ) fn generate_constraints < ' tcx > (
12
+ /// Emit `loan_killed_at` and `cfg_edge` facts at the same time.
13
+ pub ( super ) fn emit_loan_kills < ' tcx > (
13
14
tcx : TyCtxt < ' tcx > ,
14
15
all_facts : & mut AllFacts ,
15
16
location_table : & LocationTable ,
16
17
body : & Body < ' tcx > ,
17
18
borrow_set : & BorrowSet < ' tcx > ,
18
19
) {
19
20
let _prof_timer = tcx. prof . generic_activity ( "polonius_fact_generation" ) ;
20
- let mut cg = ConstraintGeneration { borrow_set, tcx, location_table, all_facts, body } ;
21
+ let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, all_facts, body } ;
21
22
for ( bb, data) in body. basic_blocks . iter_enumerated ( ) {
22
- cg . visit_basic_block_data ( bb, data) ;
23
+ visitor . visit_basic_block_data ( bb, data) ;
23
24
}
24
25
}
25
26
26
- /// 'cg = the duration of the constraint generation process itself.
27
- struct ConstraintGeneration < ' cg , ' tcx > {
27
+ struct LoanKillsGenerator < ' cx , ' tcx > {
28
28
tcx : TyCtxt < ' tcx > ,
29
- all_facts : & ' cg mut AllFacts ,
30
- location_table : & ' cg LocationTable ,
31
- borrow_set : & ' cg BorrowSet < ' tcx > ,
32
- body : & ' cg Body < ' tcx > ,
29
+ all_facts : & ' cx mut AllFacts ,
30
+ location_table : & ' cx LocationTable ,
31
+ borrow_set : & ' cx BorrowSet < ' tcx > ,
32
+ body : & ' cx Body < ' tcx > ,
33
33
}
34
34
35
- impl < ' cg , ' tcx > Visitor < ' tcx > for ConstraintGeneration < ' cg , ' tcx > {
35
+ impl < ' cx , ' tcx > Visitor < ' tcx > for LoanKillsGenerator < ' cx , ' tcx > {
36
36
fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
37
+ // Also record CFG facts here.
37
38
self . all_facts . cfg_edge . push ( (
38
39
self . location_table . start_index ( location) ,
39
40
self . location_table . mid_index ( location) ,
@@ -56,11 +57,11 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
56
57
// When we see `X = ...`, then kill borrows of
57
58
// `(*X).foo` and so forth.
58
59
self . record_killed_borrows_for_place ( * place, location) ;
59
-
60
60
self . super_assign ( place, rvalue, location) ;
61
61
}
62
62
63
63
fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
64
+ // Also record CFG facts here.
64
65
self . all_facts . cfg_edge . push ( (
65
66
self . location_table . start_index ( location) ,
66
67
self . location_table . mid_index ( location) ,
@@ -83,20 +84,11 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
83
84
84
85
self . super_terminator ( terminator, location) ;
85
86
}
86
-
87
- fn visit_ascribe_user_ty (
88
- & mut self ,
89
- _place : & Place < ' tcx > ,
90
- _variance : Variance ,
91
- _user_ty : & UserTypeProjection ,
92
- _location : Location ,
93
- ) {
94
- }
95
87
}
96
88
97
- impl < ' cx , ' tcx > ConstraintGeneration < ' cx , ' tcx > {
98
- /// When recording facts for Polonius, records the borrows on the specified place
99
- /// as `killed`. For example, when assigning to a local, or on a call's return destination.
89
+ impl < ' tcx > LoanKillsGenerator < ' _ , ' tcx > {
90
+ /// Records the borrows on the specified place as `killed`. For example, when assigning to a
91
+ /// local, or on a call's return destination.
100
92
fn record_killed_borrows_for_place ( & mut self , place : Place < ' tcx > , location : Location ) {
101
93
// Depending on the `Place` we're killing:
102
94
// - if it's a local, or a single deref of a local,
@@ -143,7 +135,7 @@ impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
143
135
}
144
136
}
145
137
146
- /// When recording facts for Polonius, records the borrows on the specified local as `killed`.
138
+ /// Records the borrows on the specified local as `killed`.
147
139
fn record_killed_borrows_for_local ( & mut self , local : Local , location : Location ) {
148
140
if let Some ( borrow_indices) = self . borrow_set . local_map . get ( & local) {
149
141
let location_index = self . location_table . mid_index ( location) ;
0 commit comments