Skip to content

Commit ff35eeb

Browse files
committed
Recycle skolemization counts and add some comments.
1 parent 7be059f commit ff35eeb

File tree

2 files changed

+27
-4
lines changed
  • src/librustc/middle/infer

2 files changed

+27
-4
lines changed

src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
7676
// fresh concrete region.
7777
let (b_prime, skol_map) = {
7878
replace_late_bound_regions(self.tcx(), b, |br, _| {
79-
let skol = self.infcx().region_vars.new_skolemized(br);
79+
let skol =
80+
self.infcx().region_vars.new_skolemized(
81+
br, &snapshot.region_vars_snapshot);
8082
debug!("Bound region {} skolemized to {}",
8183
bound_region_to_string(self.tcx(), "", false, br),
8284
skol);

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ pub struct RegionVarBindings<'a, 'tcx: 'a> {
226226
#[deriving(Show)]
227227
#[allow(missing_copy_implementations)]
228228
pub struct RegionSnapshot {
229-
length: uint
229+
length: uint,
230+
skolemization_count: uint,
230231
}
231232

232233
impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
@@ -254,7 +255,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
254255
let length = self.undo_log.borrow().len();
255256
debug!("RegionVarBindings: start_snapshot({})", length);
256257
self.undo_log.borrow_mut().push(OpenSnapshot);
257-
RegionSnapshot { length: length }
258+
RegionSnapshot { length: length, skolemization_count: self.skolemization_count.get() }
258259
}
259260

260261
pub fn commit(&self, snapshot: RegionSnapshot) {
@@ -268,6 +269,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
268269
} else {
269270
(*undo_log)[snapshot.length] = CommitedSnapshot;
270271
}
272+
self.skolemization_count.set(snapshot.skolemization_count);
271273
}
272274

273275
pub fn rollback_to(&self, snapshot: RegionSnapshot) {
@@ -306,6 +308,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
306308
}
307309
let c = undo_log.pop().unwrap();
308310
assert!(c == OpenSnapshot);
311+
self.skolemization_count.set(snapshot.skolemization_count);
309312
}
310313

311314
pub fn num_vars(&self) -> uint {
@@ -324,7 +327,25 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
324327
return vid;
325328
}
326329

327-
pub fn new_skolemized(&self, br: ty::BoundRegion) -> Region {
330+
/// Creates a new skolemized region. Skolemized regions are fresh
331+
/// regions used when performing higher-ranked computations. They
332+
/// must be used in a very particular way and are never supposed
333+
/// to "escape" out into error messages or the code at large.
334+
///
335+
/// The idea is to always create a snapshot. Skolemized regions
336+
/// can be created in the context of this snapshot, but once the
337+
/// snapshot is commited or rolled back, their numbers will be
338+
/// recycled, so you must be finished with them. See the extensive
339+
/// comments in `higher_ranked.rs` to see how it works (in
340+
/// particular, the subtyping comparison).
341+
///
342+
/// The `snapshot` argument to this function is not really used;
343+
/// it's just there to make it explicit which snapshot bounds the
344+
/// skolemized region that results.
345+
pub fn new_skolemized(&self, br: ty::BoundRegion, snapshot: &RegionSnapshot) -> Region {
346+
assert!(self.in_snapshot());
347+
assert!(self.undo_log.borrow()[snapshot.length] == OpenSnapshot);
348+
328349
let sc = self.skolemization_count.get();
329350
self.skolemization_count.set(sc + 1);
330351
ReInfer(ReSkolemized(sc, br))

0 commit comments

Comments
 (0)