Skip to content

Commit de8066f

Browse files
authored
Rollup merge of #61842 - Zoxc:trim-lift, r=eddyb
Remove unnecessary lift calls Note that some of these might be useful for sanity checking that there's no infer types or regions. r? @eddyb
2 parents 404c854 + 007aaba commit de8066f

File tree

22 files changed

+50
-89
lines changed

22 files changed

+50
-89
lines changed

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::mir::interpret::ConstValue;
1414
use std::sync::atomic::Ordering;
1515
use crate::ty::fold::{TypeFoldable, TypeFolder};
1616
use crate::ty::subst::Kind;
17-
use crate::ty::{self, BoundVar, InferConst, Lift, List, Ty, TyCtxt, TypeFlags};
17+
use crate::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags};
1818
use crate::ty::flags::FlagComputation;
1919

2020
use rustc_data_structures::fx::FxHashMap;
@@ -43,7 +43,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
4343
query_state: &mut OriginalQueryValues<'tcx>,
4444
) -> Canonicalized<'tcx, V>
4545
where
46-
V: TypeFoldable<'tcx> + Lift<'tcx>,
46+
V: TypeFoldable<'tcx>,
4747
{
4848
self.tcx
4949
.sess
@@ -87,7 +87,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
8787
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html#canonicalizing-the-query-result
8888
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
8989
where
90-
V: TypeFoldable<'tcx> + Lift<'tcx>,
90+
V: TypeFoldable<'tcx>,
9191
{
9292
let mut query_state = OriginalQueryValues::default();
9393
Canonicalizer::canonicalize(
@@ -101,7 +101,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
101101

102102
pub fn canonicalize_user_type_annotation<V>(&self, value: &V) -> Canonicalized<'tcx, V>
103103
where
104-
V: TypeFoldable<'tcx> + Lift<'tcx>,
104+
V: TypeFoldable<'tcx>,
105105
{
106106
let mut query_state = OriginalQueryValues::default();
107107
Canonicalizer::canonicalize(
@@ -132,7 +132,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
132132
query_state: &mut OriginalQueryValues<'tcx>,
133133
) -> Canonicalized<'tcx, V>
134134
where
135-
V: TypeFoldable<'tcx> + Lift<'tcx>,
135+
V: TypeFoldable<'tcx>,
136136
{
137137
self.tcx
138138
.sess
@@ -506,7 +506,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
506506
query_state: &mut OriginalQueryValues<'tcx>,
507507
) -> Canonicalized<'tcx, V>
508508
where
509-
V: TypeFoldable<'tcx> + Lift<'tcx>,
509+
V: TypeFoldable<'tcx>,
510510
{
511511
let needs_canonical_flags = if canonicalize_region_mode.any() {
512512
TypeFlags::KEEP_IN_LOCAL_TCX |
@@ -520,20 +520,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
520520
TypeFlags::HAS_CT_PLACEHOLDER
521521
};
522522

523-
let gcx = tcx.global_tcx();
524-
525523
// Fast path: nothing that needs to be canonicalized.
526524
if !value.has_type_flags(needs_canonical_flags) {
527-
let out_value = gcx.lift(value).unwrap_or_else(|| {
528-
bug!(
529-
"failed to lift `{:?}` (nothing to canonicalize)",
530-
value
531-
)
532-
});
533525
let canon_value = Canonical {
534526
max_universe: ty::UniverseIndex::ROOT,
535527
variables: List::empty(),
536-
value: out_value,
528+
value: value.clone(),
537529
};
538530
return canon_value;
539531
}
@@ -553,13 +545,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
553545
// Once we have canonicalized `out_value`, it should not
554546
// contain anything that ties it to this inference context
555547
// anymore, so it should live in the global arena.
556-
let out_value = gcx.lift(&out_value).unwrap_or_else(|| {
557-
bug!(
558-
"failed to lift `{:?}`, canonicalized from `{:?}`",
559-
out_value,
560-
value
561-
)
562-
});
548+
debug_assert!(!out_value.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX));
563549

564550
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables);
565551

src/librustc/infer/canonical/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ pub struct QueryResponse<'tcx, R> {
194194
pub value: R,
195195
}
196196

197-
pub type Canonicalized<'tcx, V> = Canonical<'tcx, <V as Lift<'tcx>>::Lifted>;
197+
pub type Canonicalized<'tcx, V> = Canonical<'tcx, V>;
198198

199199
pub type CanonicalizedQueryResponse<'tcx, T> =
200-
&'tcx Canonical<'tcx, QueryResponse<'tcx, <T as Lift<'tcx>>::Lifted>>;
200+
&'tcx Canonical<'tcx, QueryResponse<'tcx, T>>;
201201

202202
/// Indicates whether or not we were able to prove the query to be
203203
/// true.

src/librustc/infer/canonical/query_response.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::traits::TraitEngine;
2626
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
2727
use crate::ty::fold::TypeFoldable;
2828
use crate::ty::subst::{Kind, UnpackedKind};
29-
use crate::ty::{self, BoundVar, InferConst, Lift, Ty, TyCtxt};
29+
use crate::ty::{self, BoundVar, InferConst, Ty, TyCtxt};
3030
use crate::util::captures::Captures;
3131

3232
impl<'tcx> InferCtxtBuilder<'tcx> {
@@ -53,8 +53,8 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
5353
) -> Fallible<CanonicalizedQueryResponse<'tcx, R>>
5454
where
5555
K: TypeFoldable<'tcx>,
56-
R: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
57-
Canonical<'tcx, <QueryResponse<'tcx, R> as Lift<'tcx>>::Lifted>: ArenaAllocatable,
56+
R: Debug + TypeFoldable<'tcx>,
57+
Canonical<'tcx, QueryResponse<'tcx, R>>: ArenaAllocatable,
5858
{
5959
self.enter_with_canonical(
6060
DUMMY_SP,
@@ -99,8 +99,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9999
fulfill_cx: &mut dyn TraitEngine<'tcx>,
100100
) -> Fallible<CanonicalizedQueryResponse<'tcx, T>>
101101
where
102-
T: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
103-
Canonical<'tcx, <QueryResponse<'tcx, T> as Lift<'tcx>>::Lifted>: ArenaAllocatable,
102+
T: Debug + TypeFoldable<'tcx>,
103+
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable,
104104
{
105105
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
106106
let canonical_result = self.canonicalize_response(&query_response);
@@ -126,9 +126,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
126126
&self,
127127
inference_vars: CanonicalVarValues<'tcx>,
128128
answer: T,
129-
) -> Canonical<'tcx, QueryResponse<'tcx, <T as Lift<'tcx>>::Lifted>>
129+
) -> Canonical<'tcx, QueryResponse<'tcx, T>>
130130
where
131-
T: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
131+
T: Debug + TypeFoldable<'tcx>,
132132
{
133133
self.canonicalize_response(&QueryResponse {
134134
var_values: inference_vars,
@@ -147,7 +147,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
147147
fulfill_cx: &mut dyn TraitEngine<'tcx>,
148148
) -> Result<QueryResponse<'tcx, T>, NoSolution>
149149
where
150-
T: Debug + TypeFoldable<'tcx> + Lift<'tcx>,
150+
T: Debug + TypeFoldable<'tcx>,
151151
{
152152
let tcx = self.tcx;
153153

src/librustc/infer/opaque_types/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
469469
definition_ty
470470
);
471471

472-
// We can unwrap here because our reverse mapper always
473-
// produces things with 'tcx lifetime, though the type folder
474-
// obscures that.
475-
let definition_ty = gcx.lift(&definition_ty).unwrap();
476-
477472
definition_ty
478473
}
479474
}

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
817817
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
818818

819819
None =>
820-
self.tcx.global_tcx()
821-
.lift(&closure_substs)
822-
.expect("no inference cx, but inference variables in closure ty")
823-
.closure_kind(closure_def_id, self.tcx.global_tcx()),
820+
closure_substs.closure_kind(closure_def_id, self.tcx.global_tcx()),
824821
}
825822
}
826823
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

src/librustc/traits/codegen/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
141141
&self,
142142
fulfill_cx: &mut FulfillmentContext<'tcx>,
143143
result: &T,
144-
) -> T::Lifted
144+
) -> T
145145
where
146-
T: TypeFoldable<'tcx> + ty::Lift<'tcx>,
146+
T: TypeFoldable<'tcx>,
147147
{
148148
debug!("drain_fulfillment_cx_or_panic()");
149149

@@ -155,10 +155,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
155155
}
156156

157157
let result = self.resolve_vars_if_possible(result);
158-
let result = self.tcx.erase_regions(&result);
159-
160-
self.tcx.lift_to_global(&result).unwrap_or_else(||
161-
bug!("Uninferred types/regions/consts in `{:?}`", result)
162-
)
158+
self.tcx.erase_regions(&result)
163159
}
164160
}

src/librustc/traits/project.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
409409
promoted: None
410410
};
411411
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
412-
let substs = tcx.lift_to_global(&substs).unwrap();
413412
let evaluated = evaluated.subst(tcx, substs);
414413
return evaluated;
415414
}

src/librustc/traits/query/normalize.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
203203
promoted: None,
204204
};
205205
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
206-
let substs = tcx.lift_to_global(&substs).unwrap();
207206
let evaluated = evaluated.subst(tcx, substs);
208207
return evaluated;
209208
}

src/librustc/traits/query/type_op/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::rc::Rc;
88
use crate::traits::query::Fallible;
99
use crate::traits::ObligationCause;
1010
use crate::ty::fold::TypeFoldable;
11-
use crate::ty::{Lift, ParamEnvAnd, TyCtxt};
11+
use crate::ty::{ParamEnvAnd, TyCtxt};
1212

1313
pub mod ascribe_user_type;
1414
pub mod custom;
@@ -44,8 +44,8 @@ pub trait TypeOp<'tcx>: Sized + fmt::Debug {
4444
/// which produces the resulting query region constraints.
4545
///
4646
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
47-
pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + Lift<'tcx> {
48-
type QueryResponse: TypeFoldable<'tcx> + Lift<'tcx>;
47+
pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
48+
type QueryResponse: TypeFoldable<'tcx>;
4949

5050
/// Give query the option for a simple fast path that never
5151
/// actually hits the tcx cache lookup etc. Return `Some(r)` with

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020

2121
impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
2222
where
23-
T: Normalizable<'tcx>,
23+
T: Normalizable<'tcx> + 'tcx,
2424
{
2525
type QueryResponse = T;
2626

0 commit comments

Comments
 (0)