From aa481bd8a225ae7ae1a96d5a3ba41026b314477b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 13 Nov 2023 15:28:26 +0000 Subject: [PATCH] `LivenessValues` does not need to be generic over regions --- .../src/constraint_generation.rs | 6 ++--- .../rustc_borrowck/src/region_infer/mod.rs | 4 ++-- .../rustc_borrowck/src/region_infer/values.rs | 24 +++++++++---------- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_borrowck/src/constraint_generation.rs b/compiler/rustc_borrowck/src/constraint_generation.rs index 02b3bed94bfcd..21d367c40cb9c 100644 --- a/compiler/rustc_borrowck/src/constraint_generation.rs +++ b/compiler/rustc_borrowck/src/constraint_generation.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::{ }; 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 @@ use crate::{ pub(super) fn generate_constraints<'tcx>( infcx: &InferCtxt<'tcx>, - liveness_constraints: &mut LivenessValues, + liveness_constraints: &mut LivenessValues, all_facts: &mut Option, location_table: &LocationTable, body: &Body<'tcx>, @@ -43,7 +43,7 @@ struct ConstraintGeneration<'cg, 'tcx> { infcx: &'cg InferCtxt<'tcx>, all_facts: &'cg mut Option, location_table: &'cg LocationTable, - liveness_constraints: &'cg mut LivenessValues, + liveness_constraints: &'cg mut LivenessValues, borrow_set: &'cg BorrowSet<'tcx>, body: &'cg Body<'tcx>, } diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index b9a824c1401af..ff125a0274516 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -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, + liveness_constraints: LivenessValues, /// The outlives constraints computed by the type-check. constraints: Frozen>, @@ -332,7 +332,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { member_constraints_in: MemberConstraintSet<'tcx, RegionVid>, universe_causes: FxIndexMap>, type_tests: Vec>, - liveness_constraints: LivenessValues, + liveness_constraints: LivenessValues, elements: &Rc, live_loans: SparseBitMatrix, ) -> Self { diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index e005e4d63b6e3..6154a6955e929 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -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 { +pub(crate) struct LivenessValues { elements: Rc, - points: SparseIntervalMatrix, + points: SparseIntervalMatrix, } -impl LivenessValues { +impl LivenessValues { /// Create an empty map of regions to locations where they're live. pub(crate) fn new(elements: Rc) -> 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 { + pub(crate) fn regions(&self) -> impl Iterator { 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) { + pub(crate) fn add_points(&mut self, region: RegionVid, points: &IntervalSet) { 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 + '_ { + fn live_points(&self, region: RegionVid) -> impl Iterator + '_ { self.points .row(region) .into_iter() @@ -173,7 +173,7 @@ impl LivenessValues { } /// 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 @@ impl RegionValues { /// `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(&mut self, to: N, from: M, values: &LivenessValues) { + 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); } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index e23f633bea2b6..f0e35bdb75f55 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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, + pub(crate) liveness_constraints: LivenessValues, pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,