Skip to content

Commit ef064d2

Browse files
committedJul 2, 2019
Auto merge of #61871 - Zoxc:no-lift-branch, r=eddyb
Don't use lift to detect local types This overlaps with #61392. r? @eddyb
2 parents 99abdfa + 8465daf commit ef064d2

File tree

17 files changed

+141
-102
lines changed

17 files changed

+141
-102
lines changed
 

‎src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14561456
// Even if the type may have no inference variables, during
14571457
// type-checking closure types are in local tables only.
14581458
if !self.in_progress_tables.is_some() || !ty.has_closure_types() {
1459-
if let Some((param_env, ty)) = self.tcx.lift_to_global(&(param_env, ty)) {
1459+
if !(param_env, ty).has_local_value() {
14601460
return ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span);
14611461
}
14621462
}

‎src/librustc/infer/outlives/free_region_map.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub struct FreeRegionMap<'tcx> {
1111
}
1212

1313
impl<'tcx> FreeRegionMap<'tcx> {
14+
pub fn elements(&self) -> impl Iterator<Item=&Region<'tcx>> {
15+
self.relation.elements()
16+
}
17+
1418
pub fn is_empty(&self) -> bool {
1519
self.relation.is_empty()
1620
}

‎src/librustc/middle/mem_categorization.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
465465
) -> bool {
466466
self.infcx.map(|infcx| infcx.type_is_copy_modulo_regions(param_env, ty, span))
467467
.or_else(|| {
468-
self.tcx.lift_to_global(&(param_env, ty)).map(|(param_env, ty)| {
469-
ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span)
470-
})
468+
if (param_env, ty).has_local_value() {
469+
None
470+
} else {
471+
Some(ty.is_copy_modulo_regions(self.tcx, param_env, span))
472+
}
471473
})
472474
.unwrap_or(true)
473475
}

‎src/librustc/mir/interpret/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ impl ErrorHandled {
3737
}
3838
}
3939

40+
CloneTypeFoldableImpls! {
41+
ErrorHandled,
42+
}
43+
4044
pub type ConstEvalRawResult<'tcx> = Result<RawConst<'tcx>, ErrorHandled>;
4145
pub type ConstEvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, ErrorHandled>;
4246

‎src/librustc/traits/fulfill.rs

+26-32
Original file line numberDiff line numberDiff line change
@@ -461,41 +461,35 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
461461
}
462462

463463
ty::Predicate::ConstEvaluatable(def_id, substs) => {
464-
match self.selcx.tcx().lift_to_global(&obligation.param_env) {
465-
None => {
464+
if obligation.param_env.has_local_value() {
466465
ProcessResult::Unchanged
467-
}
468-
Some(param_env) => {
469-
match self.selcx.tcx().lift_to_global(&substs) {
470-
Some(substs) => {
471-
let instance = ty::Instance::resolve(
472-
self.selcx.tcx().global_tcx(),
473-
param_env,
474-
def_id,
475-
substs,
476-
);
477-
if let Some(instance) = instance {
478-
let cid = GlobalId {
479-
instance,
480-
promoted: None,
481-
};
482-
match self.selcx.tcx().at(obligation.cause.span)
483-
.const_eval(param_env.and(cid)) {
484-
Ok(_) => ProcessResult::Changed(vec![]),
485-
Err(err) => ProcessResult::Error(
486-
CodeSelectionError(ConstEvalFailure(err)))
487-
}
488-
} else {
489-
ProcessResult::Error(CodeSelectionError(
490-
ConstEvalFailure(ErrorHandled::TooGeneric)
491-
))
492-
}
493-
},
494-
None => {
495-
pending_obligation.stalled_on = substs.types().collect();
496-
ProcessResult::Unchanged
466+
} else {
467+
if !substs.has_local_value() {
468+
let instance = ty::Instance::resolve(
469+
self.selcx.tcx().global_tcx(),
470+
obligation.param_env,
471+
def_id,
472+
substs,
473+
);
474+
if let Some(instance) = instance {
475+
let cid = GlobalId {
476+
instance,
477+
promoted: None,
478+
};
479+
match self.selcx.tcx().at(obligation.cause.span)
480+
.const_eval(obligation.param_env.and(cid)) {
481+
Ok(_) => ProcessResult::Changed(vec![]),
482+
Err(err) => ProcessResult::Error(
483+
CodeSelectionError(ConstEvalFailure(err)))
497484
}
485+
} else {
486+
ProcessResult::Error(CodeSelectionError(
487+
ConstEvalFailure(ErrorHandled::TooGeneric)
488+
))
498489
}
490+
} else {
491+
pending_obligation.stalled_on = substs.types().collect();
492+
ProcessResult::Unchanged
499493
}
500494
}
501495
}

‎src/librustc/traits/mod.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ pub enum SelectionError<'tcx> {
457457
Overflow,
458458
}
459459

460+
EnumTypeFoldableImpl! {
461+
impl<'tcx> TypeFoldable<'tcx> for SelectionError<'tcx> {
462+
(SelectionError::Unimplemented),
463+
(SelectionError::OutputTypeParameterMismatch)(a, b, c),
464+
(SelectionError::TraitNotObjectSafe)(a),
465+
(SelectionError::ConstEvalFailure)(a),
466+
(SelectionError::Overflow),
467+
}
468+
}
469+
460470
pub struct FulfillmentError<'tcx> {
461471
pub obligation: PredicateObligation<'tcx>,
462472
pub code: FulfillmentErrorCode<'tcx>
@@ -782,13 +792,11 @@ fn do_normalize_predicates<'tcx>(
782792
return Err(ErrorReported)
783793
}
784794
};
785-
786-
match tcx.lift_to_global(&predicates) {
787-
Some(predicates) => Ok(predicates),
788-
None => {
789-
// FIXME: shouldn't we, you know, actually report an error here? or an ICE?
790-
Err(ErrorReported)
791-
}
795+
if predicates.has_local_value() {
796+
// FIXME: shouldn't we, you know, actually report an error here? or an ICE?
797+
Err(ErrorReported)
798+
} else {
799+
Ok(predicates)
792800
}
793801
})
794802
}

‎src/librustc/traits/project.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
399399
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
400400
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
401401
let tcx = self.selcx.tcx().global_tcx();
402-
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
402+
let param_env = self.param_env;
403+
if !param_env.has_local_value() {
403404
if substs.needs_infer() || substs.has_placeholders() {
404405
let identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
405406
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
@@ -414,7 +415,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
414415
}
415416
}
416417
} else {
417-
if let Some(substs) = self.tcx().lift_to_global(&substs) {
418+
if !substs.has_local_value() {
418419
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs);
419420
if let Some(instance) = instance {
420421
let cid = GlobalId {

‎src/librustc/traits/query/normalize.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
193193
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
194194
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
195195
let tcx = self.infcx.tcx.global_tcx();
196-
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
196+
let param_env = self.param_env;
197+
if !param_env.has_local_value() {
197198
if substs.needs_infer() || substs.has_placeholders() {
198199
let identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
199200
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
@@ -208,7 +209,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
208209
}
209210
}
210211
} else {
211-
if let Some(substs) = self.tcx().lift_to_global(&substs) {
212+
if !substs.has_local_value() {
212213
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs);
213214
if let Some(instance) = instance {
214215
let cid = GlobalId {

‎src/librustc/traits/select.rs

+37-22
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,23 @@ impl<'a, 'tcx> ty::Lift<'tcx> for SelectionCandidate<'a> {
328328
}
329329
}
330330

331+
EnumTypeFoldableImpl! {
332+
impl<'tcx> TypeFoldable<'tcx> for SelectionCandidate<'tcx> {
333+
(SelectionCandidate::BuiltinCandidate) { has_nested },
334+
(SelectionCandidate::ParamCandidate)(poly_trait_ref),
335+
(SelectionCandidate::ImplCandidate)(def_id),
336+
(SelectionCandidate::AutoImplCandidate)(def_id),
337+
(SelectionCandidate::ProjectionCandidate),
338+
(SelectionCandidate::ClosureCandidate),
339+
(SelectionCandidate::GeneratorCandidate),
340+
(SelectionCandidate::FnPointerCandidate),
341+
(SelectionCandidate::TraitAliasCandidate)(def_id),
342+
(SelectionCandidate::ObjectCandidate),
343+
(SelectionCandidate::BuiltinObjectCandidate),
344+
(SelectionCandidate::BuiltinUnsizeCandidate),
345+
}
346+
}
347+
331348
struct SelectionCandidateSet<'tcx> {
332349
// a list of candidates that definitely apply to the current
333350
// obligation (meaning: types unify).
@@ -818,27 +835,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
818835

819836
ty::Predicate::ConstEvaluatable(def_id, substs) => {
820837
let tcx = self.tcx();
821-
match tcx.lift_to_global(&(obligation.param_env, substs)) {
822-
Some((param_env, substs)) => {
823-
let instance =
824-
ty::Instance::resolve(tcx.global_tcx(), param_env, def_id, substs);
825-
if let Some(instance) = instance {
826-
let cid = GlobalId {
827-
instance,
828-
promoted: None,
829-
};
830-
match self.tcx().const_eval(param_env.and(cid)) {
831-
Ok(_) => Ok(EvaluatedToOk),
832-
Err(_) => Ok(EvaluatedToErr),
833-
}
834-
} else {
835-
Ok(EvaluatedToErr)
838+
if !(obligation.param_env, substs).has_local_value() {
839+
let param_env = obligation.param_env;
840+
let instance =
841+
ty::Instance::resolve(tcx, param_env, def_id, substs);
842+
if let Some(instance) = instance {
843+
let cid = GlobalId {
844+
instance,
845+
promoted: None,
846+
};
847+
match self.tcx().const_eval(param_env.and(cid)) {
848+
Ok(_) => Ok(EvaluatedToOk),
849+
Err(_) => Ok(EvaluatedToErr),
836850
}
851+
} else {
852+
Ok(EvaluatedToErr)
837853
}
838-
None => {
839-
// Inference variables still left in param_env or substs.
840-
Ok(EvaluatedToAmbig)
841-
}
854+
} else {
855+
// Inference variables still left in param_env or substs.
856+
Ok(EvaluatedToAmbig)
842857
}
843858
}
844859
}
@@ -1172,7 +1187,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11721187
}
11731188

11741189
if self.can_use_global_caches(param_env) {
1175-
if let Some(trait_ref) = self.tcx().lift_to_global(&trait_ref) {
1190+
if !trait_ref.has_local_value() {
11761191
debug!(
11771192
"insert_evaluation_cache(trait_ref={:?}, candidate={:?}) global",
11781193
trait_ref, result,
@@ -1645,8 +1660,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16451660
if let Err(Overflow) = candidate {
16461661
// Don't cache overflow globally; we only produce this
16471662
// in certain modes.
1648-
} else if let Some(trait_ref) = tcx.lift_to_global(&trait_ref) {
1649-
if let Some(candidate) = tcx.lift_to_global(&candidate) {
1663+
} else if !trait_ref.has_local_value() {
1664+
if !candidate.has_local_value() {
16501665
debug!(
16511666
"insert_candidate_cache(trait_ref={:?}, candidate={:?}) global",
16521667
trait_ref, candidate,

‎src/librustc/ty/erase_regions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ impl TypeFolder<'tcx> for RegionEraserVisitor<'tcx> {
4242
}
4343

4444
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
45-
if let Some(ty_lifted) = self.tcx.lift_to_global(&ty) {
46-
self.tcx.erase_regions_ty(ty_lifted)
47-
} else {
45+
if ty.has_local_value() {
4846
ty.super_fold_with(self)
47+
} else {
48+
self.tcx.erase_regions_ty(ty)
4949
}
5050
}
5151

‎src/librustc/ty/fold.rs

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9191
fn has_infer_types(&self) -> bool {
9292
self.has_type_flags(TypeFlags::HAS_TY_INFER)
9393
}
94+
fn has_local_value(&self) -> bool {
95+
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
96+
}
9497
fn needs_infer(&self) -> bool {
9598
self.has_type_flags(
9699
TypeFlags::HAS_TY_INFER | TypeFlags::HAS_RE_INFER | TypeFlags::HAS_CT_INFER
@@ -922,6 +925,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
922925
}
923926
}
924927

928+
// FIXME: Optimize for checking for infer flags
925929
struct HasTypeFlagsVisitor {
926930
flags: ty::TypeFlags,
927931
}

‎src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
550550
if let ConstValue::Unevaluated(def_id, substs) = x.val {
551551
// FIXME(eddyb) get the right param_env.
552552
let param_env = ty::ParamEnv::empty();
553-
if let Some(substs) = tcx.lift_to_global(&substs) {
553+
if !substs.has_local_value() {
554554
let instance = ty::Instance::resolve(
555555
tcx.global_tcx(),
556556
param_env,

‎src/librustc/ty/structural_impls.rs

+7
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ EnumTypeFoldableImpl! {
821821
} where T: TypeFoldable<'tcx>
822822
}
823823

824+
EnumTypeFoldableImpl! {
825+
impl<'tcx, T, E> TypeFoldable<'tcx> for Result<T, E> {
826+
(Ok)(a),
827+
(Err)(a),
828+
} where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>,
829+
}
830+
824831
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
825832
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
826833
Rc::new((**self).fold_with(folder))

‎src/librustc_data_structures/transitive_relation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
5858
self.edges.is_empty()
5959
}
6060

61+
pub fn elements(&self) -> impl Iterator<Item=&T> {
62+
self.elements.iter()
63+
}
64+
6165
fn index(&self, a: &T) -> Option<Index> {
6266
self.map.get(a).cloned()
6367
}

‎src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
809809
ty: Ty<'tcx>,
810810
) -> Option<ClosureOutlivesSubject<'tcx>> {
811811
let tcx = infcx.tcx;
812-
let gcx = tcx.global_tcx();
813812

814813
debug!("try_promote_type_test_subject(ty = {:?})", ty);
815814

@@ -863,8 +862,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
863862
});
864863
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
865864

866-
// `lift_to_global` will only fail if we failed to promote some region.
867-
gcx.lift_to_global(&ty)?;
865+
// `has_local_value` will only be true if we failed to promote some region.
866+
if ty.has_local_value() {
867+
return None;
868+
}
868869

869870
Some(ClosureOutlivesSubject::Ty(ty))
870871
}

‎src/librustc_typeck/check/wfcheck.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::constrained_generic_params::{identify_constrained_generic_params, Par
33

44
use crate::hir::def_id::DefId;
55
use rustc::traits::{self, ObligationCauseCode};
6-
use rustc::ty::{self, Lift, Ty, TyCtxt, GenericParamDefKind, TypeFoldable, ToPredicate};
6+
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable, ToPredicate};
77
use rustc::ty::subst::{Subst, InternalSubsts};
88
use rustc::util::nodemap::{FxHashSet, FxHashMap};
99
use rustc::mir::interpret::ConstValue;
@@ -261,14 +261,15 @@ fn check_type_defn<'tcx, F>(
261261
let needs_drop_copy = || {
262262
packed && {
263263
let ty = variant.fields.last().unwrap().ty;
264-
fcx.tcx.erase_regions(&ty).lift_to_tcx(fcx_tcx)
265-
.map(|ty| ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id)))
266-
.unwrap_or_else(|| {
264+
let ty = fcx.tcx.erase_regions(&ty);
265+
if ty.has_local_value() {
267266
fcx_tcx.sess.delay_span_bug(
268267
item.span, &format!("inference variables in {:?}", ty));
269268
// Just treat unresolved type expression as if it needs drop.
270269
true
271-
})
270+
} else {
271+
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id))
272+
}
272273
}
273274
};
274275
let all_sized =

0 commit comments

Comments
 (0)
Please sign in to comment.