Skip to content

Commit aa481bd

Browse files
committed
LivenessValues does not need to be generic over regions
1 parent 30e8406 commit aa481bd

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

Diff for: compiler/rustc_borrowck/src/constraint_generation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::mir::{
99
};
1010
use rustc_middle::ty::visit::TypeVisitable;
1111
use rustc_middle::ty::GenericArgsRef;
12-
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, Ty, TyCtxt};
1313

1414
use crate::{
1515
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict,
@@ -18,7 +18,7 @@ use crate::{
1818

1919
pub(super) fn generate_constraints<'tcx>(
2020
infcx: &InferCtxt<'tcx>,
21-
liveness_constraints: &mut LivenessValues<RegionVid>,
21+
liveness_constraints: &mut LivenessValues,
2222
all_facts: &mut Option<AllFacts>,
2323
location_table: &LocationTable,
2424
body: &Body<'tcx>,
@@ -43,7 +43,7 @@ struct ConstraintGeneration<'cg, 'tcx> {
4343
infcx: &'cg InferCtxt<'tcx>,
4444
all_facts: &'cg mut Option<AllFacts>,
4545
location_table: &'cg LocationTable,
46-
liveness_constraints: &'cg mut LivenessValues<RegionVid>,
46+
liveness_constraints: &'cg mut LivenessValues,
4747
borrow_set: &'cg BorrowSet<'tcx>,
4848
body: &'cg Body<'tcx>,
4949
}

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct RegionInferenceContext<'tcx> {
5959
/// regions, these start out empty and steadily grow, though for
6060
/// each universally quantified region R they start out containing
6161
/// the entire CFG and `end(R)`.
62-
liveness_constraints: LivenessValues<RegionVid>,
62+
liveness_constraints: LivenessValues,
6363

6464
/// The outlives constraints computed by the type-check.
6565
constraints: Frozen<OutlivesConstraintSet<'tcx>>,
@@ -332,7 +332,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
332332
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
333333
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
334334
type_tests: Vec<TypeTest<'tcx>>,
335-
liveness_constraints: LivenessValues<RegionVid>,
335+
liveness_constraints: LivenessValues,
336336
elements: &Rc<RegionValueElements>,
337337
live_loans: SparseBitMatrix<PointIndex, BorrowIndex>,
338338
) -> Self {

Diff for: compiler/rustc_borrowck/src/region_infer/values.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -118,53 +118,53 @@ pub(crate) enum RegionElement {
118118

119119
/// Records the CFG locations where each region is live. When we initially compute liveness, we use
120120
/// an interval matrix storing liveness ranges for each region-vid.
121-
pub(crate) struct LivenessValues<N: Idx> {
121+
pub(crate) struct LivenessValues {
122122
elements: Rc<RegionValueElements>,
123-
points: SparseIntervalMatrix<N, PointIndex>,
123+
points: SparseIntervalMatrix<RegionVid, PointIndex>,
124124
}
125125

126-
impl<N: Idx> LivenessValues<N> {
126+
impl LivenessValues {
127127
/// Create an empty map of regions to locations where they're live.
128128
pub(crate) fn new(elements: Rc<RegionValueElements>) -> Self {
129129
Self { points: SparseIntervalMatrix::new(elements.num_points), elements }
130130
}
131131

132132
/// Iterate through each region that has a value in this set.
133-
pub(crate) fn regions(&self) -> impl Iterator<Item = N> {
133+
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> {
134134
self.points.rows()
135135
}
136136

137137
/// Records `region` as being live at the given `location`.
138-
pub(crate) fn add_location(&mut self, region: N, location: Location) {
138+
pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) {
139139
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
140140
let point = self.elements.point_from_location(location);
141141
self.points.insert(region, point);
142142
}
143143

144144
/// Records `region` as being live at all the given `points`.
145-
pub(crate) fn add_points(&mut self, region: N, points: &IntervalSet<PointIndex>) {
145+
pub(crate) fn add_points(&mut self, region: RegionVid, points: &IntervalSet<PointIndex>) {
146146
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
147147
self.points.union_row(region, points);
148148
}
149149

150150
/// Records `region` as being live at all the control-flow points.
151-
pub(crate) fn add_all_points(&mut self, region: N) {
151+
pub(crate) fn add_all_points(&mut self, region: RegionVid) {
152152
self.points.insert_all_into_row(region);
153153
}
154154

155155
/// Returns whether `region` is marked live at the given `location`.
156-
pub(crate) fn is_live_at(&self, region: N, location: Location) -> bool {
156+
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
157157
let point = self.elements.point_from_location(location);
158158
self.points.row(region).is_some_and(|r| r.contains(point))
159159
}
160160

161161
/// Returns whether `region` is marked live at any location.
162-
pub(crate) fn is_live_anywhere(&self, region: N) -> bool {
162+
pub(crate) fn is_live_anywhere(&self, region: RegionVid) -> bool {
163163
self.live_points(region).next().is_some()
164164
}
165165

166166
/// Returns an iterator of all the points where `region` is live.
167-
fn live_points(&self, region: N) -> impl Iterator<Item = PointIndex> + '_ {
167+
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> + '_ {
168168
self.points
169169
.row(region)
170170
.into_iter()
@@ -173,7 +173,7 @@ impl<N: Idx> LivenessValues<N> {
173173
}
174174

175175
/// Returns a "pretty" string value of the region. Meant for debugging.
176-
pub(crate) fn region_value_str(&self, region: N) -> String {
176+
pub(crate) fn region_value_str(&self, region: RegionVid) -> String {
177177
region_value_str(
178178
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
179179
)
@@ -309,7 +309,7 @@ impl<N: Idx> RegionValues<N> {
309309
/// `self[to] |= values[from]`, essentially: that is, take all the
310310
/// elements for the region `from` from `values` and add them to
311311
/// the region `to` in `self`.
312-
pub(crate) fn merge_liveness<M: Idx>(&mut self, to: N, from: M, values: &LivenessValues<M>) {
312+
pub(crate) fn merge_liveness(&mut self, to: N, from: RegionVid, values: &LivenessValues) {
313313
if let Some(set) = values.points.row(from) {
314314
self.points.union_row(to, set);
315315
}

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> {
899899
/// not otherwise appear in the MIR -- in particular, the
900900
/// late-bound regions that it instantiates at call-sites -- and
901901
/// hence it must report on their liveness constraints.
902-
pub(crate) liveness_constraints: LivenessValues<RegionVid>,
902+
pub(crate) liveness_constraints: LivenessValues,
903903

904904
pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,
905905

0 commit comments

Comments
 (0)