Skip to content

Commit 3e12f5f

Browse files
committed
move refcells out from RegionVarBindings and up into InferCtxt
1 parent f9cda89 commit 3e12f5f

File tree

11 files changed

+151
-156
lines changed

11 files changed

+151
-156
lines changed

src/librustc/infer/equate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
104104
a,
105105
b);
106106
let origin = Subtype(self.fields.trace.clone());
107-
self.fields.infcx.region_vars.make_eqregion(origin, a, b);
107+
self.fields.infcx.region_vars.borrow_mut().make_eqregion(origin, a, b);
108108
Ok(a)
109109
}
110110

src/librustc/infer/fudge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
7878
self.type_variables.borrow_mut().types_created_since_snapshot(
7979
&snapshot.type_snapshot);
8080
let region_vars =
81-
self.region_vars.vars_created_since_snapshot(
81+
self.region_vars.borrow().vars_created_since_snapshot(
8282
&snapshot.region_vars_snapshot);
8383

8484
Ok((type_variables, region_vars, value))

src/librustc/infer/glb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
6767
b);
6868

6969
let origin = Subtype(self.fields.trace.clone());
70-
Ok(self.fields.infcx.region_vars.glb_regions(self.tcx(), origin, a, b))
70+
Ok(self.fields.infcx.region_vars.borrow_mut().glb_regions(self.tcx(), origin, a, b))
7171
}
7272

7373
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
176176
.filter(|&r| r != representative)
177177
{
178178
let origin = SubregionOrigin::Subtype(self.trace.clone());
179-
self.infcx.region_vars.make_eqregion(origin,
180-
*representative,
181-
*region);
179+
self.infcx.region_vars.borrow_mut().make_eqregion(origin,
180+
*representative,
181+
*region);
182182
}
183183
}
184184

@@ -427,7 +427,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
427427
fn fresh_bound_variable<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
428428
debruijn: ty::DebruijnIndex)
429429
-> ty::Region<'tcx> {
430-
infcx.region_vars.new_bound(infcx.tcx, debruijn)
430+
infcx.region_vars.borrow_mut().new_bound(infcx.tcx, debruijn)
431431
}
432432
}
433433
}
@@ -481,7 +481,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
481481
r: ty::Region<'tcx>,
482482
directions: TaintDirections)
483483
-> FxHashSet<ty::Region<'tcx>> {
484-
self.region_vars.tainted(self.tcx, &snapshot.region_vars_snapshot, r, directions)
484+
self.region_vars.borrow().tainted(self.tcx, &snapshot.region_vars_snapshot, r, directions)
485485
}
486486

487487
fn region_vars_confined_to_snapshot(&self,
@@ -539,7 +539,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
539539
*/
540540

541541
let mut region_vars =
542-
self.region_vars.vars_created_since_snapshot(&snapshot.region_vars_snapshot);
542+
self.region_vars.borrow().vars_created_since_snapshot(&snapshot.region_vars_snapshot);
543543

544544
let escaping_types =
545545
self.type_variables.borrow_mut().types_escaping_snapshot(&snapshot.type_snapshot);
@@ -581,7 +581,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
581581
where T : TypeFoldable<'tcx>
582582
{
583583
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
584-
self.region_vars.push_skolemized(self.tcx, br, &snapshot.region_vars_snapshot)
584+
self.region_vars.borrow_mut().push_skolemized(self.tcx,
585+
br,
586+
&snapshot.region_vars_snapshot)
585587
});
586588

587589
debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
@@ -766,7 +768,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
766768
{
767769
debug!("pop_skolemized({:?})", skol_map);
768770
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
769-
self.region_vars.pop_skolemized(self.tcx, &skol_regions, &snapshot.region_vars_snapshot);
771+
self.region_vars.borrow_mut().pop_skolemized(self.tcx,
772+
&skol_regions,
773+
&snapshot.region_vars_snapshot);
770774
if !skol_map.is_empty() {
771775
self.projection_cache.borrow_mut().rollback_skolemized(
772776
&snapshot.projection_cache_snapshot);

src/librustc/infer/lexical_region_resolve/graphviz.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
113113
}
114114
};
115115

116-
let constraints = &*region_vars.constraints.borrow();
117-
match dump_region_constraints_to(region_rels, constraints, &output_path) {
116+
match dump_region_constraints_to(region_rels, &region_vars.constraints, &output_path) {
118117
Ok(()) => {}
119118
Err(e) => {
120119
let msg = format!("io error dumping region constraints: {}", e);

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
8080
/// constraints, assuming such values can be found; if they cannot,
8181
/// errors are reported.
8282
pub fn resolve_regions(
83-
&self,
83+
&mut self,
8484
region_rels: &RegionRelations<'_, '_, 'tcx>,
8585
) -> (
8686
LexicalRegionResolutions<'tcx>,
@@ -114,7 +114,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
114114

115115
(&ReVar(v_id), _) | (_, &ReVar(v_id)) => {
116116
span_bug!(
117-
(*self.var_origins.borrow())[v_id.index as usize].span(),
117+
self.var_origins[v_id.index as usize].span(),
118118
"lub_concrete_regions invoked with non-concrete \
119119
regions: {:?}, {:?}",
120120
a,
@@ -183,7 +183,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
183183
}
184184

185185
fn infer_variable_values(
186-
&self,
186+
&mut self,
187187
region_rels: &RegionRelations<'_, '_, 'tcx>,
188188
errors: &mut Vec<RegionResolutionError<'tcx>>,
189189
) -> LexicalRegionResolutions<'tcx> {
@@ -222,12 +222,12 @@ impl<'tcx> RegionVarBindings<'tcx> {
222222
"----() Start constraint listing (context={:?}) ()----",
223223
free_regions.context
224224
);
225-
for (idx, (constraint, _)) in self.constraints.borrow().iter().enumerate() {
225+
for (idx, (constraint, _)) in self.constraints.iter().enumerate() {
226226
debug!("Constraint {} => {:?}", idx, constraint);
227227
}
228228
}
229229

230-
fn expand_givens(&self, graph: &RegionGraph) {
230+
fn expand_givens(&mut self, graph: &RegionGraph) {
231231
// Givens are a kind of horrible hack to account for
232232
// constraints like 'c <= '0 that are known to hold due to
233233
// closure signatures (see the comment above on the `givens`
@@ -238,15 +238,14 @@ impl<'tcx> RegionVarBindings<'tcx> {
238238
// and '0 <= '1
239239
// then 'c <= '1
240240

241-
let mut givens = self.givens.borrow_mut();
242-
let seeds: Vec<_> = givens.iter().cloned().collect();
241+
let seeds: Vec<_> = self.givens.iter().cloned().collect();
243242
for (r, vid) in seeds {
244243
let seed_index = NodeIndex(vid.index as usize);
245244
for succ_index in graph.depth_traverse(seed_index, OUTGOING) {
246245
let succ_index = succ_index.0 as u32;
247246
if succ_index < self.num_vars() {
248247
let succ_vid = RegionVid { index: succ_index };
249-
givens.insert((r, succ_vid));
248+
self.givens.insert((r, succ_vid));
250249
}
251250
}
252251
}
@@ -292,7 +291,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
292291
// Check if this relationship is implied by a given.
293292
match *a_region {
294293
ty::ReEarlyBound(_) | ty::ReFree(_) => {
295-
if self.givens.borrow().contains(&(a_region, b_vid)) {
294+
if self.givens.contains(&(a_region, b_vid)) {
296295
debug!("given");
297296
return false;
298297
}
@@ -333,8 +332,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
333332
var_data: &mut LexicalRegionResolutions<'tcx>,
334333
errors: &mut Vec<RegionResolutionError<'tcx>>,
335334
) {
336-
let constraints = self.constraints.borrow();
337-
for (constraint, origin) in constraints.iter() {
335+
for (constraint, origin) in &self.constraints {
338336
debug!(
339337
"collect_errors: constraint={:?} origin={:?}",
340338
constraint,
@@ -392,7 +390,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
392390
}
393391
}
394392

395-
for verify in self.verifys.borrow().iter() {
393+
for verify in &self.verifys {
396394
debug!("collect_errors: verify={:?}", verify);
397395
let sub = var_data.normalize(verify.region);
398396

@@ -488,8 +486,6 @@ impl<'tcx> RegionVarBindings<'tcx> {
488486
fn construct_graph(&self) -> RegionGraph<'tcx> {
489487
let num_vars = self.num_vars();
490488

491-
let constraints = self.constraints.borrow();
492-
493489
let mut graph = graph::Graph::new();
494490

495491
for _ in 0..num_vars {
@@ -504,7 +500,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
504500
let dummy_source = graph.add_node(());
505501
let dummy_sink = graph.add_node(());
506502

507-
for (constraint, _) in constraints.iter() {
503+
for (constraint, _) in &self.constraints {
508504
match *constraint {
509505
Constraint::VarSubVar(a_id, b_id) => {
510506
graph.add_edge(
@@ -564,7 +560,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
564560
for lower_bound in &lower_bounds {
565561
for upper_bound in &upper_bounds {
566562
if !region_rels.is_subregion_of(lower_bound.region, upper_bound.region) {
567-
let origin = (*self.var_origins.borrow())[node_idx.index as usize].clone();
563+
let origin = self.var_origins[node_idx.index as usize].clone();
568564
debug!(
569565
"region inference error at {:?} for {:?}: SubSupConflict sub: {:?} \
570566
sup: {:?}",
@@ -586,7 +582,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
586582
}
587583

588584
span_bug!(
589-
(*self.var_origins.borrow())[node_idx.index as usize].span(),
585+
self.var_origins[node_idx.index as usize].span(),
590586
"collect_error_for_expanding_node() could not find \
591587
error for var {:?}, lower_bounds={:?}, \
592588
upper_bounds={:?}",
@@ -671,7 +667,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
671667
Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => {
672668
state.result.push(RegionAndOrigin {
673669
region,
674-
origin: this.constraints.borrow().get(&edge.data).unwrap().clone(),
670+
origin: this.constraints.get(&edge.data).unwrap().clone(),
675671
});
676672
}
677673

@@ -694,7 +690,7 @@ impl<'tcx> RegionVarBindings<'tcx> {
694690
changed = false;
695691
iteration += 1;
696692
debug!("---- {} Iteration {}{}", "#", tag, iteration);
697-
for (constraint, origin) in self.constraints.borrow().iter() {
693+
for (constraint, origin) in &self.constraints {
698694
let edge_changed = body(constraint, origin);
699695
if edge_changed {
700696
debug!("Updated due to constraint {:?}", constraint);

src/librustc/infer/lub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
6767
b);
6868

6969
let origin = Subtype(self.fields.trace.clone());
70-
Ok(self.fields.infcx.region_vars.lub_regions(self.tcx(), origin, a, b))
70+
Ok(self.fields.infcx.region_vars.borrow_mut().lub_regions(self.tcx(), origin, a, b))
7171
}
7272

7373
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)

src/librustc/infer/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
104104
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,
105105

106106
// For region variables.
107-
region_vars: RegionVarBindings<'tcx>,
107+
region_vars: RefCell<RegionVarBindings<'tcx>>,
108108

109109
// Once region inference is done, the values for each variable.
110110
lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>,
@@ -424,7 +424,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
424424
type_variables: RefCell::new(type_variable::TypeVariableTable::new()),
425425
int_unification_table: RefCell::new(UnificationTable::new()),
426426
float_unification_table: RefCell::new(UnificationTable::new()),
427-
region_vars: RegionVarBindings::new(),
427+
region_vars: RefCell::new(RegionVarBindings::new()),
428428
lexical_region_resolutions: RefCell::new(None),
429429
selection_cache: traits::SelectionCache::new(),
430430
evaluation_cache: traits::EvaluationCache::new(),
@@ -767,7 +767,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
767767
type_snapshot: self.type_variables.borrow_mut().snapshot(),
768768
int_snapshot: self.int_unification_table.borrow_mut().snapshot(),
769769
float_snapshot: self.float_unification_table.borrow_mut().snapshot(),
770-
region_vars_snapshot: self.region_vars.start_snapshot(),
770+
region_vars_snapshot: self.region_vars.borrow_mut().start_snapshot(),
771771
was_in_snapshot: in_snapshot,
772772
// Borrow tables "in progress" (i.e. during typeck)
773773
// to ban writes from within a snapshot to them.
@@ -802,6 +802,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
802802
.borrow_mut()
803803
.rollback_to(float_snapshot);
804804
self.region_vars
805+
.borrow_mut()
805806
.rollback_to(region_vars_snapshot);
806807
}
807808

@@ -830,6 +831,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
830831
.borrow_mut()
831832
.commit(float_snapshot);
832833
self.region_vars
834+
.borrow_mut()
833835
.commit(region_vars_snapshot);
834836
}
835837

@@ -885,7 +887,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
885887
sub: ty::Region<'tcx>,
886888
sup: ty::RegionVid)
887889
{
888-
self.region_vars.add_given(sub, sup);
890+
self.region_vars.borrow_mut().add_given(sub, sup);
889891
}
890892

891893
pub fn can_sub<T>(&self,
@@ -925,7 +927,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
925927
a: ty::Region<'tcx>,
926928
b: ty::Region<'tcx>) {
927929
debug!("sub_regions({:?} <: {:?})", a, b);
928-
self.region_vars.make_subregion(origin, a, b);
930+
self.region_vars.borrow_mut().make_subregion(origin, a, b);
929931
}
930932

931933
pub fn equality_predicate(&self,
@@ -1028,7 +1030,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10281030

10291031
pub fn next_region_var(&self, origin: RegionVariableOrigin)
10301032
-> ty::Region<'tcx> {
1031-
self.tcx.mk_region(ty::ReVar(self.region_vars.new_region_var(origin)))
1033+
self.tcx.mk_region(ty::ReVar(self.region_vars.borrow_mut().new_region_var(origin)))
10321034
}
10331035

10341036
/// Create a region inference variable for the given
@@ -1124,7 +1126,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11241126
region_context,
11251127
region_map,
11261128
free_regions);
1127-
let (lexical_region_resolutions, errors) = self.region_vars.resolve_regions(&region_rels);
1129+
let (lexical_region_resolutions, errors) =
1130+
self.region_vars.borrow_mut().resolve_regions(&region_rels);
11281131

11291132
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
11301133
assert!(old_value.is_none());
@@ -1362,7 +1365,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13621365
a,
13631366
bound);
13641367

1365-
self.region_vars.verify_generic_bound(origin, kind, a, bound);
1368+
self.region_vars.borrow_mut().verify_generic_bound(origin, kind, a, bound);
13661369
}
13671370

13681371
pub fn type_moves_by_default(&self,

0 commit comments

Comments
 (0)