@@ -226,7 +226,8 @@ pub struct RegionVarBindings<'a, 'tcx: 'a> {
226
226
#[ deriving( Show ) ]
227
227
#[ allow( missing_copy_implementations) ]
228
228
pub struct RegionSnapshot {
229
- length : uint
229
+ length : uint ,
230
+ skolemization_count : uint ,
230
231
}
231
232
232
233
impl < ' a , ' tcx > RegionVarBindings < ' a , ' tcx > {
@@ -254,7 +255,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
254
255
let length = self . undo_log . borrow ( ) . len ( ) ;
255
256
debug ! ( "RegionVarBindings: start_snapshot({})" , length) ;
256
257
self . undo_log . borrow_mut ( ) . push ( OpenSnapshot ) ;
257
- RegionSnapshot { length : length }
258
+ RegionSnapshot { length : length, skolemization_count : self . skolemization_count . get ( ) }
258
259
}
259
260
260
261
pub fn commit ( & self , snapshot : RegionSnapshot ) {
@@ -268,6 +269,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
268
269
} else {
269
270
( * undo_log) [ snapshot. length ] = CommitedSnapshot ;
270
271
}
272
+ self . skolemization_count . set ( snapshot. skolemization_count ) ;
271
273
}
272
274
273
275
pub fn rollback_to ( & self , snapshot : RegionSnapshot ) {
@@ -306,6 +308,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
306
308
}
307
309
let c = undo_log. pop ( ) . unwrap ( ) ;
308
310
assert ! ( c == OpenSnapshot ) ;
311
+ self . skolemization_count . set ( snapshot. skolemization_count ) ;
309
312
}
310
313
311
314
pub fn num_vars ( & self ) -> uint {
@@ -324,7 +327,25 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
324
327
return vid;
325
328
}
326
329
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
+
328
349
let sc = self . skolemization_count . get ( ) ;
329
350
self . skolemization_count . set ( sc + 1 ) ;
330
351
ReInfer ( ReSkolemized ( sc, br) )
0 commit comments