Skip to content

Commit 6f1c417

Browse files
committed
stop calling DenseLocationMap "elements"
"Elements" are `RegionElement`s. The dense location mapping was removed from the element containers a while ago but didn't rename its use-sites. Most of the old naming only used the mapping, and are better named `location_map`.
1 parent 9c87288 commit 6f1c417

File tree

7 files changed

+65
-61
lines changed

7 files changed

+65
-61
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
9494
let mut all_facts =
9595
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
9696

97-
let elements = Rc::new(DenseLocationMap::new(body));
97+
let location_map = Rc::new(DenseLocationMap::new(body));
9898

9999
// Run the MIR type-checker.
100100
let MirTypeckResults {
@@ -112,7 +112,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
112112
&mut all_facts,
113113
flow_inits,
114114
move_data,
115-
Rc::clone(&elements),
115+
Rc::clone(&location_map),
116116
);
117117

118118
// Create the region inference context, taking ownership of the
@@ -137,7 +137,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
137137
var_infos,
138138
constraints,
139139
universal_region_relations,
140-
elements,
140+
location_map,
141141
);
142142

143143
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
396396
var_infos: VarInfos,
397397
constraints: MirTypeckRegionConstraints<'tcx>,
398398
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
399-
elements: Rc<DenseLocationMap>,
399+
location_map: Rc<DenseLocationMap>,
400400
) -> Self {
401401
let universal_regions = &universal_region_relations.universal_regions;
402402
let MirTypeckRegionConstraints {
@@ -440,7 +440,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
440440
}
441441

442442
let mut scc_values =
443-
RegionValues::new(elements, universal_regions.len(), placeholder_indices);
443+
RegionValues::new(location_map, universal_regions.len(), placeholder_indices);
444444

445445
for region in liveness_constraints.regions() {
446446
let scc = constraint_sccs.scc(region);

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

+27-26
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) enum RegionElement {
3838
/// an interval matrix storing liveness ranges for each region-vid.
3939
pub(crate) struct LivenessValues {
4040
/// The map from locations to points.
41-
elements: Rc<DenseLocationMap>,
41+
location_map: Rc<DenseLocationMap>,
4242

4343
/// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and
4444
/// currently only used for validating promoteds (which don't care about more precise tracking).
@@ -77,11 +77,11 @@ impl LiveLoans {
7777

7878
impl LivenessValues {
7979
/// Create an empty map of regions to locations where they're live.
80-
pub(crate) fn with_specific_points(elements: Rc<DenseLocationMap>) -> Self {
80+
pub(crate) fn with_specific_points(location_map: Rc<DenseLocationMap>) -> Self {
8181
LivenessValues {
8282
live_regions: None,
83-
points: Some(SparseIntervalMatrix::new(elements.num_points())),
84-
elements,
83+
points: Some(SparseIntervalMatrix::new(location_map.num_points())),
84+
location_map,
8585
loans: None,
8686
}
8787
}
@@ -90,11 +90,11 @@ impl LivenessValues {
9090
///
9191
/// Unlike `with_specific_points`, does not track exact locations where something is live, only
9292
/// which regions are live.
93-
pub(crate) fn without_specific_points(elements: Rc<DenseLocationMap>) -> Self {
93+
pub(crate) fn without_specific_points(location_map: Rc<DenseLocationMap>) -> Self {
9494
LivenessValues {
9595
live_regions: Some(Default::default()),
9696
points: None,
97-
elements,
97+
location_map,
9898
loans: None,
9999
}
100100
}
@@ -122,11 +122,11 @@ impl LivenessValues {
122122

123123
/// Records `region` as being live at the given `location`.
124124
pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) {
125-
let point = self.elements.point_from_location(location);
125+
let point = self.location_map.point_from_location(location);
126126
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
127127
if let Some(points) = &mut self.points {
128128
points.insert(region, point);
129-
} else if self.elements.point_in_range(point) {
129+
} else if self.location_map.point_in_range(point) {
130130
self.live_regions.as_mut().unwrap().insert(region);
131131
}
132132

@@ -143,7 +143,7 @@ impl LivenessValues {
143143
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
144144
if let Some(this) = &mut self.points {
145145
this.union_row(region, points);
146-
} else if points.iter().any(|point| self.elements.point_in_range(point)) {
146+
} else if points.iter().any(|point| self.location_map.point_in_range(point)) {
147147
self.live_regions.as_mut().unwrap().insert(region);
148148
}
149149

@@ -170,7 +170,7 @@ impl LivenessValues {
170170

171171
/// Returns whether `region` is marked live at the given `location`.
172172
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
173-
let point = self.elements.point_from_location(location);
173+
let point = self.location_map.point_from_location(location);
174174
if let Some(points) = &self.points {
175175
points.row(region).is_some_and(|r| r.contains(point))
176176
} else {
@@ -191,25 +191,26 @@ impl LivenessValues {
191191
.row(region)
192192
.into_iter()
193193
.flat_map(|set| set.iter())
194-
.take_while(|&p| self.elements.point_in_range(p))
194+
.take_while(|&p| self.location_map.point_in_range(p))
195195
}
196196

197197
/// For debugging purposes, returns a pretty-printed string of the points where the `region` is
198198
/// live.
199199
pub(crate) fn pretty_print_live_points(&self, region: RegionVid) -> String {
200200
pretty_print_region_elements(
201-
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
201+
self.live_points(region)
202+
.map(|p| RegionElement::Location(self.location_map.to_location(p))),
202203
)
203204
}
204205

205206
#[inline]
206207
pub(crate) fn point_from_location(&self, location: Location) -> PointIndex {
207-
self.elements.point_from_location(location)
208+
self.location_map.point_from_location(location)
208209
}
209210

210211
#[inline]
211212
pub(crate) fn location_from_point(&self, point: PointIndex) -> Location {
212-
self.elements.to_location(point)
213+
self.location_map.to_location(point)
213214
}
214215

215216
/// When using `-Zpolonius=next`, returns whether the `loan_idx` is live at the given `point`.
@@ -272,7 +273,7 @@ impl PlaceholderIndices {
272273
/// because (since it is returned) it must live for at least `'a`. But
273274
/// it would also contain various points from within the function.
274275
pub(crate) struct RegionValues<N: Idx> {
275-
elements: Rc<DenseLocationMap>,
276+
location_map: Rc<DenseLocationMap>,
276277
placeholder_indices: PlaceholderIndices,
277278
points: SparseIntervalMatrix<N, PointIndex>,
278279
free_regions: SparseBitMatrix<N, RegionVid>,
@@ -287,14 +288,14 @@ impl<N: Idx> RegionValues<N> {
287288
/// Each of the regions in num_region_variables will be initialized with an
288289
/// empty set of points and no causal information.
289290
pub(crate) fn new(
290-
elements: Rc<DenseLocationMap>,
291+
location_map: Rc<DenseLocationMap>,
291292
num_universal_regions: usize,
292293
placeholder_indices: PlaceholderIndices,
293294
) -> Self {
294-
let num_points = elements.num_points();
295+
let num_points = location_map.num_points();
295296
let num_placeholders = placeholder_indices.len();
296297
Self {
297-
elements,
298+
location_map,
298299
points: SparseIntervalMatrix::new(num_points),
299300
placeholder_indices,
300301
free_regions: SparseBitMatrix::new(num_universal_regions),
@@ -336,7 +337,7 @@ impl<N: Idx> RegionValues<N> {
336337
end: usize,
337338
) -> Option<usize> {
338339
let row = self.points.row(r)?;
339-
let block = self.elements.entry_point(block);
340+
let block = self.location_map.entry_point(block);
340341
let start = block.plus(start);
341342
let end = block.plus(end);
342343
let first_unset = row.first_unset_in(start..=end)?;
@@ -375,8 +376,8 @@ impl<N: Idx> RegionValues<N> {
375376
pub(crate) fn locations_outlived_by<'a>(&'a self, r: N) -> impl Iterator<Item = Location> + 'a {
376377
self.points.row(r).into_iter().flat_map(move |set| {
377378
set.iter()
378-
.take_while(move |&p| self.elements.point_in_range(p))
379-
.map(move |p| self.elements.to_location(p))
379+
.take_while(move |&p| self.location_map.point_in_range(p))
380+
.map(move |p| self.location_map.to_location(p))
380381
})
381382
}
382383

@@ -430,12 +431,12 @@ pub(crate) trait ToElementIndex: Debug + Copy {
430431

431432
impl ToElementIndex for Location {
432433
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
433-
let index = values.elements.point_from_location(self);
434+
let index = values.location_map.point_from_location(self);
434435
values.points.insert(row, index)
435436
}
436437

437438
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
438-
let index = values.elements.point_from_location(self);
439+
let index = values.location_map.point_from_location(self);
439440
values.points.contains(row, index)
440441
}
441442
}
@@ -464,14 +465,14 @@ impl ToElementIndex for ty::PlaceholderRegion {
464465

465466
/// For debugging purposes, returns a pretty-printed string of the given points.
466467
pub(crate) fn pretty_print_points(
467-
elements: &DenseLocationMap,
468+
location_map: &DenseLocationMap,
468469
points: impl IntoIterator<Item = PointIndex>,
469470
) -> String {
470471
pretty_print_region_elements(
471472
points
472473
.into_iter()
473-
.take_while(|&p| elements.point_in_range(p))
474-
.map(|p| elements.to_location(p))
474+
.take_while(|&p| location_map.point_in_range(p))
475+
.map(|p| location_map.to_location(p))
475476
.map(RegionElement::Location),
476477
)
477478
}

Diff for: compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a> Iterator for AppearancesIter<'a> {
8282
impl LocalUseMap {
8383
pub(crate) fn build(
8484
live_locals: &[Local],
85-
elements: &DenseLocationMap,
85+
location_map: &DenseLocationMap,
8686
body: &Body<'_>,
8787
) -> Self {
8888
let nones = IndexVec::from_elem(None, &body.local_decls);
@@ -101,7 +101,7 @@ impl LocalUseMap {
101101
IndexVec::from_elem(false, &body.local_decls);
102102
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
103103

104-
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
104+
LocalUseMapBuild { local_use_map: &mut local_use_map, location_map, locals_with_use_data }
105105
.visit_body(body);
106106

107107
local_use_map
@@ -125,7 +125,7 @@ impl LocalUseMap {
125125

126126
struct LocalUseMapBuild<'me> {
127127
local_use_map: &'me mut LocalUseMap,
128-
elements: &'me DenseLocationMap,
128+
location_map: &'me DenseLocationMap,
129129

130130
// Vector used in `visit_local` to signal which `Local`s do we need
131131
// def/use/drop information on, constructed from `live_locals` (that
@@ -147,7 +147,7 @@ impl Visitor<'_> for LocalUseMapBuild<'_> {
147147
DefUse::Use => &mut self.local_use_map.first_use_at[local],
148148
DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
149149
};
150-
let point_index = self.elements.point_from_location(location);
150+
let point_index = self.location_map.point_from_location(location);
151151
let appearance_index = self
152152
.local_use_map
153153
.appearances

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod trace;
3232
pub(super) fn generate<'a, 'tcx>(
3333
typeck: &mut TypeChecker<'_, 'tcx>,
3434
body: &Body<'tcx>,
35-
elements: &DenseLocationMap,
35+
location_map: &DenseLocationMap,
3636
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
3737
move_data: &MoveData<'tcx>,
3838
) {
@@ -49,7 +49,7 @@ pub(super) fn generate<'a, 'tcx>(
4949
trace::trace(
5050
typeck,
5151
body,
52-
elements,
52+
location_map,
5353
flow_inits,
5454
move_data,
5555
relevant_live_locals,

0 commit comments

Comments
 (0)