Skip to content

Commit

Permalink
LivenessValues does not need to be generic over regions
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Nov 13, 2023
1 parent 30e8406 commit aa481bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/constraint_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +18,7 @@ use crate::{

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>,
Expand All @@ -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>,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
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 {
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -173,7 +173,7 @@ impl<N: Idx> LivenessValues<N> {
}

/// 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))),
)
Expand Down Expand Up @@ -309,7 +309,7 @@ impl<N: Idx> RegionValues<N> {
/// `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);
}
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 @@ -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>,

Expand Down

0 comments on commit aa481bd

Please sign in to comment.