Skip to content

Commit e0481d1

Browse files
committed
add polonius activities to -Z self-profile
- "polonius_fact_generation" is dedicated to profiling the Polonius fact generation, from the MIR and NLL constraints - "polonius_analysis" is dedicated to profiling the duration of the Polonius computations themselves: move/init analysis, liveness, borrowck-ing
1 parent 72579c9 commit e0481d1

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

src/librustc_mir/borrow_check/nll/constraint_generation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
9797
location: Location,
9898
) {
9999
if let Some(all_facts) = self.all_facts {
100+
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
100101
all_facts.cfg_edge.push((
101102
self.location_table.start_index(location),
102103
self.location_table.mid_index(location),
@@ -142,6 +143,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
142143
location: Location,
143144
) {
144145
if let Some(all_facts) = self.all_facts {
146+
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
145147
all_facts.cfg_edge.push((
146148
self.location_table.start_index(location),
147149
self.location_table.mid_index(location),
@@ -205,6 +207,8 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
205207
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
206208
fn record_killed_borrows_for_place(&mut self, place: &Place<'tcx>, location: Location) {
207209
if let Some(all_facts) = self.all_facts {
210+
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
211+
208212
// Depending on the `Place` we're killing:
209213
// - if it's a local, or a single deref of a local,
210214
// we kill all the borrows on the local.

src/librustc_mir/borrow_check/nll/invalidation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(super) fn generate_invalidates<'tcx>(
3131
}
3232

3333
if let Some(all_facts) = all_facts {
34+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
3435
let dominators = body.dominators();
3536
let mut ig = InvalidationGenerator {
3637
all_facts,

src/librustc_mir/borrow_check/nll/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
201201
);
202202

203203
if let Some(all_facts) = &mut all_facts {
204+
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
204205
all_facts
205206
.universal_region
206207
.extend(universal_regions.universal_regions());
@@ -302,6 +303,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
302303
.unwrap_or_else(|_| String::from("Naive"));
303304
let algorithm = Algorithm::from_str(&algorithm).unwrap();
304305
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
306+
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");
305307
Some(Rc::new(Output::compute(
306308
&all_facts,
307309
algorithm,

src/librustc_mir/borrow_check/nll/type_check/liveness/polonius.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub(super) fn populate_access_facts(
109109

110110
for (local, local_decl) in body.local_decls.iter_enumerated() {
111111
debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty);
112+
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
112113
let universal_regions = &typeck.borrowck_context.universal_regions;
113114
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
114115
let region_vid = universal_regions.to_region_vid(region);
@@ -127,6 +128,7 @@ pub(super) fn add_var_drops_regions(
127128
) {
128129
debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind);
129130
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
131+
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
130132
let universal_regions = &typeck.borrowck_context.universal_regions;
131133
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
132134
let region_vid = universal_regions.to_region_vid(drop_live_region);

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub(crate) fn type_check<'tcx>(
182182
move_data,
183183
location_table);
184184

185-
translate_outlives_facts(cx.borrowck_context);
185+
translate_outlives_facts(&mut cx);
186186
},
187187
);
188188

@@ -228,8 +228,10 @@ fn type_check_internal<'a, 'tcx, R>(
228228
extra(&mut checker)
229229
}
230230

231-
fn translate_outlives_facts(cx: &mut BorrowCheckContext<'_, '_>) {
231+
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
232+
let cx = &mut typeck.borrowck_context;
232233
if let Some(facts) = cx.all_facts {
234+
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
233235
let location_table = cx.location_table;
234236
facts
235237
.outlives
@@ -2489,6 +2491,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24892491
// that occurs when we are borrowing an unsafe place, for
24902492
// example).
24912493
if let Some(all_facts) = all_facts {
2494+
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
24922495
if let Some(borrow_index) = borrow_set.location_map.get(&location) {
24932496
let region_vid = borrow_region.to_region_vid();
24942497
all_facts.borrow_region.push((

0 commit comments

Comments
 (0)