提交 11f6096a 编写于 作者: B bors

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
......@@ -488,12 +488,12 @@ fn canonicalize<V>(
V: TypeFoldable<'tcx>,
{
let needs_canonical_flags = if canonicalize_region_mode.any() {
TypeFlags::KEEP_IN_LOCAL_TCX |
TypeFlags::NEEDS_INFER |
TypeFlags::HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS`
TypeFlags::HAS_TY_PLACEHOLDER |
TypeFlags::HAS_CT_PLACEHOLDER
} else {
TypeFlags::KEEP_IN_LOCAL_TCX
TypeFlags::NEEDS_INFER
| TypeFlags::HAS_RE_PLACEHOLDER
| TypeFlags::HAS_TY_PLACEHOLDER
| TypeFlags::HAS_CT_PLACEHOLDER
......@@ -524,7 +524,7 @@ fn canonicalize<V>(
// Once we have canonicalized `out_value`, it should not
// contain anything that ties it to this inference context
// anymore, so it should live in the global arena.
debug_assert!(!out_value.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX));
debug_assert!(!out_value.needs_infer());
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables);
......
......@@ -181,10 +181,8 @@ fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if !t.needs_infer() && !ty::keep_local(&t) {
if !t.needs_infer() {
t // micro-optimize -- if there is nothing in this type that this fold affects...
// ^ we need to have the `keep_local` check to un-default
// defaulted tuples.
} else {
let t = self.infcx.shallow_resolve(t);
match t.kind {
......@@ -222,10 +220,8 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
}
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
if !c.needs_infer() && !ty::keep_local(&c) {
if !c.needs_infer() {
c // micro-optimize -- if there is nothing in this const that this fold affects...
// ^ we need to have the `keep_local` check to un-default
// defaulted tuples.
} else {
let c = self.infcx.shallow_resolve(c);
match c.val {
......
......@@ -2065,10 +2065,6 @@ pub fn $method(self, v: $ty) -> &'tcx $ty {
}
}
pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX)
}
direct_interners!(
region: mk_region(RegionKind),
goal: mk_goal(GoalKind<'tcx>),
......
......@@ -40,7 +40,7 @@ fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if ty.has_local_value() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
if ty.needs_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
}
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
......
......@@ -109,13 +109,12 @@ fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
}
&ty::Infer(infer) => {
self.add_flags(TypeFlags::HAS_TY_INFER);
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
match infer {
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {}
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => {
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
self.add_flags(TypeFlags::HAS_TY_INFER)
}
}
}
......@@ -221,11 +220,10 @@ fn add_const(&mut self, c: &ty::Const<'_>) {
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
}
ty::ConstKind::Infer(infer) => {
self.add_flags(TypeFlags::HAS_CT_INFER);
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
match infer {
InferConst::Fresh(_) => {}
InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX),
InferConst::Var(_) => self.add_flags(TypeFlags::HAS_CT_INFER),
}
}
ty::ConstKind::Bound(debruijn, _) => {
......
......@@ -96,9 +96,6 @@ fn has_infer_types_or_consts(&self) -> bool {
fn has_infer_consts(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_CT_INFER)
}
fn has_local_value(&self) -> bool {
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
}
fn needs_infer(&self) -> bool {
self.has_type_flags(TypeFlags::NEEDS_INFER)
}
......
......@@ -71,7 +71,7 @@
pub use self::binding::BindingMode;
pub use self::binding::BindingMode::*;
pub use self::context::{keep_local, tls, FreeRegionInfo, TyCtxt};
pub use self::context::{tls, FreeRegionInfo, TyCtxt};
pub use self::context::{
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
UserType, UserTypeAnnotationIndex,
......@@ -577,27 +577,23 @@ pub struct TypeFlags: u32 {
| TypeFlags::HAS_TY_OPAQUE.bits
| TypeFlags::HAS_CT_PROJECTION.bits;
/// Present if the type belongs in a local type context.
/// Set for placeholders and inference variables that are not "Fresh".
const KEEP_IN_LOCAL_TCX = 1 << 13;
/// Is an error type reachable?
const HAS_TY_ERR = 1 << 14;
const HAS_TY_ERR = 1 << 13;
/// Does this have any region that "appears free" in the type?
/// Basically anything but [ReLateBound] and [ReErased].
const HAS_FREE_REGIONS = 1 << 15;
const HAS_FREE_REGIONS = 1 << 14;
/// Does this have any [ReLateBound] regions? Used to check
/// if a global bound is safe to evaluate.
const HAS_RE_LATE_BOUND = 1 << 16;
const HAS_RE_LATE_BOUND = 1 << 15;
/// Does this have any [ReErased] regions?
const HAS_RE_ERASED = 1 << 17;
const HAS_RE_ERASED = 1 << 16;
/// Does this value have parameters/placeholders/inference variables which could be
/// replaced later, in a way that would change the results of `impl` specialization?
const STILL_FURTHER_SPECIALIZABLE = 1 << 18;
const STILL_FURTHER_SPECIALIZABLE = 1 << 17;
}
}
......
......@@ -510,7 +510,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
let tcx = relation.tcx();
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| {
if !x.val.has_local_value() {
if !x.val.needs_infer() {
return x.eval(tcx, relation.param_env()).val;
}
x.val
......
......@@ -1605,7 +1605,6 @@ pub fn type_flags(&self) -> TypeFlags {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
flags = flags | TypeFlags::HAS_RE_INFER;
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE;
}
ty::RePlaceholder(..) => {
......@@ -2361,8 +2360,8 @@ pub fn eval(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> &Const<'tcx>
let try_const_eval = |did, param_env: ParamEnv<'tcx>, substs, promoted| {
let param_env_and_substs = param_env.with_reveal_all().and(substs);
// Avoid querying `tcx.const_eval(...)` with any e.g. inference vars.
if param_env_and_substs.has_local_value() {
// Avoid querying `tcx.const_eval(...)` with any inference vars.
if param_env_and_substs.needs_infer() {
return None;
}
......@@ -2377,12 +2376,12 @@ pub fn eval(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> &Const<'tcx>
match self.val {
ConstKind::Unevaluated(did, substs, promoted) => {
// HACK(eddyb) when substs contain e.g. inference variables,
// HACK(eddyb) when substs contain inference variables,
// attempt using identity substs instead, that will succeed
// when the expression doesn't depend on any parameters.
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
// we can call `infcx.const_eval_resolve` which handles inference variables.
if substs.has_local_value() {
if substs.needs_infer() {
let identity_substs = InternalSubsts::identity_for_item(tcx, did);
// The `ParamEnv` needs to match the `identity_substs`.
let identity_param_env = tcx.param_env(did);
......
......@@ -995,15 +995,15 @@ fn try_promote_type_test_subject(
self.definitions[upper_bound].external_name.unwrap_or(r)
} else {
// In the case of a failure, use a `ReVar` result. This will
// cause the `has_local_value` later on to return `None`.
// cause the `needs_infer` later on to return `None`.
r
}
});
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
// `has_local_value` will only be true if we failed to promote some region.
if ty.has_local_value() {
// `needs_infer` will only be true if we failed to promote some region.
if ty.needs_infer() {
return None;
}
......
......@@ -43,7 +43,7 @@ fn type_is_copy_modulo_regions(
) -> bool {
let ty = self.resolve_vars_if_possible(&ty);
if !(param_env, ty).has_local_value() {
if !(param_env, ty).needs_infer() {
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
}
......
......@@ -259,8 +259,8 @@ fn do_normalize_predicates<'tcx>(
return Err(ErrorReported);
}
};
if predicates.has_local_value() {
// FIXME: shouldn't we, you know, actually report an error here? or an ICE?
if predicates.needs_infer() {
tcx.sess.delay_span_bug(span, "encountered inference variables after `fully_resolve`");
Err(ErrorReported)
} else {
Ok(predicates)
......
......@@ -820,7 +820,7 @@ fn insert_evaluation_cache(
}
if self.can_use_global_caches(param_env) {
if !trait_ref.has_local_value() {
if !trait_ref.needs_infer() {
debug!(
"insert_evaluation_cache(trait_ref={:?}, candidate={:?}) global",
trait_ref, result,
......@@ -1178,10 +1178,10 @@ fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Option<
/// Do note that if the type itself is not in the
/// global tcx, the local caches will be used.
fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
// If there are any e.g. inference variables in the `ParamEnv`, then we
// If there are any inference variables in the `ParamEnv`, then we
// always use a cache local to this particular scope. Otherwise, we
// switch to a global cache.
if param_env.has_local_value() {
if param_env.needs_infer() {
return false;
}
......@@ -1242,7 +1242,7 @@ fn can_cache_candidate(
result: &SelectionResult<'tcx, SelectionCandidate<'tcx>>,
) -> bool {
match result {
Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.has_local_value(),
Ok(Some(SelectionCandidate::ParamCandidate(trait_ref))) => !trait_ref.needs_infer(),
_ => true,
}
}
......@@ -1269,8 +1269,8 @@ fn insert_candidate_cache(
if self.can_use_global_caches(param_env) {
if let Err(Overflow) = candidate {
// Don't cache overflow globally; we only produce this in certain modes.
} else if !trait_ref.has_local_value() {
if !candidate.has_local_value() {
} else if !trait_ref.needs_infer() {
if !candidate.needs_infer() {
debug!(
"insert_candidate_cache(trait_ref={:?}, candidate={:?}) global",
trait_ref, candidate,
......
......@@ -369,7 +369,7 @@ fn check_type_defn<'tcx, F>(
packed && {
let ty = variant.fields.last().unwrap().ty;
let ty = fcx.tcx.erase_regions(&ty);
if ty.has_local_value() {
if ty.needs_infer() {
fcx_tcx
.sess
.delay_span_bug(item.span, &format!("inference variables in {:?}", ty));
......
......@@ -365,8 +365,12 @@ fn visit_user_provided_tys(&mut self) {
for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
if cfg!(debug_assertions) && c_ty.has_local_value() {
span_bug!(hir_id.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", c_ty);
if cfg!(debug_assertions) && c_ty.needs_infer() {
span_bug!(
hir_id.to_span(self.fcx.tcx),
"writeback: `{:?}` has inference variables",
c_ty
);
};
self.tables.user_provided_types_mut().insert(hir_id, c_ty.clone());
......@@ -399,10 +403,10 @@ fn visit_user_provided_sigs(&mut self) {
assert_eq!(fcx_tables.hir_owner, self.tables.hir_owner);
for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
if cfg!(debug_assertions) && c_sig.has_local_value() {
if cfg!(debug_assertions) && c_sig.needs_infer() {
span_bug!(
self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
"writeback: `{:?}` is a local value",
"writeback: `{:?}` has inference variables",
c_sig
);
};
......@@ -457,7 +461,7 @@ fn visit_opaque_types(&mut self, span: Span) {
}
}
if !opaque_defn.substs.has_local_value() {
if !opaque_defn.substs.needs_infer() {
// We only want to add an entry into `concrete_opaque_types`
// if we actually found a defining usage of this opaque type.
// Otherwise, we do nothing - we'll either find a defining usage
......@@ -485,7 +489,7 @@ fn visit_opaque_types(&mut self, span: Span) {
}
}
} else {
self.tcx().sess.delay_span_bug(span, "`opaque_defn` is a local value");
self.tcx().sess.delay_span_bug(span, "`opaque_defn` has inference variables");
}
}
}
......@@ -579,8 +583,8 @@ fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T
T: TypeFoldable<'tcx>,
{
let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
if cfg!(debug_assertions) && x.has_local_value() {
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` is a local value", x);
if cfg!(debug_assertions) && x.needs_infer() {
span_bug!(span.to_span(self.fcx.tcx), "writeback: `{:?}` has inference variables", x);
}
x
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册