Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 11f6096

Browse files
committed
Auto merge of rust-lang#70860 - lcnr:has_local_value, r=nikomatsakis
remove `KEEP_IN_LOCAL_TCX` flag closes rust-lang#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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 6 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)