introduce is_live_anywhere
instead of peeking into points
and refactor misnamed `get_elements`
This commit is contained in:
parent
b4c7d1dd05
commit
79c5e913d3
2 changed files with 12 additions and 6 deletions
|
@ -158,19 +158,25 @@ impl<N: Idx> LivenessValues<N> {
|
||||||
self.points.row(region).is_some_and(|r| r.contains(point))
|
self.points.row(region).is_some_and(|r| r.contains(point))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator of all the elements contained by `region`.
|
/// Returns whether `region` is marked live at any location.
|
||||||
pub(crate) fn get_elements(&self, region: N) -> impl Iterator<Item = 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
|
self.points
|
||||||
.row(region)
|
.row(region)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|set| set.iter())
|
.flat_map(|set| set.iter())
|
||||||
.take_while(move |&p| self.elements.point_in_range(p))
|
.take_while(|&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.
|
/// Returns a "pretty" string value of the region. Meant for debugging.
|
||||||
pub(crate) fn region_value_str(&self, region: N) -> String {
|
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]
|
#[inline]
|
||||||
|
|
|
@ -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,
|
// 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
|
// then add a liveness constraint to the main MIR for this region
|
||||||
// at the location provided as an argument to this method
|
// 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
|
self.cx
|
||||||
.borrowck_context
|
.borrowck_context
|
||||||
.constraints
|
.constraints
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue