LivenessValues
does not need to be generic over regions
This commit is contained in:
parent
79c5e913d3
commit
84a002cc42
@ -9,7 +9,7 @@
|
||||
};
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
||||
use crate::{
|
||||
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict,
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
pub(super) fn generate_constraints<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
liveness_constraints: &mut LivenessValues<RegionVid>,
|
||||
liveness_constraints: &mut LivenessValues,
|
||||
all_facts: &mut Option<AllFacts>,
|
||||
location_table: &LocationTable,
|
||||
body: &Body<'tcx>,
|
||||
@ -43,7 +43,7 @@ struct ConstraintGeneration<'cg, 'tcx> {
|
||||
infcx: &'cg InferCtxt<'tcx>,
|
||||
all_facts: &'cg mut Option<AllFacts>,
|
||||
location_table: &'cg LocationTable,
|
||||
liveness_constraints: &'cg mut LivenessValues<RegionVid>,
|
||||
liveness_constraints: &'cg mut LivenessValues,
|
||||
borrow_set: &'cg BorrowSet<'tcx>,
|
||||
body: &'cg Body<'tcx>,
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ pub struct RegionInferenceContext<'tcx> {
|
||||
/// regions, these start out empty and steadily grow, though for
|
||||
/// each universally quantified region R they start out containing
|
||||
/// the entire CFG and `end(R)`.
|
||||
liveness_constraints: LivenessValues<RegionVid>,
|
||||
liveness_constraints: LivenessValues,
|
||||
|
||||
/// The outlives constraints computed by the type-check.
|
||||
constraints: Frozen<OutlivesConstraintSet<'tcx>>,
|
||||
@ -332,7 +332,7 @@ pub(crate) fn new<'cx>(
|
||||
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
|
||||
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||
type_tests: Vec<TypeTest<'tcx>>,
|
||||
liveness_constraints: LivenessValues<RegionVid>,
|
||||
liveness_constraints: LivenessValues,
|
||||
elements: &Rc<RegionValueElements>,
|
||||
live_loans: SparseBitMatrix<PointIndex, BorrowIndex>,
|
||||
) -> Self {
|
||||
|
@ -118,53 +118,53 @@ pub(crate) enum RegionElement {
|
||||
|
||||
/// Records the CFG locations where each region is live. When we initially compute liveness, we use
|
||||
/// an interval matrix storing liveness ranges for each region-vid.
|
||||
pub(crate) struct LivenessValues<N: Idx> {
|
||||
pub(crate) struct LivenessValues {
|
||||
elements: Rc<RegionValueElements>,
|
||||
points: SparseIntervalMatrix<N, PointIndex>,
|
||||
points: SparseIntervalMatrix<RegionVid, PointIndex>,
|
||||
}
|
||||
|
||||
impl<N: Idx> LivenessValues<N> {
|
||||
impl LivenessValues {
|
||||
/// Create an empty map of regions to locations where they're live.
|
||||
pub(crate) fn new(elements: Rc<RegionValueElements>) -> Self {
|
||||
Self { points: SparseIntervalMatrix::new(elements.num_points), elements }
|
||||
}
|
||||
|
||||
/// Iterate through each region that has a value in this set.
|
||||
pub(crate) fn regions(&self) -> impl Iterator<Item = N> {
|
||||
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> {
|
||||
self.points.rows()
|
||||
}
|
||||
|
||||
/// Records `region` as being live at the given `location`.
|
||||
pub(crate) fn add_location(&mut self, region: N, location: Location) {
|
||||
pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) {
|
||||
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
|
||||
let point = self.elements.point_from_location(location);
|
||||
self.points.insert(region, point);
|
||||
}
|
||||
|
||||
/// Records `region` as being live at all the given `points`.
|
||||
pub(crate) fn add_points(&mut self, region: N, points: &IntervalSet<PointIndex>) {
|
||||
pub(crate) fn add_points(&mut self, region: RegionVid, points: &IntervalSet<PointIndex>) {
|
||||
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
|
||||
self.points.union_row(region, points);
|
||||
}
|
||||
|
||||
/// Records `region` as being live at all the control-flow points.
|
||||
pub(crate) fn add_all_points(&mut self, region: N) {
|
||||
pub(crate) fn add_all_points(&mut self, region: RegionVid) {
|
||||
self.points.insert_all_into_row(region);
|
||||
}
|
||||
|
||||
/// Returns whether `region` is marked live at the given `location`.
|
||||
pub(crate) fn is_live_at(&self, region: N, location: Location) -> bool {
|
||||
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
|
||||
let point = self.elements.point_from_location(location);
|
||||
self.points.row(region).is_some_and(|r| r.contains(point))
|
||||
}
|
||||
|
||||
/// Returns whether `region` is marked live at any location.
|
||||
pub(crate) fn is_live_anywhere(&self, region: N) -> bool {
|
||||
pub(crate) fn is_live_anywhere(&self, region: RegionVid) -> 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> + '_ {
|
||||
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
self.points
|
||||
.row(region)
|
||||
.into_iter()
|
||||
@ -173,7 +173,7 @@ fn live_points(&self, region: N) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
}
|
||||
|
||||
/// 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: RegionVid) -> String {
|
||||
region_value_str(
|
||||
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
|
||||
)
|
||||
@ -309,7 +309,7 @@ pub(crate) fn first_non_contained_inclusive(
|
||||
/// `self[to] |= values[from]`, essentially: that is, take all the
|
||||
/// elements for the region `from` from `values` and add them to
|
||||
/// the region `to` in `self`.
|
||||
pub(crate) fn merge_liveness<M: Idx>(&mut self, to: N, from: M, values: &LivenessValues<M>) {
|
||||
pub(crate) fn merge_liveness(&mut self, to: N, from: RegionVid, values: &LivenessValues) {
|
||||
if let Some(set) = values.points.row(from) {
|
||||
self.points.union_row(to, set);
|
||||
}
|
||||
|
@ -899,7 +899,7 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> {
|
||||
/// not otherwise appear in the MIR -- in particular, the
|
||||
/// late-bound regions that it instantiates at call-sites -- and
|
||||
/// hence it must report on their liveness constraints.
|
||||
pub(crate) liveness_constraints: LivenessValues<RegionVid>,
|
||||
pub(crate) liveness_constraints: LivenessValues,
|
||||
|
||||
pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user