Skip to content

Commit f9cda89

Browse files
committed
extract the tcx out from RegionVarBindings
1 parent 11b1b60 commit f9cda89

File tree

10 files changed

+89
-80
lines changed

10 files changed

+89
-80
lines changed

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(origin, a, b))
70+
Ok(self.fields.infcx.region_vars.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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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(debruijn)
430+
infcx.region_vars.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(&snapshot.region_vars_snapshot, r, directions)
484+
self.region_vars.tainted(self.tcx, &snapshot.region_vars_snapshot, r, directions)
485485
}
486486

487487
fn region_vars_confined_to_snapshot(&self,
@@ -581,7 +581,7 @@ 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(br, &snapshot.region_vars_snapshot)
584+
self.region_vars.push_skolemized(self.tcx, br, &snapshot.region_vars_snapshot)
585585
});
586586

587587
debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
@@ -766,7 +766,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
766766
{
767767
debug!("pop_skolemized({:?})", skol_map);
768768
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
769-
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
769+
self.region_vars.pop_skolemized(self.tcx, &skol_regions, &snapshot.region_vars_snapshot);
770770
if !skol_map.is_empty() {
771771
self.projection_cache.borrow_mut().rollback_skolemized(
772772
&snapshot.projection_cache_snapshot);

src/librustc/infer/lexical_region_resolve/graphviz.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ graphs will be printed. \n\
5757
}
5858

5959
pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
60-
region_vars: &RegionVarBindings<'a, 'gcx, 'tcx>,
60+
region_vars: &RegionVarBindings<'tcx>,
6161
region_rels: &RegionRelations<'a, 'gcx, 'tcx>)
6262
{
63+
let tcx = region_rels.tcx;
6364
let context = region_rels.context;
6465

65-
if !region_vars.tcx.sess.opts.debugging_opts.print_region_graph {
66+
if !tcx.sess.opts.debugging_opts.print_region_graph {
6667
return;
6768
}
6869

@@ -117,7 +118,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
117118
Ok(()) => {}
118119
Err(e) => {
119120
let msg = format!("io error dumping region constraints: {}", e);
120-
region_vars.tcx.sess.err(&msg)
121+
tcx.sess.err(&msg)
121122
}
122123
}
123124
}

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_data_structures::fx::FxHashSet;
2121
use rustc_data_structures::graph::{self, Direction, NodeIndex, OUTGOING};
2222
use std::fmt;
2323
use std::u32;
24-
use ty;
24+
use ty::{self, TyCtxt};
2525
use ty::{Region, RegionVid};
2626
use ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic};
2727
use ty::{ReLateBound, ReScope, ReSkolemized, ReVar};
@@ -73,15 +73,15 @@ struct RegionAndOrigin<'tcx> {
7373

7474
type RegionGraph<'tcx> = graph::Graph<(), Constraint<'tcx>>;
7575

76-
impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
76+
impl<'tcx> RegionVarBindings<'tcx> {
7777
/// This function performs the actual region resolution. It must be
7878
/// called after all constraints have been added. It performs a
7979
/// fixed-point iteration to find region values which satisfy all
8080
/// constraints, assuming such values can be found; if they cannot,
8181
/// errors are reported.
8282
pub fn resolve_regions(
8383
&self,
84-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
84+
region_rels: &RegionRelations<'_, '_, 'tcx>,
8585
) -> (
8686
LexicalRegionResolutions<'tcx>,
8787
Vec<RegionResolutionError<'tcx>>,
@@ -94,10 +94,11 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
9494

9595
fn lub_concrete_regions(
9696
&self,
97-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
97+
region_rels: &RegionRelations<'_, '_, 'tcx>,
9898
a: Region<'tcx>,
9999
b: Region<'tcx>,
100100
) -> Region<'tcx> {
101+
let tcx = region_rels.tcx;
101102
match (a, b) {
102103
(&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => {
103104
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
@@ -130,10 +131,10 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
130131
// reasonably compare free regions and scopes:
131132
let fr_scope = match (a, b) {
132133
(&ReEarlyBound(ref br), _) | (_, &ReEarlyBound(ref br)) => {
133-
region_rels.region_scope_tree.early_free_scope(self.tcx, br)
134+
region_rels.region_scope_tree.early_free_scope(region_rels.tcx, br)
134135
}
135136
(&ReFree(ref fr), _) | (_, &ReFree(ref fr)) => {
136-
region_rels.region_scope_tree.free_scope(self.tcx, fr)
137+
region_rels.region_scope_tree.free_scope(region_rels.tcx, fr)
137138
}
138139
_ => bug!(),
139140
};
@@ -153,7 +154,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
153154

154155
// otherwise, we don't know what the free region is,
155156
// so we must conservatively say the LUB is static:
156-
self.tcx.types.re_static
157+
tcx.types.re_static
157158
}
158159

159160
(&ReScope(a_id), &ReScope(b_id)) => {
@@ -163,7 +164,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
163164
let lub = region_rels
164165
.region_scope_tree
165166
.nearest_common_ancestor(a_id, b_id);
166-
self.tcx.mk_region(ReScope(lub))
167+
tcx.mk_region(ReScope(lub))
167168
}
168169

169170
(&ReEarlyBound(_), &ReEarlyBound(_)) |
@@ -176,17 +177,17 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
176177
(&ReSkolemized(..), _) | (_, &ReSkolemized(..)) => if a == b {
177178
a
178179
} else {
179-
self.tcx.types.re_static
180+
tcx.types.re_static
180181
},
181182
}
182183
}
183184

184185
fn infer_variable_values(
185186
&self,
186-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
187+
region_rels: &RegionRelations<'_, '_, 'tcx>,
187188
errors: &mut Vec<RegionResolutionError<'tcx>>,
188189
) -> LexicalRegionResolutions<'tcx> {
189-
let mut var_data = self.construct_var_data();
190+
let mut var_data = self.construct_var_data(region_rels.tcx);
190191

191192
// Dorky hack to cause `dump_constraints` to only get called
192193
// if debug mode is enabled:
@@ -205,16 +206,18 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
205206
var_data
206207
}
207208

208-
fn construct_var_data(&self) -> LexicalRegionResolutions<'tcx> {
209+
/// Initially, the value for all variables is set to `'empty`, the
210+
/// empty region. The `expansion` phase will grow this larger.
211+
fn construct_var_data(&self, tcx: TyCtxt<'_, '_, 'tcx>) -> LexicalRegionResolutions<'tcx> {
209212
LexicalRegionResolutions {
210-
error_region: self.tcx.types.re_static,
213+
error_region: tcx.types.re_static,
211214
values: (0..self.num_vars() as usize)
212-
.map(|_| VarValue::Value(self.tcx.types.re_empty))
215+
.map(|_| VarValue::Value(tcx.types.re_empty))
213216
.collect(),
214217
}
215218
}
216219

217-
fn dump_constraints(&self, free_regions: &RegionRelations<'a, 'gcx, 'tcx>) {
220+
fn dump_constraints(&self, free_regions: &RegionRelations<'_, '_, 'tcx>) {
218221
debug!(
219222
"----() Start constraint listing (context={:?}) ()----",
220223
free_regions.context
@@ -251,7 +254,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
251254

252255
fn expansion(
253256
&self,
254-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
257+
region_rels: &RegionRelations<'_, '_, 'tcx>,
255258
var_values: &mut LexicalRegionResolutions<'tcx>,
256259
) {
257260
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
@@ -279,7 +282,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
279282

280283
fn expand_node(
281284
&self,
282-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
285+
region_rels: &RegionRelations<'_, '_, 'tcx>,
283286
a_region: Region<'tcx>,
284287
b_vid: RegionVid,
285288
b_data: &mut VarValue<'tcx>,
@@ -326,7 +329,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
326329
/// and check that they are satisfied.
327330
fn collect_errors(
328331
&self,
329-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
332+
region_rels: &RegionRelations<'_, '_, 'tcx>,
330333
var_data: &mut LexicalRegionResolutions<'tcx>,
331334
errors: &mut Vec<RegionResolutionError<'tcx>>,
332335
) {
@@ -423,7 +426,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
423426
/// and create a `RegionResolutionError` for each of them.
424427
fn collect_var_errors(
425428
&self,
426-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
429+
region_rels: &RegionRelations<'_, '_, 'tcx>,
427430
var_data: &LexicalRegionResolutions<'tcx>,
428431
graph: &RegionGraph<'tcx>,
429432
errors: &mut Vec<RegionResolutionError<'tcx>>,
@@ -528,7 +531,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
528531

529532
fn collect_error_for_expanding_node(
530533
&self,
531-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
534+
region_rels: &RegionRelations<'_, '_, 'tcx>,
532535
graph: &RegionGraph<'tcx>,
533536
dup_vec: &mut [u32],
534537
node_idx: RegionVid,
@@ -642,8 +645,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
642645
} = state;
643646
return (result, dup_found);
644647

645-
fn process_edges<'a, 'gcx, 'tcx>(
646-
this: &RegionVarBindings<'a, 'gcx, 'tcx>,
648+
fn process_edges<'tcx>(
649+
this: &RegionVarBindings<'tcx>,
647650
state: &mut WalkState<'tcx>,
648651
graph: &RegionGraph<'tcx>,
649652
source_vid: RegionVid,
@@ -710,10 +713,10 @@ impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
710713
}
711714

712715

713-
impl<'a, 'gcx, 'tcx> VerifyBound<'tcx> {
716+
impl<'tcx> VerifyBound<'tcx> {
714717
fn is_met(
715718
&self,
716-
region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
719+
region_rels: &RegionRelations<'_, '_, 'tcx>,
717720
var_values: &LexicalRegionResolutions<'tcx>,
718721
min: ty::Region<'tcx>,
719722
) -> bool {

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(origin, a, b))
70+
Ok(self.fields.infcx.region_vars.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: 2 additions & 6 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<'a, 'gcx, 'tcx>,
107+
region_vars: 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(tcx),
427+
region_vars: RegionVarBindings::new(),
428428
lexical_region_resolutions: RefCell::new(None),
429429
selection_cache: traits::SelectionCache::new(),
430430
evaluation_cache: traits::EvaluationCache::new(),
@@ -1087,10 +1087,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10871087
})
10881088
}
10891089

1090-
pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region<'tcx> {
1091-
self.region_vars.new_bound(debruijn)
1092-
}
1093-
10941090
/// True if errors have been reported since this infcx was
10951091
/// created. This is sometimes used as a heuristic to skip
10961092
/// reporting errors that often occur as a result of earlier

0 commit comments

Comments
 (0)