Skip to content

Commit 1bea7f9

Browse files
committed
record variance of regular live regions
1 parent d1cadf6 commit 1bea7f9

File tree

1 file changed

+21
-3
lines changed
  • compiler/rustc_borrowck/src/type_check/liveness

1 file changed

+21
-3
lines changed

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_data_structures::fx::FxHashSet;
33
use rustc_middle::mir::visit::{TyContext, Visitor};
44
use rustc_middle::mir::{Body, Local, Location, SourceInfo};
55
use rustc_middle::span_bug;
6+
use rustc_middle::ty::relate::Relate;
67
use rustc_middle::ty::visit::TypeVisitable;
78
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
89
use rustc_mir_dataflow::ResultsCursor;
@@ -13,6 +14,7 @@ use tracing::debug;
1314

1415
use super::TypeChecker;
1516
use crate::constraints::OutlivesConstraintSet;
17+
use crate::polonius::PoloniusContext;
1618
use crate::region_infer::values::LivenessValues;
1719
use crate::universal_regions::UniversalRegions;
1820

@@ -56,7 +58,13 @@ pub(super) fn generate<'a, 'tcx>(
5658

5759
// Mark regions that should be live where they appear within rvalues or within a call: like
5860
// args, regions, and types.
59-
record_regular_live_regions(typeck.tcx(), &mut typeck.constraints.liveness_constraints, body);
61+
record_regular_live_regions(
62+
typeck.tcx(),
63+
&mut typeck.constraints.liveness_constraints,
64+
&typeck.universal_regions,
65+
&mut typeck.polonius_context,
66+
body,
67+
);
6068
}
6169

6270
// The purpose of `compute_relevant_live_locals` is to define the subset of `Local`
@@ -130,9 +138,12 @@ fn regions_that_outlive_free_regions<'tcx>(
130138
fn record_regular_live_regions<'tcx>(
131139
tcx: TyCtxt<'tcx>,
132140
liveness_constraints: &mut LivenessValues,
141+
universal_regions: &UniversalRegions<'tcx>,
142+
polonius_context: &mut Option<PoloniusContext>,
133143
body: &Body<'tcx>,
134144
) {
135-
let mut visitor = LiveVariablesVisitor { tcx, liveness_constraints };
145+
let mut visitor =
146+
LiveVariablesVisitor { tcx, liveness_constraints, universal_regions, polonius_context };
136147
for (bb, data) in body.basic_blocks.iter_enumerated() {
137148
visitor.visit_basic_block_data(bb, data);
138149
}
@@ -142,6 +153,8 @@ fn record_regular_live_regions<'tcx>(
142153
struct LiveVariablesVisitor<'a, 'tcx> {
143154
tcx: TyCtxt<'tcx>,
144155
liveness_constraints: &'a mut LivenessValues,
156+
universal_regions: &'a UniversalRegions<'tcx>,
157+
polonius_context: &'a mut Option<PoloniusContext>,
145158
}
146159

147160
impl<'a, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'a, 'tcx> {
@@ -184,12 +197,17 @@ impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {
184197
/// all regions appearing in the type of `value` must be live at `location`.
185198
fn record_regions_live_at<T>(&mut self, value: T, location: Location)
186199
where
187-
T: TypeVisitable<TyCtxt<'tcx>>,
200+
T: TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
188201
{
189202
debug!("record_regions_live_at(value={:?}, location={:?})", value, location);
190203
self.tcx.for_each_free_region(&value, |live_region| {
191204
let live_region_vid = live_region.as_var();
192205
self.liveness_constraints.add_location(live_region_vid, location);
193206
});
207+
208+
// When using `-Zpolonius=next`, we record the variance of each live region.
209+
if let Some(polonius_context) = self.polonius_context {
210+
polonius_context.record_live_region_variance(self.tcx, self.universal_regions, value);
211+
}
194212
}
195213
}

0 commit comments

Comments
 (0)