Skip to content

Commit 316510f

Browse files
Ariel Ben-Yehudaarielb1
authored andcommitted
split ReInfer into ReVar and ReSkolemized
this should reduce the size of ty::Region to 24 bytes (from 32), and they are treated differently in most cases anyway.
1 parent 797d0ba commit 316510f

File tree

15 files changed

+65
-76
lines changed

15 files changed

+65
-76
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
271271
ty::ReEmpty => {
272272
mywrite!(w, "e");
273273
}
274-
ty::ReInfer(_) => {
274+
ty::ReVar(_) | ty::ReSkolemized(..) => {
275275
// these should not crop up after typeck
276276
cx.diag.handler().bug("cannot encode region variables");
277277
}

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl tr for ty::Region {
498498
ty::ReScope(scope) => {
499499
ty::ReScope(scope.tr(dcx))
500500
}
501-
ty::ReEmpty | ty::ReStatic | ty::ReInfer(..) => {
501+
ty::ReEmpty | ty::ReStatic | ty::ReVar(..) | ty::ReSkolemized(..) => {
502502
*self
503503
}
504504
ty::ReFree(ref fr) => {

src/librustc/middle/infer/combine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
340340

341341
// Always make a fresh region variable for skolemized regions;
342342
// the higher-ranked decision procedures rely on this.
343-
ty::ReInfer(ty::ReSkolemized(..)) => { }
343+
ty::ReSkolemized(..) => { }
344344

345345
// For anything else, we make a region variable, unless we
346346
// are *equating*, in which case it's just wasteful.
347347
ty::ReEmpty |
348348
ty::ReStatic |
349349
ty::ReScope(..) |
350-
ty::ReInfer(ty::ReVar(..)) |
350+
ty::ReVar(..) |
351351
ty::ReFree(..) => {
352352
if !self.make_region_vars {
353353
return r;

src/librustc/middle/infer/error_reporting.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ impl<'tcx> ty::ctxt<'tcx> {
196196

197197
ty::ReEarlyBound(ref data) => (data.name.to_string(), None),
198198

199-
// I believe these cases should not occur (except when debugging,
200-
// perhaps)
201-
ty::ReInfer(_) | ty::ReLateBound(..) => {
199+
// FIXME(#13998) ReSkolemized should probably print like
200+
// ReFree rather than dumping Debug output on the user.
201+
//
202+
// We shouldn't really be having unification failures with ReVar
203+
// and ReLateBound through.
204+
ty::ReSkolemized(..) | ty::ReVar(_) | ty::ReLateBound(..) => {
202205
(format!("lifetime {:?}", region), None)
203206
}
204207
};

src/librustc/middle/infer/freshen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
9595
ty::ReStatic |
9696
ty::ReFree(_) |
9797
ty::ReScope(_) |
98-
ty::ReInfer(_) |
98+
ty::ReVar(_) |
99+
ty::ReSkolemized(..) |
99100
ty::ReEmpty => {
100101
// replace all free regions with 'static
101102
ty::ReStatic

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
335335
-> Vec<ty::RegionVid> {
336336
map.iter()
337337
.map(|(_, r)| match *r {
338-
ty::ReInfer(ty::ReVar(r)) => { r }
338+
ty::ReVar(r) => { r }
339339
r => {
340340
fields.tcx().sess.span_bug(
341341
fields.trace.origin.span(),
@@ -347,7 +347,7 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
347347

348348
fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
349349
match r {
350-
ty::ReInfer(ty::ReVar(ref v)) => new_vars.iter().any(|x| x == v),
350+
ty::ReVar(ref v) => new_vars.iter().any(|x| x == v),
351351
_ => false
352352
}
353353
}
@@ -443,7 +443,7 @@ impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
443443
}
444444

445445
region_vars.retain(|&region_vid| {
446-
let r = ty::ReInfer(ty::ReVar(region_vid));
446+
let r = ty::ReVar(region_vid);
447447
!escaping_region_vars.contains(&r)
448448
});
449449

@@ -561,7 +561,7 @@ pub fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
561561
// Each skolemized should only be relatable to itself
562562
// or new variables:
563563
match tainted_region {
564-
ty::ReInfer(ty::ReVar(vid)) => {
564+
ty::ReVar(vid) => {
565565
if new_vars.iter().any(|&x| x == vid) { continue; }
566566
}
567567
_ => {

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10591059
}
10601060

10611061
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region {
1062-
ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
1062+
ty::ReVar(self.region_vars.new_region_var(origin))
10631063
}
10641064

10651065
pub fn region_vars_for_defs(&self,

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use middle::free_region::FreeRegionMap;
2525
use middle::region;
2626
use middle::ty::{self, Ty, TypeError};
2727
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
28-
use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound};
28+
use middle::ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound};
2929
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
3030
use middle::ty_relate::RelateResult;
3131
use util::common::indenter;
@@ -373,7 +373,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
373373

374374
let sc = self.skolemization_count.get();
375375
self.skolemization_count.set(sc + 1);
376-
ReInfer(ReSkolemized(sc, br))
376+
ReSkolemized(sc, br)
377377
}
378378

379379
pub fn new_bound(&self, debruijn: ty::DebruijnIndex) -> Region {
@@ -510,13 +510,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
510510
(_, ReStatic) => {
511511
// all regions are subregions of static, so we can ignore this
512512
}
513-
(ReInfer(ReVar(sub_id)), ReInfer(ReVar(sup_id))) => {
513+
(ReVar(sub_id), ReVar(sup_id)) => {
514514
self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin);
515515
}
516-
(r, ReInfer(ReVar(sup_id))) => {
516+
(r, ReVar(sup_id)) => {
517517
self.add_constraint(ConstrainRegSubVar(r, sup_id), origin);
518518
}
519-
(ReInfer(ReVar(sub_id)), r) => {
519+
(ReVar(sub_id), r) => {
520520
self.add_constraint(ConstrainVarSubReg(sub_id, r), origin);
521521
}
522522
_ => {
@@ -621,7 +621,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
621621
let vars = TwoRegions { a: a, b: b };
622622
match self.combine_map(t).borrow().get(&vars) {
623623
Some(&c) => {
624-
return ReInfer(ReVar(c));
624+
return ReVar(c);
625625
}
626626
None => {}
627627
}
@@ -630,10 +630,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
630630
if self.in_snapshot() {
631631
self.undo_log.borrow_mut().push(AddCombination(t, vars));
632632
}
633-
relate(self, a, ReInfer(ReVar(c)));
634-
relate(self, b, ReInfer(ReVar(c)));
633+
relate(self, a, ReVar(c));
634+
relate(self, b, ReVar(c));
635635
debug!("combine_vars() c={:?}", c);
636-
ReInfer(ReVar(c))
636+
ReVar(c)
637637
}
638638

639639
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot)
@@ -672,22 +672,22 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
672672
&AddConstraint(ConstrainVarSubVar(a, b)) => {
673673
consider_adding_bidirectional_edges(
674674
&mut result_set, r,
675-
ReInfer(ReVar(a)), ReInfer(ReVar(b)));
675+
ReVar(a), ReVar(b));
676676
}
677677
&AddConstraint(ConstrainRegSubVar(a, b)) => {
678678
consider_adding_bidirectional_edges(
679679
&mut result_set, r,
680-
a, ReInfer(ReVar(b)));
680+
a, ReVar(b));
681681
}
682682
&AddConstraint(ConstrainVarSubReg(a, b)) => {
683683
consider_adding_bidirectional_edges(
684684
&mut result_set, r,
685-
ReInfer(ReVar(a)), b);
685+
ReVar(a), b);
686686
}
687687
&AddGiven(a, b) => {
688688
consider_adding_bidirectional_edges(
689689
&mut result_set, r,
690-
ReFree(a), ReInfer(ReVar(b)));
690+
ReFree(a), ReVar(b));
691691
}
692692
&AddVerify(i) => {
693693
match (*self.verifys.borrow())[i] {
@@ -775,7 +775,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
775775
r // everything lives longer than empty
776776
}
777777

778-
(ReInfer(ReVar(v_id)), _) | (_, ReInfer(ReVar(v_id))) => {
778+
(ReVar(v_id), _) | (_, ReVar(v_id)) => {
779779
self.tcx.sess.span_bug(
780780
(*self.var_origins.borrow())[v_id.index as usize].span(),
781781
&format!("lub_concrete_regions invoked with \
@@ -818,8 +818,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
818818

819819
// For these types, we cannot define any additional
820820
// relationship:
821-
(ReInfer(ReSkolemized(..)), _) |
822-
(_, ReInfer(ReSkolemized(..))) => {
821+
(ReSkolemized(..), _) |
822+
(_, ReSkolemized(..)) => {
823823
if a == b {a} else {ReStatic}
824824
}
825825
}
@@ -853,8 +853,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
853853
Ok(ReEmpty)
854854
}
855855

856-
(ReInfer(ReVar(v_id)), _) |
857-
(_, ReInfer(ReVar(v_id))) => {
856+
(ReVar(v_id), _) |
857+
(_, ReVar(v_id)) => {
858858
self.tcx.sess.span_bug(
859859
(*self.var_origins.borrow())[v_id.index as usize].span(),
860860
&format!("glb_concrete_regions invoked with \
@@ -890,8 +890,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
890890

891891
// For these types, we cannot define any additional
892892
// relationship:
893-
(ReInfer(ReSkolemized(..)), _) |
894-
(_, ReInfer(ReSkolemized(..))) => {
893+
(ReSkolemized(..), _) |
894+
(_, ReSkolemized(..)) => {
895895
if a == b {
896896
Ok(a)
897897
} else {
@@ -1632,7 +1632,7 @@ impl<'tcx> fmt::Debug for Verify<'tcx> {
16321632

16331633
fn normalize(values: &Vec<VarValue>, r: ty::Region) -> ty::Region {
16341634
match r {
1635-
ty::ReInfer(ReVar(rid)) => lookup(values, rid),
1635+
ty::ReVar(rid) => lookup(values, rid),
16361636
_ => r
16371637
}
16381638
}

src/librustc/middle/infer/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
106106

107107
fn fold_region(&mut self, r: ty::Region) -> ty::Region {
108108
match r {
109-
ty::ReInfer(ty::ReVar(rid)) => self.infcx.region_vars.resolve_var(rid),
109+
ty::ReVar(rid) => self.infcx.region_vars.resolve_var(rid),
110110
_ => r,
111111
}
112112
}

src/librustc/middle/ty.rs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![allow(non_camel_case_types)]
1313

1414
pub use self::InferTy::*;
15-
pub use self::InferRegion::*;
1615
pub use self::ImplOrTraitItemId::*;
1716
pub use self::ClosureKind::*;
1817
pub use self::Variance::*;
@@ -1529,7 +1528,11 @@ pub enum Region {
15291528
ReStatic,
15301529

15311530
/// A region variable. Should not exist after typeck.
1532-
ReInfer(InferRegion),
1531+
ReVar(RegionVid),
1532+
1533+
/// A skolemized region - basically the higher-ranked version of ReFree.
1534+
/// Should not exist after typeck.
1535+
ReSkolemized(u32, BoundRegion),
15331536

15341537
/// Empty lifetime is for data that is never accessed.
15351538
/// Bottom in the region lattice. We treat ReEmpty somewhat
@@ -1648,7 +1651,7 @@ impl Region {
16481651

16491652
pub fn needs_infer(&self) -> bool {
16501653
match *self {
1651-
ty::ReInfer(..) => true,
1654+
ty::ReVar(..) | ty::ReSkolemized(..) => true,
16521655
_ => false
16531656
}
16541657
}
@@ -2187,29 +2190,6 @@ pub enum UnconstrainedNumeric {
21872190
}
21882191

21892192

2190-
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash, Debug, Copy)]
2191-
pub enum InferRegion {
2192-
ReVar(RegionVid),
2193-
ReSkolemized(u32, BoundRegion)
2194-
}
2195-
2196-
impl cmp::PartialEq for InferRegion {
2197-
fn eq(&self, other: &InferRegion) -> bool {
2198-
match ((*self), *other) {
2199-
(ReVar(rva), ReVar(rvb)) => {
2200-
rva == rvb
2201-
}
2202-
(ReSkolemized(rva, _), ReSkolemized(rvb, _)) => {
2203-
rva == rvb
2204-
}
2205-
_ => false
2206-
}
2207-
}
2208-
fn ne(&self, other: &InferRegion) -> bool {
2209-
!((*self) == (*other))
2210-
}
2211-
}
2212-
22132193
impl fmt::Debug for TyVid {
22142194
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22152195
write!(f, "_#{}t", self.index)
@@ -3722,7 +3702,8 @@ impl FlagComputation {
37223702

37233703
fn add_region(&mut self, r: Region) {
37243704
match r {
3725-
ty::ReInfer(_) => { self.add_flags(TypeFlags::HAS_RE_INFER); }
3705+
ty::ReVar(..) |
3706+
ty::ReSkolemized(..) => { self.add_flags(TypeFlags::HAS_RE_INFER); }
37263707
ty::ReLateBound(debruijn, _) => { self.add_depth(debruijn.depth); }
37273708
ty::ReEarlyBound(..) => { self.add_flags(TypeFlags::HAS_RE_EARLY_BOUND); }
37283709
ty::ReStatic => {}
@@ -5728,7 +5709,7 @@ impl<'tcx> ctxt<'tcx> {
57285709
self.note_and_explain_region("concrete lifetime that was found is ",
57295710
conc_region, "");
57305711
}
5731-
RegionsOverlyPolymorphic(_, ty::ReInfer(ty::ReVar(_))) => {
5712+
RegionsOverlyPolymorphic(_, ty::ReVar(_)) => {
57325713
// don't bother to print out the message below for
57335714
// inference variables, it's not very illuminating.
57345715
}
@@ -6479,7 +6460,8 @@ impl<'tcx> ctxt<'tcx> {
64796460
ReLateBound(..) |
64806461
ReFree(..) |
64816462
ReScope(..) |
6482-
ReInfer(..) => {
6463+
ReVar(..) |
6464+
ReSkolemized(..) => {
64836465
tcx.sess.bug("unexpected region found when hashing a type")
64846466
}
64856467
}
@@ -7338,8 +7320,9 @@ impl HasTypeFlags for Region {
73387320
}
73397321
}
73407322
if flags.intersects(TypeFlags::HAS_RE_INFER) {
7341-
if let ty::ReInfer(_) = *self {
7342-
return true;
7323+
match *self {
7324+
ty::ReVar(_) | ty::ReSkolemized(..) => { return true }
7325+
_ => {}
73437326
}
73447327
}
73457328
false

src/librustc/util/ppaux.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use middle::def_id::DefId;
1313
use middle::subst::{self, Subst};
1414
use middle::ty::{BoundRegion, BrAnon, BrNamed};
1515
use middle::ty::{ReEarlyBound, BrFresh, ctxt};
16-
use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
16+
use middle::ty::{ReFree, ReScope, ReStatic, Region, ReEmpty};
1717
use middle::ty::{ReSkolemized, ReVar, BrEnv};
1818
use middle::ty::{TyBool, TyChar, TyStruct, TyEnum};
1919
use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
@@ -413,11 +413,11 @@ impl fmt::Debug for ty::Region {
413413

414414
ty::ReStatic => write!(f, "ReStatic"),
415415

416-
ty::ReInfer(ReVar(ref vid)) => {
416+
ty::ReVar(ref vid) => {
417417
write!(f, "{:?}", vid)
418418
}
419419

420-
ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
420+
ty::ReSkolemized(id, ref bound_region) => {
421421
write!(f, "ReSkolemized({}, {:?})", id, bound_region)
422422
}
423423

@@ -442,11 +442,11 @@ impl fmt::Display for ty::Region {
442442
}
443443
ty::ReLateBound(_, br) |
444444
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
445-
ty::ReInfer(ReSkolemized(_, br)) => {
445+
ty::ReSkolemized(_, br) => {
446446
write!(f, "{}", br)
447447
}
448448
ty::ReScope(_) |
449-
ty::ReInfer(ReVar(_)) => Ok(()),
449+
ty::ReVar(_) => Ok(()),
450450
ty::ReStatic => write!(f, "'static"),
451451
ty::ReEmpty => write!(f, "'<empty>"),
452452
}

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
377377
ty::ReEmpty |
378378
ty::ReLateBound(..) |
379379
ty::ReEarlyBound(..) |
380-
ty::ReInfer(..) => {
380+
ty::ReVar(..) |
381+
ty::ReSkolemized(..) => {
381382
self.tcx().sess.span_bug(
382383
cmt.span,
383384
&format!("invalid borrow lifetime: {:?}",

0 commit comments

Comments
 (0)