Skip to content

Commit

Permalink
introduce is_live_anywhere instead of peeking into points
Browse files Browse the repository at this point in the history
and refactor misnamed `get_elements`
  • Loading branch information
lqd committed Nov 13, 2023
1 parent b4c7d1d commit 30e8406
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,25 @@ impl<N: Idx> LivenessValues<N> {
self.points.row(region).is_some_and(|r| r.contains(point))
}

/// Returns an iterator of all the elements contained by `region`.
pub(crate) fn get_elements(&self, region: N) -> impl Iterator<Item = Location> + '_ {
/// Returns whether `region` is marked live at any location.
pub(crate) fn is_live_anywhere(&self, region: N) -> bool {
self.live_points(region).next().is_some()
}

/// Returns an iterator of all the points where `region` is live.
fn live_points(&self, region: N) -> impl Iterator<Item = PointIndex> + '_ {
self.points
.row(region)
.into_iter()
.flat_map(|set| set.iter())
.take_while(move |&p| self.elements.point_in_range(p))
.map(move |p| self.elements.to_location(p))
}

/// Returns a "pretty" string value of the region. Meant for debugging.
pub(crate) fn region_value_str(&self, region: N) -> String {
region_value_str(self.get_elements(region).map(RegionElement::Location))
region_value_str(
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
// If the region is live at at least one location in the promoted MIR,
// then add a liveness constraint to the main MIR for this region
// at the location provided as an argument to this method
if liveness_constraints.get_elements(region).next().is_some() {
if liveness_constraints.is_live_anywhere(region) {
self.cx
.borrowck_context
.constraints
Expand Down

0 comments on commit 30e8406

Please sign in to comment.