Skip to content

Commit 11f6096

Browse files
committed
Auto merge of #70860 - lcnr:has_local_value, r=nikomatsakis
remove `KEEP_IN_LOCAL_TCX` flag closes #70285 I did not rename `needs_infer` here as this complex enough as is. Will probably open a followup for that. r? @eddyb
2 parents d249d75 + fca7d16 commit 11f6096

File tree

15 files changed

+44
-58
lines changed

15 files changed

+44
-58
lines changed

src/librustc_infer/infer/canonical/canonicalizer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
488488
V: TypeFoldable<'tcx>,
489489
{
490490
let needs_canonical_flags = if canonicalize_region_mode.any() {
491-
TypeFlags::KEEP_IN_LOCAL_TCX |
491+
TypeFlags::NEEDS_INFER |
492492
TypeFlags::HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS`
493493
TypeFlags::HAS_TY_PLACEHOLDER |
494494
TypeFlags::HAS_CT_PLACEHOLDER
495495
} else {
496-
TypeFlags::KEEP_IN_LOCAL_TCX
496+
TypeFlags::NEEDS_INFER
497497
| TypeFlags::HAS_RE_PLACEHOLDER
498498
| TypeFlags::HAS_TY_PLACEHOLDER
499499
| TypeFlags::HAS_CT_PLACEHOLDER
@@ -524,7 +524,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
524524
// Once we have canonicalized `out_value`, it should not
525525
// contain anything that ties it to this inference context
526526
// anymore, so it should live in the global arena.
527-
debug_assert!(!out_value.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX));
527+
debug_assert!(!out_value.needs_infer());
528528

529529
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables);
530530

src/librustc_infer/infer/resolve.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
181181
}
182182

183183
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
184-
if !t.needs_infer() && !ty::keep_local(&t) {
184+
if !t.needs_infer() {
185185
t // micro-optimize -- if there is nothing in this type that this fold affects...
186-
// ^ we need to have the `keep_local` check to un-default
187-
// defaulted tuples.
188186
} else {
189187
let t = self.infcx.shallow_resolve(t);
190188
match t.kind {
@@ -222,10 +220,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
222220
}
223221

224222
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
225-
if !c.needs_infer() && !ty::keep_local(&c) {
223+
if !c.needs_infer() {
226224
c // micro-optimize -- if there is nothing in this const that this fold affects...
227-
// ^ we need to have the `keep_local` check to un-default
228-
// defaulted tuples.
229225
} else {
230226
let c = self.infcx.shallow_resolve(c);
231227
match c.val {

src/librustc_middle/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2065,10 +2065,6 @@ macro_rules! direct_interners {
20652065
}
20662066
}
20672067

2068-
pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
2069-
x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX)
2070-
}
2071-
20722068
direct_interners!(
20732069
region: mk_region(RegionKind),
20742070
goal: mk_goal(GoalKind<'tcx>),

src/librustc_middle/ty/erase_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TypeFolder<'tcx> for RegionEraserVisitor<'tcx> {
4040
}
4141

4242
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
43-
if ty.has_local_value() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
43+
if ty.needs_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
4444
}
4545

4646
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>

src/librustc_middle/ty/flags.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,12 @@ impl FlagComputation {
109109
}
110110

111111
&ty::Infer(infer) => {
112-
self.add_flags(TypeFlags::HAS_TY_INFER);
113112
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
114113
match infer {
115114
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {}
116115

117116
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => {
118-
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
117+
self.add_flags(TypeFlags::HAS_TY_INFER)
119118
}
120119
}
121120
}
@@ -221,11 +220,10 @@ impl FlagComputation {
221220
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
222221
}
223222
ty::ConstKind::Infer(infer) => {
224-
self.add_flags(TypeFlags::HAS_CT_INFER);
225223
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
226224
match infer {
227225
InferConst::Fresh(_) => {}
228-
InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX),
226+
InferConst::Var(_) => self.add_flags(TypeFlags::HAS_CT_INFER),
229227
}
230228
}
231229
ty::ConstKind::Bound(debruijn, _) => {

src/librustc_middle/ty/fold.rs

-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9696
fn has_infer_consts(&self) -> bool {
9797
self.has_type_flags(TypeFlags::HAS_CT_INFER)
9898
}
99-
fn has_local_value(&self) -> bool {
100-
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
101-
}
10299
fn needs_infer(&self) -> bool {
103100
self.has_type_flags(TypeFlags::NEEDS_INFER)
104101
}

src/librustc_middle/ty/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub use crate::ty::diagnostics::*;
7171
pub use self::binding::BindingMode;
7272
pub use self::binding::BindingMode::*;
7373

74-
pub use self::context::{keep_local, tls, FreeRegionInfo, TyCtxt};
74+
pub use self::context::{tls, FreeRegionInfo, TyCtxt};
7575
pub use self::context::{
7676
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
7777
UserType, UserTypeAnnotationIndex,
@@ -577,27 +577,23 @@ bitflags! {
577577
| TypeFlags::HAS_TY_OPAQUE.bits
578578
| TypeFlags::HAS_CT_PROJECTION.bits;
579579

580-
/// Present if the type belongs in a local type context.
581-
/// Set for placeholders and inference variables that are not "Fresh".
582-
const KEEP_IN_LOCAL_TCX = 1 << 13;
583-
584580
/// Is an error type reachable?
585-
const HAS_TY_ERR = 1 << 14;
581+
const HAS_TY_ERR = 1 << 13;
586582

587583
/// Does this have any region that "appears free" in the type?
588584
/// Basically anything but [ReLateBound] and [ReErased].
589-
const HAS_FREE_REGIONS = 1 << 15;
585+
const HAS_FREE_REGIONS = 1 << 14;
590586

591587
/// Does this have any [ReLateBound] regions? Used to check
592588
/// if a global bound is safe to evaluate.
593-
const HAS_RE_LATE_BOUND = 1 << 16;
589+
const HAS_RE_LATE_BOUND = 1 << 15;
594590

595591
/// Does this have any [ReErased] regions?
596-
const HAS_RE_ERASED = 1 << 17;
592+
const HAS_RE_ERASED = 1 << 16;
597593

598594
/// Does this value have parameters/placeholders/inference variables which could be
599595
/// replaced later, in a way that would change the results of `impl` specialization?
600-
const STILL_FURTHER_SPECIALIZABLE = 1 << 18;
596+
const STILL_FURTHER_SPECIALIZABLE = 1 << 17;
601597
}
602598
}
603599

src/librustc_middle/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
510510
let tcx = relation.tcx();
511511

512512
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| {
513-
if !x.val.has_local_value() {
513+
if !x.val.needs_infer() {
514514
return x.eval(tcx, relation.param_env()).val;
515515
}
516516
x.val

src/librustc_middle/ty/sty.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ impl RegionKind {
16051605
flags = flags | TypeFlags::HAS_FREE_REGIONS;
16061606
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
16071607
flags = flags | TypeFlags::HAS_RE_INFER;
1608-
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
16091608
flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE;
16101609
}
16111610
ty::RePlaceholder(..) => {
@@ -2361,8 +2360,8 @@ impl<'tcx> Const<'tcx> {
23612360
let try_const_eval = |did, param_env: ParamEnv<'tcx>, substs, promoted| {
23622361
let param_env_and_substs = param_env.with_reveal_all().and(substs);
23632362

2364-
// Avoid querying `tcx.const_eval(...)` with any e.g. inference vars.
2365-
if param_env_and_substs.has_local_value() {
2363+
// Avoid querying `tcx.const_eval(...)` with any inference vars.
2364+
if param_env_and_substs.needs_infer() {
23662365
return None;
23672366
}
23682367

@@ -2377,12 +2376,12 @@ impl<'tcx> Const<'tcx> {
23772376

23782377
match self.val {
23792378
ConstKind::Unevaluated(did, substs, promoted) => {
2380-
// HACK(eddyb) when substs contain e.g. inference variables,
2379+
// HACK(eddyb) when substs contain inference variables,
23812380
// attempt using identity substs instead, that will succeed
23822381
// when the expression doesn't depend on any parameters.
23832382
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
23842383
// we can call `infcx.const_eval_resolve` which handles inference variables.
2385-
if substs.has_local_value() {
2384+
if substs.needs_infer() {
23862385
let identity_substs = InternalSubsts::identity_for_item(tcx, did);
23872386
// The `ParamEnv` needs to match the `identity_substs`.
23882387
let identity_param_env = tcx.param_env(did);

src/librustc_mir/borrow_check/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -995,15 +995,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
995995
self.definitions[upper_bound].external_name.unwrap_or(r)
996996
} else {
997997
// In the case of a failure, use a `ReVar` result. This will
998-
// cause the `has_local_value` later on to return `None`.
998+
// cause the `needs_infer` later on to return `None`.
999999
r
10001000
}
10011001
});
10021002

10031003
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
10041004

1005-
// `has_local_value` will only be true if we failed to promote some region.
1006-
if ty.has_local_value() {
1005+
// `needs_infer` will only be true if we failed to promote some region.
1006+
if ty.needs_infer() {
10071007
return None;
10081008
}
10091009

src/librustc_trait_selection/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4343
) -> bool {
4444
let ty = self.resolve_vars_if_possible(&ty);
4545

46-
if !(param_env, ty).has_local_value() {
46+
if !(param_env, ty).needs_infer() {
4747
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
4848
}
4949

src/librustc_trait_selection/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ fn do_normalize_predicates<'tcx>(
259259
return Err(ErrorReported);
260260
}
261261
};
262-
if predicates.has_local_value() {
263-
// FIXME: shouldn't we, you know, actually report an error here? or an ICE?
262+
if predicates.needs_infer() {
263+
tcx.sess.delay_span_bug(span, "encountered inference variables after `fully_resolve`");
264264
Err(ErrorReported)
265265
} else {
266266
Ok(predicates)

src/librustc_trait_selection/traits/select.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
820820
}
821821

822822
if self.can_use_global_caches(param_env) {
823-
if !trait_ref.has_local_value() {
823+
if !trait_ref.needs_infer() {
824824
debug!(
825825
"insert_evaluation_cache(trait_ref={:?}, candidate={:?}) global",
826826
trait_ref, result,
@@ -1178,10 +1178,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11781178
/// Do note that if the type itself is not in the
11791179
/// global tcx, the local caches will be used.
11801180
fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
1181-
// If there are any e.g. inference variables in the `ParamEnv`, then we
1181+
// If there are any inference variables in the `ParamEnv`, then we
11821182
// always use a cache local to this particular scope. Otherwise, we
11831183
// switch to a global cache.
1184-
if param_env.has_local_value() {
1184+
if param_env.needs_infer() {
11851185
return false;
11861186
}
11871187

@@ -1242,7 +1242,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12421242
result: &SelectionResult<'tcx, SelectionCandidate<'tcx>>,
12431243
) -> bool {
12441244
match result {
1245-
Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.has_local_value(),
1245+
Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.needs_infer(),
12461246
_ => true,
12471247
}
12481248
}
@@ -1269,8 +1269,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12691269
if self.can_use_global_caches(param_env) {
12701270
if let Err(Overflow) = candidate {
12711271
// Don't cache overflow globally; we only produce this in certain modes.
1272-
} else if !trait_ref.has_local_value() {
1273-
if !candidate.has_local_value() {
1272+
} else if !trait_ref.needs_infer() {
1273+
if !candidate.needs_infer() {
12741274
debug!(
12751275
"insert_candidate_cache(trait_ref={:?}, candidate={:?}) global",
12761276
trait_ref, candidate,

src/librustc_typeck/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn check_type_defn<'tcx, F>(
369369
packed && {
370370
let ty = variant.fields.last().unwrap().ty;
371371
let ty = fcx.tcx.erase_regions(&ty);
372-
if ty.has_local_value() {
372+
if ty.needs_infer() {
373373
fcx_tcx
374374
.sess
375375
.delay_span_bug(item.span, &format!("inference variables in {:?}", ty));

src/librustc_typeck/check/writeback.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
365365
for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
366366
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
367367

368-
if cfg!(debug_assertions) && c_ty.has_local_value() {
369-
span_bug!(hir_id.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", c_ty);
368+
if cfg!(debug_assertions) && c_ty.needs_infer() {
369+
span_bug!(
370+
hir_id.to_span(self.fcx.tcx),
371+
"writeback: `{:?}` has inference variables",
372+
c_ty
373+
);
370374
};
371375

372376
self.tables.user_provided_types_mut().insert(hir_id, c_ty.clone());
@@ -399,10 +403,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
399403
assert_eq!(fcx_tables.hir_owner, self.tables.hir_owner);
400404

401405
for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
402-
if cfg!(debug_assertions) && c_sig.has_local_value() {
406+
if cfg!(debug_assertions) && c_sig.needs_infer() {
403407
span_bug!(
404408
self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
405-
"writeback: `{:?}` is a local value",
409+
"writeback: `{:?}` has inference variables",
406410
c_sig
407411
);
408412
};
@@ -457,7 +461,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
457461
}
458462
}
459463

460-
if !opaque_defn.substs.has_local_value() {
464+
if !opaque_defn.substs.needs_infer() {
461465
// We only want to add an entry into `concrete_opaque_types`
462466
// if we actually found a defining usage of this opaque type.
463467
// Otherwise, we do nothing - we'll either find a defining usage
@@ -485,7 +489,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
485489
}
486490
}
487491
} else {
488-
self.tcx().sess.delay_span_bug(span, "`opaque_defn` is a local value");
492+
self.tcx().sess.delay_span_bug(span, "`opaque_defn` has inference variables");
489493
}
490494
}
491495
}
@@ -579,8 +583,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
579583
T: TypeFoldable<'tcx>,
580584
{
581585
let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
582-
if cfg!(debug_assertions) && x.has_local_value() {
583-
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", x);
586+
if cfg!(debug_assertions) && x.needs_infer() {
587+
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` has inference variables", x);
584588
}
585589
x
586590
}

0 commit comments

Comments
 (0)