Skip to content

Commit 4b46271

Browse files
committed
Remove a couple of Rc's from RegionInferenceContext
1 parent 54b7d21 commit 4b46271

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ crate use place_ext::PlaceExt;
7373
crate use places_conflict::{places_conflict, PlaceConflictBias};
7474
crate use region_infer::RegionInferenceContext;
7575

76+
/// An owned immutable value.
77+
#[derive(Debug)]
78+
struct Frozen<T>(T);
79+
80+
impl<T> Frozen<T> {
81+
pub fn freeze(val: T) -> Self {
82+
Frozen(val)
83+
}
84+
}
85+
86+
impl<T> std::ops::Deref for Frozen<T> {
87+
type Target = T;
88+
89+
fn deref(&self) -> &T {
90+
&self.0
91+
}
92+
}
93+
7694
// FIXME(eddyb) perhaps move this somewhere more centrally.
7795
#[derive(Debug)]
7896
crate struct Upvar {
@@ -1577,11 +1595,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15771595
mpi,
15781596
);
15791597
} // Only query longest prefix with a MovePath, not further
1580-
// ancestors; dataflow recurs on children when parents
1581-
// move (to support partial (re)inits).
1582-
//
1583-
// (I.e., querying parents breaks scenario 7; but may want
1584-
// to do such a query based on partial-init feature-gate.)
1598+
// ancestors; dataflow recurs on children when parents
1599+
// move (to support partial (re)inits).
1600+
//
1601+
// (I.e., querying parents breaks scenario 7; but may want
1602+
// to do such a query based on partial-init feature-gate.)
15851603
}
15861604

15871605
/// Subslices correspond to multiple move paths, so we iterate through the

src/librustc_mir/borrow_check/region_infer/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::borrow_check::{
3131
},
3232
type_check::{free_region_relations::UniversalRegionRelations, Locations},
3333
universal_regions::UniversalRegions,
34+
Frozen,
3435
};
3536

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

5657
/// The outlives constraints computed by the type-check.
57-
constraints: Rc<OutlivesConstraintSet>,
58+
constraints: Frozen<OutlivesConstraintSet>,
5859

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

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

266-
let constraints = Rc::new(outlives_constraints); // freeze constraints
267-
let constraint_graph = Rc::new(constraints.graph(definitions.len()));
267+
let constraints = Frozen::freeze(outlives_constraints);
268+
let constraint_graph = Frozen::freeze(constraints.graph(definitions.len()));
268269
let fr_static = universal_regions.fr_static;
269270
let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static));
270271

0 commit comments

Comments
 (0)