mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
Remove unnecessary lift calls
This commit is contained in:
parent
9606f6fa64
commit
007aabae93
@ -14,7 +14,7 @@ use crate::mir::interpret::ConstValue;
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||||
use crate::ty::subst::Kind;
|
use crate::ty::subst::Kind;
|
||||||
use crate::ty::{self, BoundVar, InferConst, Lift, List, Ty, TyCtxt, TypeFlags};
|
use crate::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags};
|
||||||
use crate::ty::flags::FlagComputation;
|
use crate::ty::flags::FlagComputation;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
@ -43,7 +43,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
query_state: &mut OriginalQueryValues<'tcx>,
|
query_state: &mut OriginalQueryValues<'tcx>,
|
||||||
) -> Canonicalized<'tcx, V>
|
) -> Canonicalized<'tcx, V>
|
||||||
where
|
where
|
||||||
V: TypeFoldable<'tcx> + Lift<'tcx>,
|
V: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
self.tcx
|
self.tcx
|
||||||
.sess
|
.sess
|
||||||
@ -87,7 +87,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html#canonicalizing-the-query-result
|
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html#canonicalizing-the-query-result
|
||||||
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||||
where
|
where
|
||||||
V: TypeFoldable<'tcx> + Lift<'tcx>,
|
V: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let mut query_state = OriginalQueryValues::default();
|
let mut query_state = OriginalQueryValues::default();
|
||||||
Canonicalizer::canonicalize(
|
Canonicalizer::canonicalize(
|
||||||
@ -101,7 +101,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
|
|
||||||
pub fn canonicalize_user_type_annotation<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
pub fn canonicalize_user_type_annotation<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||||
where
|
where
|
||||||
V: TypeFoldable<'tcx> + Lift<'tcx>,
|
V: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let mut query_state = OriginalQueryValues::default();
|
let mut query_state = OriginalQueryValues::default();
|
||||||
Canonicalizer::canonicalize(
|
Canonicalizer::canonicalize(
|
||||||
@ -132,7 +132,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
query_state: &mut OriginalQueryValues<'tcx>,
|
query_state: &mut OriginalQueryValues<'tcx>,
|
||||||
) -> Canonicalized<'tcx, V>
|
) -> Canonicalized<'tcx, V>
|
||||||
where
|
where
|
||||||
V: TypeFoldable<'tcx> + Lift<'tcx>,
|
V: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
self.tcx
|
self.tcx
|
||||||
.sess
|
.sess
|
||||||
@ -506,7 +506,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||||||
query_state: &mut OriginalQueryValues<'tcx>,
|
query_state: &mut OriginalQueryValues<'tcx>,
|
||||||
) -> Canonicalized<'tcx, V>
|
) -> Canonicalized<'tcx, V>
|
||||||
where
|
where
|
||||||
V: TypeFoldable<'tcx> + Lift<'tcx>,
|
V: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let needs_canonical_flags = if canonicalize_region_mode.any() {
|
let needs_canonical_flags = if canonicalize_region_mode.any() {
|
||||||
TypeFlags::KEEP_IN_LOCAL_TCX |
|
TypeFlags::KEEP_IN_LOCAL_TCX |
|
||||||
@ -520,20 +520,12 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||||||
TypeFlags::HAS_CT_PLACEHOLDER
|
TypeFlags::HAS_CT_PLACEHOLDER
|
||||||
};
|
};
|
||||||
|
|
||||||
let gcx = tcx.global_tcx();
|
|
||||||
|
|
||||||
// Fast path: nothing that needs to be canonicalized.
|
// Fast path: nothing that needs to be canonicalized.
|
||||||
if !value.has_type_flags(needs_canonical_flags) {
|
if !value.has_type_flags(needs_canonical_flags) {
|
||||||
let out_value = gcx.lift(value).unwrap_or_else(|| {
|
|
||||||
bug!(
|
|
||||||
"failed to lift `{:?}` (nothing to canonicalize)",
|
|
||||||
value
|
|
||||||
)
|
|
||||||
});
|
|
||||||
let canon_value = Canonical {
|
let canon_value = Canonical {
|
||||||
max_universe: ty::UniverseIndex::ROOT,
|
max_universe: ty::UniverseIndex::ROOT,
|
||||||
variables: List::empty(),
|
variables: List::empty(),
|
||||||
value: out_value,
|
value: value.clone(),
|
||||||
};
|
};
|
||||||
return canon_value;
|
return canon_value;
|
||||||
}
|
}
|
||||||
@ -553,13 +545,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||||||
// Once we have canonicalized `out_value`, it should not
|
// Once we have canonicalized `out_value`, it should not
|
||||||
// contain anything that ties it to this inference context
|
// contain anything that ties it to this inference context
|
||||||
// anymore, so it should live in the global arena.
|
// anymore, so it should live in the global arena.
|
||||||
let out_value = gcx.lift(&out_value).unwrap_or_else(|| {
|
debug_assert!(!out_value.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX));
|
||||||
bug!(
|
|
||||||
"failed to lift `{:?}`, canonicalized from `{:?}`",
|
|
||||||
out_value,
|
|
||||||
value
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables);
|
let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables);
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ pub struct QueryResponse<'tcx, R> {
|
|||||||
pub value: R,
|
pub value: R,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Canonicalized<'tcx, V> = Canonical<'tcx, <V as Lift<'tcx>>::Lifted>;
|
pub type Canonicalized<'tcx, V> = Canonical<'tcx, V>;
|
||||||
|
|
||||||
pub type CanonicalizedQueryResponse<'tcx, T> =
|
pub type CanonicalizedQueryResponse<'tcx, T> =
|
||||||
&'tcx Canonical<'tcx, QueryResponse<'tcx, <T as Lift<'tcx>>::Lifted>>;
|
&'tcx Canonical<'tcx, QueryResponse<'tcx, T>>;
|
||||||
|
|
||||||
/// Indicates whether or not we were able to prove the query to be
|
/// Indicates whether or not we were able to prove the query to be
|
||||||
/// true.
|
/// true.
|
||||||
|
@ -26,7 +26,7 @@ use crate::traits::TraitEngine;
|
|||||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||||
use crate::ty::fold::TypeFoldable;
|
use crate::ty::fold::TypeFoldable;
|
||||||
use crate::ty::subst::{Kind, UnpackedKind};
|
use crate::ty::subst::{Kind, UnpackedKind};
|
||||||
use crate::ty::{self, BoundVar, InferConst, Lift, Ty, TyCtxt};
|
use crate::ty::{self, BoundVar, InferConst, Ty, TyCtxt};
|
||||||
use crate::util::captures::Captures;
|
use crate::util::captures::Captures;
|
||||||
|
|
||||||
impl<'tcx> InferCtxtBuilder<'tcx> {
|
impl<'tcx> InferCtxtBuilder<'tcx> {
|
||||||
@ -53,8 +53,8 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
|
|||||||
) -> Fallible<CanonicalizedQueryResponse<'tcx, R>>
|
) -> Fallible<CanonicalizedQueryResponse<'tcx, R>>
|
||||||
where
|
where
|
||||||
K: TypeFoldable<'tcx>,
|
K: TypeFoldable<'tcx>,
|
||||||
R: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
|
R: Debug + TypeFoldable<'tcx>,
|
||||||
Canonical<'tcx, <QueryResponse<'tcx, R> as Lift<'tcx>>::Lifted>: ArenaAllocatable,
|
Canonical<'tcx, QueryResponse<'tcx, R>>: ArenaAllocatable,
|
||||||
{
|
{
|
||||||
self.enter_with_canonical(
|
self.enter_with_canonical(
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
@ -99,8 +99,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
fulfill_cx: &mut dyn TraitEngine<'tcx>,
|
fulfill_cx: &mut dyn TraitEngine<'tcx>,
|
||||||
) -> Fallible<CanonicalizedQueryResponse<'tcx, T>>
|
) -> Fallible<CanonicalizedQueryResponse<'tcx, T>>
|
||||||
where
|
where
|
||||||
T: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
|
T: Debug + TypeFoldable<'tcx>,
|
||||||
Canonical<'tcx, <QueryResponse<'tcx, T> as Lift<'tcx>>::Lifted>: ArenaAllocatable,
|
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable,
|
||||||
{
|
{
|
||||||
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
|
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
|
||||||
let canonical_result = self.canonicalize_response(&query_response);
|
let canonical_result = self.canonicalize_response(&query_response);
|
||||||
@ -126,9 +126,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
inference_vars: CanonicalVarValues<'tcx>,
|
inference_vars: CanonicalVarValues<'tcx>,
|
||||||
answer: T,
|
answer: T,
|
||||||
) -> Canonical<'tcx, QueryResponse<'tcx, <T as Lift<'tcx>>::Lifted>>
|
) -> Canonical<'tcx, QueryResponse<'tcx, T>>
|
||||||
where
|
where
|
||||||
T: Debug + Lift<'tcx> + TypeFoldable<'tcx>,
|
T: Debug + TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
self.canonicalize_response(&QueryResponse {
|
self.canonicalize_response(&QueryResponse {
|
||||||
var_values: inference_vars,
|
var_values: inference_vars,
|
||||||
@ -147,7 +147,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
fulfill_cx: &mut dyn TraitEngine<'tcx>,
|
fulfill_cx: &mut dyn TraitEngine<'tcx>,
|
||||||
) -> Result<QueryResponse<'tcx, T>, NoSolution>
|
) -> Result<QueryResponse<'tcx, T>, NoSolution>
|
||||||
where
|
where
|
||||||
T: Debug + TypeFoldable<'tcx> + Lift<'tcx>,
|
T: Debug + TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
|
@ -469,11 +469,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
definition_ty
|
definition_ty
|
||||||
);
|
);
|
||||||
|
|
||||||
// We can unwrap here because our reverse mapper always
|
|
||||||
// produces things with 'tcx lifetime, though the type folder
|
|
||||||
// obscures that.
|
|
||||||
let definition_ty = gcx.lift(&definition_ty).unwrap();
|
|
||||||
|
|
||||||
definition_ty
|
definition_ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -819,10 +819,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
|
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
|
||||||
|
|
||||||
None =>
|
None =>
|
||||||
self.tcx.global_tcx()
|
closure_substs.closure_kind(closure_def_id, self.tcx.global_tcx()),
|
||||||
.lift(&closure_substs)
|
|
||||||
.expect("no inference cx, but inference variables in closure ty")
|
|
||||||
.closure_kind(closure_def_id, self.tcx.global_tcx()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),
|
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),
|
||||||
|
@ -141,9 +141,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
fulfill_cx: &mut FulfillmentContext<'tcx>,
|
fulfill_cx: &mut FulfillmentContext<'tcx>,
|
||||||
result: &T,
|
result: &T,
|
||||||
) -> T::Lifted
|
) -> T
|
||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx> + ty::Lift<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
debug!("drain_fulfillment_cx_or_panic()");
|
debug!("drain_fulfillment_cx_or_panic()");
|
||||||
|
|
||||||
@ -155,10 +155,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = self.resolve_vars_if_possible(result);
|
let result = self.resolve_vars_if_possible(result);
|
||||||
let result = self.tcx.erase_regions(&result);
|
self.tcx.erase_regions(&result)
|
||||||
|
|
||||||
self.tcx.lift_to_global(&result).unwrap_or_else(||
|
|
||||||
bug!("Uninferred types/regions/consts in `{:?}`", result)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,6 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
|
|||||||
promoted: None
|
promoted: None
|
||||||
};
|
};
|
||||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||||
let substs = tcx.lift_to_global(&substs).unwrap();
|
|
||||||
let evaluated = evaluated.subst(tcx, substs);
|
let evaluated = evaluated.subst(tcx, substs);
|
||||||
return evaluated;
|
return evaluated;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
|
|||||||
promoted: None,
|
promoted: None,
|
||||||
};
|
};
|
||||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||||
let substs = tcx.lift_to_global(&substs).unwrap();
|
|
||||||
let evaluated = evaluated.subst(tcx, substs);
|
let evaluated = evaluated.subst(tcx, substs);
|
||||||
return evaluated;
|
return evaluated;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||||||
use crate::traits::query::Fallible;
|
use crate::traits::query::Fallible;
|
||||||
use crate::traits::ObligationCause;
|
use crate::traits::ObligationCause;
|
||||||
use crate::ty::fold::TypeFoldable;
|
use crate::ty::fold::TypeFoldable;
|
||||||
use crate::ty::{Lift, ParamEnvAnd, TyCtxt};
|
use crate::ty::{ParamEnvAnd, TyCtxt};
|
||||||
|
|
||||||
pub mod ascribe_user_type;
|
pub mod ascribe_user_type;
|
||||||
pub mod custom;
|
pub mod custom;
|
||||||
@ -44,8 +44,8 @@ pub trait TypeOp<'tcx>: Sized + fmt::Debug {
|
|||||||
/// which produces the resulting query region constraints.
|
/// which produces the resulting query region constraints.
|
||||||
///
|
///
|
||||||
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
|
/// [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
|
||||||
pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + Lift<'tcx> {
|
pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
|
||||||
type QueryResponse: TypeFoldable<'tcx> + Lift<'tcx>;
|
type QueryResponse: TypeFoldable<'tcx>;
|
||||||
|
|
||||||
/// Give query the option for a simple fast path that never
|
/// Give query the option for a simple fast path that never
|
||||||
/// actually hits the tcx cache lookup etc. Return `Some(r)` with
|
/// actually hits the tcx cache lookup etc. Return `Some(r)` with
|
||||||
|
@ -20,7 +20,7 @@ where
|
|||||||
|
|
||||||
impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
|
impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
|
||||||
where
|
where
|
||||||
T: Normalizable<'tcx>,
|
T: Normalizable<'tcx> + 'tcx,
|
||||||
{
|
{
|
||||||
type QueryResponse = T;
|
type QueryResponse = T;
|
||||||
|
|
||||||
|
@ -132,12 +132,7 @@ pub fn find_associated_item<'tcx>(
|
|||||||
let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs);
|
let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs);
|
||||||
let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id,
|
let substs = translate_substs(&infcx, param_env, impl_data.impl_def_id,
|
||||||
substs, node_item.node);
|
substs, node_item.node);
|
||||||
let substs = infcx.tcx.erase_regions(&substs);
|
infcx.tcx.erase_regions(&substs)
|
||||||
tcx.lift(&substs).unwrap_or_else(||
|
|
||||||
bug!("find_method: translate_substs \
|
|
||||||
returned {:?} which contains inference types/regions",
|
|
||||||
substs)
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
(node_item.item.def_id, substs)
|
(node_item.item.def_id, substs)
|
||||||
}
|
}
|
||||||
|
@ -192,9 +192,12 @@ impl<'tcx> ty::TyS<'tcx> {
|
|||||||
|
|
||||||
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
|
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
|
||||||
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
|
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
|
||||||
ty::Array(_, n) => match n.assert_usize(tcx) {
|
ty::Array(_, n) => {
|
||||||
Some(n) => format!("array of {} elements", n).into(),
|
let n = tcx.lift_to_global(&n).unwrap();
|
||||||
None => "array".into(),
|
match n.assert_usize(tcx) {
|
||||||
|
Some(n) => format!("array of {} elements", n).into(),
|
||||||
|
None => "array".into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ty::Slice(_) => "slice".into(),
|
ty::Slice(_) => "slice".into(),
|
||||||
ty::RawPtr(_) => "*-ptr".into(),
|
ty::RawPtr(_) => "*-ptr".into(),
|
||||||
|
@ -2262,7 +2262,6 @@ impl<'tcx> Const<'tcx> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_bits(tcx: TyCtxt<'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> &'tcx Self {
|
pub fn from_bits(tcx: TyCtxt<'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> &'tcx Self {
|
||||||
let ty = tcx.lift_to_global(&ty).unwrap();
|
|
||||||
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
|
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
|
||||||
panic!("could not compute layout for {:?}: {:?}", ty, e)
|
panic!("could not compute layout for {:?}: {:?}", ty, e)
|
||||||
}).size;
|
}).size;
|
||||||
@ -2289,7 +2288,6 @@ impl<'tcx> Const<'tcx> {
|
|||||||
if self.ty != ty.value {
|
if self.ty != ty.value {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ty = tcx.lift_to_global(&ty).unwrap();
|
|
||||||
let size = tcx.layout_of(ty).ok()?.size;
|
let size = tcx.layout_of(ty).ok()?.size;
|
||||||
self.val.try_to_bits(size)
|
self.val.try_to_bits(size)
|
||||||
}
|
}
|
||||||
@ -2300,15 +2298,14 @@ impl<'tcx> Const<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn assert_bits(&self, tcx: TyCtxt<'_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option<u128> {
|
pub fn assert_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option<u128> {
|
||||||
assert_eq!(self.ty, ty.value);
|
assert_eq!(self.ty, ty.value);
|
||||||
let ty = tcx.lift_to_global(&ty).unwrap();
|
|
||||||
let size = tcx.layout_of(ty).ok()?.size;
|
let size = tcx.layout_of(ty).ok()?.size;
|
||||||
self.val.try_to_bits(size)
|
self.val.try_to_bits(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn assert_bool(&self, tcx: TyCtxt<'_>) -> Option<bool> {
|
pub fn assert_bool(&self, tcx: TyCtxt<'tcx>) -> Option<bool> {
|
||||||
self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.bool)).and_then(|v| match v {
|
self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.bool)).and_then(|v| match v {
|
||||||
0 => Some(false),
|
0 => Some(false),
|
||||||
1 => Some(true),
|
1 => Some(true),
|
||||||
@ -2317,18 +2314,18 @@ impl<'tcx> Const<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn assert_usize(&self, tcx: TyCtxt<'_>) -> Option<u64> {
|
pub fn assert_usize(&self, tcx: TyCtxt<'tcx>) -> Option<u64> {
|
||||||
self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.usize)).map(|v| v as u64)
|
self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.usize)).map(|v| v as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unwrap_bits(&self, tcx: TyCtxt<'_>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 {
|
pub fn unwrap_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 {
|
||||||
self.assert_bits(tcx, ty).unwrap_or_else(||
|
self.assert_bits(tcx, ty).unwrap_or_else(||
|
||||||
bug!("expected bits of {}, got {:#?}", ty.value, self))
|
bug!("expected bits of {}, got {:#?}", ty.value, self))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unwrap_usize(&self, tcx: TyCtxt<'_>) -> u64 {
|
pub fn unwrap_usize(&self, tcx: TyCtxt<'tcx>) -> u64 {
|
||||||
self.assert_usize(tcx).unwrap_or_else(||
|
self.assert_usize(tcx).unwrap_or_else(||
|
||||||
bug!("expected constant usize, got {:#?}", self))
|
bug!("expected constant usize, got {:#?}", self))
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
|
|||||||
// "Lift" into the gcx -- once regions are erased, this type should be in the
|
// "Lift" into the gcx -- once regions are erased, this type should be in the
|
||||||
// global arenas; this "lift" operation basically just asserts that is true, but
|
// global arenas; this "lift" operation basically just asserts that is true, but
|
||||||
// that is useful later.
|
// that is useful later.
|
||||||
let drop_place_ty = gcx.lift(&drop_place_ty).unwrap();
|
gcx.lift_to_global(&drop_place_ty).unwrap();
|
||||||
|
|
||||||
debug!("visit_terminator_drop \
|
debug!("visit_terminator_drop \
|
||||||
loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",
|
loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",
|
||||||
|
@ -863,8 +863,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
});
|
});
|
||||||
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
|
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
|
||||||
|
|
||||||
// `lift` will only fail if we failed to promote some region.
|
// `lift_to_global` will only fail if we failed to promote some region.
|
||||||
let ty = gcx.lift(&ty)?;
|
gcx.lift_to_global(&ty)?;
|
||||||
|
|
||||||
Some(ClosureOutlivesSubject::Ty(ty))
|
Some(ClosureOutlivesSubject::Ty(ty))
|
||||||
}
|
}
|
||||||
|
@ -1866,7 +1866,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// `Sized` bound in no way depends on precise regions, so this
|
// `Sized` bound in no way depends on precise regions, so this
|
||||||
// shouldn't affect `is_sized`.
|
// shouldn't affect `is_sized`.
|
||||||
let gcx = tcx.global_tcx();
|
let gcx = tcx.global_tcx();
|
||||||
let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap();
|
let erased_ty = tcx.erase_regions(&ty);
|
||||||
if !erased_ty.is_sized(gcx.at(span), self.param_env) {
|
if !erased_ty.is_sized(gcx.at(span), self.param_env) {
|
||||||
// in current MIR construction, all non-control-flow rvalue
|
// in current MIR construction, all non-control-flow rvalue
|
||||||
// expressions evaluate through `as_temp` or `into` a return
|
// expressions evaluate through `as_temp` or `into` a return
|
||||||
@ -2652,7 +2652,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
|
|
||||||
fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
|
fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
|
||||||
where
|
where
|
||||||
T: type_op::normalize::Normalizable<'tcx> + Copy,
|
T: type_op::normalize::Normalizable<'tcx> + Copy + 'tcx,
|
||||||
{
|
{
|
||||||
debug!("normalize(value={:?}, location={:?})", value, location);
|
debug!("normalize(value={:?}, location={:?})", value, location);
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
|
@ -569,7 +569,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
|
|
||||||
// Helper to get a `-1` value of the appropriate type
|
// Helper to get a `-1` value of the appropriate type
|
||||||
fn neg_1_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
fn neg_1_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
||||||
let param_ty = ty::ParamEnv::empty().and(self.hir.tcx().lift_to_global(&ty).unwrap());
|
let param_ty = ty::ParamEnv::empty().and(ty);
|
||||||
let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits();
|
let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits();
|
||||||
let n = (!0u128) >> (128 - bits);
|
let n = (!0u128) >> (128 - bits);
|
||||||
let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty);
|
let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty);
|
||||||
@ -580,7 +580,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
// Helper to get the minimum value of the appropriate type
|
// Helper to get the minimum value of the appropriate type
|
||||||
fn minval_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
fn minval_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
||||||
assert!(ty.is_signed());
|
assert!(ty.is_signed());
|
||||||
let param_ty = ty::ParamEnv::empty().and(self.hir.tcx().lift_to_global(&ty).unwrap());
|
let param_ty = ty::ParamEnv::empty().and(ty);
|
||||||
let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits();
|
let bits = self.hir.tcx().layout_of(param_ty).unwrap().size.bits();
|
||||||
let n = 1 << (bits - 1);
|
let n = 1 << (bits - 1);
|
||||||
let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty);
|
let literal = ty::Const::from_bits(self.hir.tcx(), n, param_ty);
|
||||||
|
@ -151,7 +151,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>(
|
|||||||
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
|
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
|
||||||
|
|
||||||
let gcx = tcx.global_tcx();
|
let gcx = tcx.global_tcx();
|
||||||
let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap();
|
let erased_ty = tcx.erase_regions(&ty);
|
||||||
if erased_ty.needs_drop(gcx, ctxt.param_env) {
|
if erased_ty.needs_drop(gcx, ctxt.param_env) {
|
||||||
each_child(child);
|
each_child(child);
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,7 +18,7 @@ crate fn lit_to_const<'tcx>(
|
|||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
|
|
||||||
let trunc = |n| {
|
let trunc = |n| {
|
||||||
let param_ty = ParamEnv::reveal_all().and(tcx.lift_to_global(&ty).unwrap());
|
let param_ty = ParamEnv::reveal_all().and(ty);
|
||||||
let width = tcx.layout_of(param_ty).map_err(|_| LitToConstError::Reported)?.size;
|
let width = tcx.layout_of(param_ty).map_err(|_| LitToConstError::Reported)?.size;
|
||||||
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
|
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
|
||||||
let result = truncate(n, width);
|
let result = truncate(n, width);
|
||||||
|
@ -191,12 +191,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
|
pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
|
||||||
let (ty, param_env) = self.tcx.lift_to_global(&(ty, self.param_env)).unwrap_or_else(|| {
|
ty.needs_drop(self.tcx.global_tcx(), self.param_env)
|
||||||
bug!("MIR: Cx::needs_drop({:?}, {:?}) got \
|
|
||||||
type with inference types/regions",
|
|
||||||
ty, self.param_env);
|
|
||||||
});
|
|
||||||
ty.needs_drop(self.tcx.global_tcx(), param_env)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tcx(&self) -> TyCtxt<'tcx> {
|
pub fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
|
@ -1311,7 +1311,7 @@ fn is_useful_specialized<'p, 'a: 'p, 'tcx: 'a>(
|
|||||||
/// Returns `None` in case of a catch-all, which can't be specialized.
|
/// Returns `None` in case of a catch-all, which can't be specialized.
|
||||||
fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
|
fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
|
||||||
pat: &Pattern<'tcx>,
|
pat: &Pattern<'tcx>,
|
||||||
pcx: PatternContext<'_>)
|
pcx: PatternContext<'tcx>)
|
||||||
-> Option<Vec<Constructor<'tcx>>>
|
-> Option<Vec<Constructor<'tcx>>>
|
||||||
{
|
{
|
||||||
match *pat.kind {
|
match *pat.kind {
|
||||||
|
@ -37,8 +37,7 @@ fn normalize_ty_after_erasing_regions<'tcx>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let normalized_value = infcx.resolve_vars_if_possible(&normalized_value);
|
let normalized_value = infcx.resolve_vars_if_possible(&normalized_value);
|
||||||
let normalized_value = infcx.tcx.erase_regions(&normalized_value);
|
infcx.tcx.erase_regions(&normalized_value)
|
||||||
tcx.lift_to_global(&normalized_value).unwrap()
|
|
||||||
}
|
}
|
||||||
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
|
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user