Skip to content

Commit

Permalink
Remove a couple of Rc's from RegionInferenceContext
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Mar 13, 2020
1 parent 54b7d21 commit 4b46271
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
28 changes: 23 additions & 5 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -73,6 +73,24 @@ crate use place_ext::PlaceExt;
crate use places_conflict::{places_conflict, PlaceConflictBias};
crate use region_infer::RegionInferenceContext;

/// An owned immutable value.
#[derive(Debug)]
struct Frozen<T>(T);

impl<T> Frozen<T> {
pub fn freeze(val: T) -> Self {
Frozen(val)
}
}

impl<T> std::ops::Deref for Frozen<T> {
type Target = T;

fn deref(&self) -> &T {
&self.0
}
}

// FIXME(eddyb) perhaps move this somewhere more centrally.
#[derive(Debug)]
crate struct Upvar {
Expand Down Expand Up @@ -1577,11 +1595,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
mpi,
);
} // Only query longest prefix with a MovePath, not further
// ancestors; dataflow recurs on children when parents
// move (to support partial (re)inits).
//
// (I.e., querying parents breaks scenario 7; but may want
// to do such a query based on partial-init feature-gate.)
// ancestors; dataflow recurs on children when parents
// move (to support partial (re)inits).
//
// (I.e., querying parents breaks scenario 7; but may want
// to do such a query based on partial-init feature-gate.)
}

/// Subslices correspond to multiple move paths, so we iterate through the
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/borrow_check/region_infer/mod.rs
Expand Up @@ -31,6 +31,7 @@ use crate::borrow_check::{
},
type_check::{free_region_relations::UniversalRegionRelations, Locations},
universal_regions::UniversalRegions,
Frozen,
};

mod dump_mir;
Expand All @@ -54,12 +55,12 @@ pub struct RegionInferenceContext<'tcx> {
liveness_constraints: LivenessValues<RegionVid>,

/// The outlives constraints computed by the type-check.
constraints: Rc<OutlivesConstraintSet>,
constraints: Frozen<OutlivesConstraintSet>,

/// The constraint-set, but in graph form, making it easy to traverse
/// the constraints adjacent to a particular region. Used to construct
/// the SCC (see `constraint_sccs`) and for error reporting.
constraint_graph: Rc<NormalConstraintGraph>,
constraint_graph: Frozen<NormalConstraintGraph>,

/// The SCC computed from `constraints` and the constraint
/// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
Expand Down Expand Up @@ -263,8 +264,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.map(|info| RegionDefinition::new(info.universe, info.origin))
.collect();

let constraints = Rc::new(outlives_constraints); // freeze constraints
let constraint_graph = Rc::new(constraints.graph(definitions.len()));
let constraints = Frozen::freeze(outlives_constraints);
let constraint_graph = Frozen::freeze(constraints.graph(definitions.len()));
let fr_static = universal_regions.fr_static;
let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static));

Expand Down

0 comments on commit 4b46271

Please sign in to comment.