Skip to content

Commit 2a8ad90

Browse files
committed
Auto merge of #50197 - nikomatsakis:skolemize-out-of-tcx, r=eddyb
move skolemized regions into global tcx Experimental branch to move skolemized regions into global tcx. This is probably not what we want long term but may be convenient to unblock @sgrif in the short term. I'd like to do a perf run, though the main concern I guess would be memory usage. r? @eddyb
2 parents 357bf00 + 149ab1b commit 2a8ad90

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
409409
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
410410
let tcx = self.selcx.tcx().global_tcx();
411411
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
412-
if substs.needs_infer() {
412+
if substs.needs_infer() || substs.has_skol() {
413413
let identity_substs = Substs::identity_for_item(tcx, def_id);
414414
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
415415
if let Some(instance) = instance {

src/librustc/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
196196
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
197197
let tcx = self.infcx.tcx.global_tcx();
198198
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
199-
if substs.needs_infer() {
199+
if substs.needs_infer() || substs.has_skol() {
200200
let identity_substs = Substs::identity_for_item(tcx, def_id);
201201
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
202202
if let Some(instance) = instance {

src/librustc/ty/context.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ macro_rules! intern_method {
21192119
$alloc_method:ident,
21202120
$alloc_to_key:expr,
21212121
$alloc_to_ret:expr,
2122-
$needs_infer:expr) -> $ty:ty) => {
2122+
$keep_in_local_tcx:expr) -> $ty:ty) => {
21232123
impl<'a, 'gcx, $lt_tcx> TyCtxt<'a, 'gcx, $lt_tcx> {
21242124
pub fn $method(self, v: $alloc) -> &$lt_tcx $ty {
21252125
{
@@ -2137,7 +2137,7 @@ macro_rules! intern_method {
21372137
// HACK(eddyb) Depend on flags being accurate to
21382138
// determine that all contents are in the global tcx.
21392139
// See comments on Lift for why we can't use that.
2140-
if !($needs_infer)(&v) {
2140+
if !($keep_in_local_tcx)(&v) {
21412141
if !self.is_global() {
21422142
let v = unsafe {
21432143
mem::transmute(v)
@@ -2165,7 +2165,7 @@ macro_rules! intern_method {
21652165
}
21662166

21672167
macro_rules! direct_interners {
2168-
($lt_tcx:tt, $($name:ident: $method:ident($needs_infer:expr) -> $ty:ty),+) => {
2168+
($lt_tcx:tt, $($name:ident: $method:ident($keep_in_local_tcx:expr) -> $ty:ty),+) => {
21692169
$(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> {
21702170
fn eq(&self, other: &Self) -> bool {
21712171
self.0 == other.0
@@ -2180,7 +2180,10 @@ macro_rules! direct_interners {
21802180
}
21812181
}
21822182

2183-
intern_method!($lt_tcx, $name: $method($ty, alloc, |x| x, |x| x, $needs_infer) -> $ty);)+
2183+
intern_method!(
2184+
$lt_tcx,
2185+
$name: $method($ty, alloc, |x| x, |x| x, $keep_in_local_tcx) -> $ty
2186+
);)+
21842187
}
21852188
}
21862189

@@ -2189,12 +2192,7 @@ pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
21892192
}
21902193

21912194
direct_interners!('tcx,
2192-
region: mk_region(|r| {
2193-
match r {
2194-
&ty::ReVar(_) | &ty::ReSkolemized(..) => true,
2195-
_ => false
2196-
}
2197-
}) -> RegionKind,
2195+
region: mk_region(|r: &RegionKind| r.keep_in_local_tcx()) -> RegionKind,
21982196
const_: mk_const(|c: &Const| keep_local(&c.ty) || keep_local(&c.val)) -> Const<'tcx>
21992197
);
22002198

src/librustc/ty/fold.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9191
fn needs_infer(&self) -> bool {
9292
self.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_RE_INFER)
9393
}
94+
fn has_skol(&self) -> bool {
95+
self.has_type_flags(TypeFlags::HAS_RE_SKOL)
96+
}
9497
fn needs_subst(&self) -> bool {
9598
self.has_type_flags(TypeFlags::NEEDS_SUBST)
9699
}
@@ -111,15 +114,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
111114
self.has_type_flags(TypeFlags::HAS_FREE_REGIONS)
112115
}
113116

114-
fn is_normalized_for_trans(&self) -> bool {
115-
!self.has_type_flags(TypeFlags::HAS_RE_INFER |
116-
TypeFlags::HAS_FREE_REGIONS |
117-
TypeFlags::HAS_TY_INFER |
118-
TypeFlags::HAS_PARAMS |
119-
TypeFlags::HAS_NORMALIZABLE_PROJECTION |
120-
TypeFlags::HAS_TY_ERR |
121-
TypeFlags::HAS_SELF)
122-
}
123117
/// Indicates whether this value references only 'global'
124118
/// types/lifetimes that are the same regardless of what fn we are
125119
/// in. This is used for caching. Errs on the side of returning

src/librustc/ty/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,11 @@ impl<'tcx> ParamEnv<'tcx> {
14761476
}
14771477

14781478
Reveal::All => {
1479-
if value.needs_infer() || value.has_param_types() || value.has_self_ty() {
1479+
if value.has_skol()
1480+
|| value.needs_infer()
1481+
|| value.has_param_types()
1482+
|| value.has_self_ty()
1483+
{
14801484
ParamEnvAnd {
14811485
param_env: self,
14821486
value,

src/librustc/ty/sty.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1171,13 +1171,6 @@ impl RegionKind {
11711171
}
11721172
}
11731173

1174-
pub fn needs_infer(&self) -> bool {
1175-
match *self {
1176-
ty::ReVar(..) | ty::ReSkolemized(..) => true,
1177-
_ => false
1178-
}
1179-
}
1180-
11811174
pub fn escapes_depth(&self, depth: u32) -> bool {
11821175
match *self {
11831176
ty::ReLateBound(debruijn, _) => debruijn.depth > depth,
@@ -1195,20 +1188,29 @@ impl RegionKind {
11951188
}
11961189
}
11971190

1191+
pub fn keep_in_local_tcx(&self) -> bool {
1192+
if let ty::ReVar(..) = self {
1193+
true
1194+
} else {
1195+
false
1196+
}
1197+
}
1198+
11981199
pub fn type_flags(&self) -> TypeFlags {
11991200
let mut flags = TypeFlags::empty();
12001201

1202+
if self.keep_in_local_tcx() {
1203+
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
1204+
}
1205+
12011206
match *self {
12021207
ty::ReVar(..) => {
12031208
flags = flags | TypeFlags::HAS_FREE_REGIONS;
12041209
flags = flags | TypeFlags::HAS_RE_INFER;
1205-
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
12061210
}
12071211
ty::ReSkolemized(..) => {
12081212
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1209-
flags = flags | TypeFlags::HAS_RE_INFER;
12101213
flags = flags | TypeFlags::HAS_RE_SKOL;
1211-
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
12121214
}
12131215
ty::ReLateBound(..) => { }
12141216
ty::ReEarlyBound(..) => {

src/librustc_typeck/check/method/probe.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,10 @@ impl<'tcx> Candidate<'tcx> {
14851485
// inference variables or other artifacts. This
14861486
// means they are safe to put into the
14871487
// `WhereClausePick`.
1488-
assert!(!trait_ref.skip_binder().substs.needs_infer());
1488+
assert!(
1489+
!trait_ref.skip_binder().substs.needs_infer()
1490+
&& !trait_ref.skip_binder().substs.has_skol()
1491+
);
14891492

14901493
WhereClausePick(trait_ref.clone())
14911494
}

src/librustc_typeck/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
107107

108108
fn write_ty_to_tables(&mut self, hir_id: hir::HirId, ty: Ty<'gcx>) {
109109
debug!("write_ty_to_tables({:?}, {:?})", hir_id, ty);
110-
assert!(!ty.needs_infer());
110+
assert!(!ty.needs_infer() && !ty.has_skol());
111111
self.tables.node_types_mut().insert(hir_id, ty);
112112
}
113113

@@ -431,7 +431,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
431431
if let Some(substs) = self.fcx.tables.borrow().node_substs_opt(hir_id) {
432432
let substs = self.resolve(&substs, &span);
433433
debug!("write_substs_to_tcx({:?}, {:?})", hir_id, substs);
434-
assert!(!substs.needs_infer());
434+
assert!(!substs.needs_infer() && !substs.has_skol());
435435
self.tables.node_substs_mut().insert(hir_id, substs);
436436
}
437437
}

0 commit comments

Comments
 (0)