Auto merge of #37129 - arielb1:erased-normal, r=eddyb
normalize types every time HR regions are erased Associated type normalization is inhibited by higher-ranked regions. Therefore, every time we erase them, we must re-normalize. I was meaning to introduce this change some time ago, but we used to erase regions in generic context, which broke this terribly (because you can't always normalize in a generic context). That seems to be gone now. Ensure this by having a `erase_late_bound_regions_and_normalize` function. Fixes #37109 (the missing call was in mir::block). r? @eddyb
This commit is contained in:
commit
6572a46311
@ -583,7 +583,8 @@ impl_trans_normalize!('gcx,
|
|||||||
ty::FnSig<'gcx>,
|
ty::FnSig<'gcx>,
|
||||||
&'gcx ty::BareFnTy<'gcx>,
|
&'gcx ty::BareFnTy<'gcx>,
|
||||||
ty::ClosureSubsts<'gcx>,
|
ty::ClosureSubsts<'gcx>,
|
||||||
ty::PolyTraitRef<'gcx>
|
ty::PolyTraitRef<'gcx>,
|
||||||
|
ty::ExistentialTraitRef<'gcx>
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<'gcx> TransNormalize<'gcx> for LvalueTy<'gcx> {
|
impl<'gcx> TransNormalize<'gcx> for LvalueTy<'gcx> {
|
||||||
@ -603,6 +604,18 @@ impl<'gcx> TransNormalize<'gcx> for LvalueTy<'gcx> {
|
|||||||
|
|
||||||
// NOTE: Callable from trans only!
|
// NOTE: Callable from trans only!
|
||||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||||
|
/// Currently, higher-ranked type bounds inhibit normalization. Therefore,
|
||||||
|
/// each time we erase them in translation, we need to normalize
|
||||||
|
/// the contents.
|
||||||
|
pub fn erase_late_bound_regions_and_normalize<T>(self, value: &ty::Binder<T>)
|
||||||
|
-> T
|
||||||
|
where T: TransNormalize<'tcx>
|
||||||
|
{
|
||||||
|
assert!(!value.needs_subst());
|
||||||
|
let value = self.erase_late_bound_regions(value);
|
||||||
|
self.normalize_associated_type(&value)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn normalize_associated_type<T>(self, value: &T) -> T
|
pub fn normalize_associated_type<T>(self, value: &T) -> T
|
||||||
where T: TransNormalize<'tcx>
|
where T: TransNormalize<'tcx>
|
||||||
{
|
{
|
||||||
|
@ -1050,8 +1050,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
|
|||||||
let fn_ty = ccx.tcx().erase_regions(&fn_ty);
|
let fn_ty = ccx.tcx().erase_regions(&fn_ty);
|
||||||
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &fn_ty);
|
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &fn_ty);
|
||||||
|
|
||||||
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
|
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(fn_ty.fn_sig());
|
||||||
let sig = ccx.tcx().normalize_associated_type(&sig);
|
|
||||||
let abi = fn_ty.fn_abi();
|
let abi = fn_ty.fn_abi();
|
||||||
|
|
||||||
let lldecl = match ccx.instances().borrow().get(&instance) {
|
let lldecl = match ccx.instances().borrow().get(&instance) {
|
||||||
@ -1073,8 +1072,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
|
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
|
||||||
let ctor_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &ctor_ty);
|
let ctor_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &ctor_ty);
|
||||||
|
|
||||||
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
|
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&ctor_ty.fn_sig());
|
||||||
let sig = ccx.tcx().normalize_associated_type(&sig);
|
|
||||||
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
|
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
|
||||||
|
|
||||||
let (arena, fcx): (TypedArena<_>, FunctionContext);
|
let (arena, fcx): (TypedArena<_>, FunctionContext);
|
||||||
|
@ -184,8 +184,7 @@ impl<'tcx> Callee<'tcx> {
|
|||||||
pub fn direct_fn_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
|
pub fn direct_fn_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
|
||||||
extra_args: &[Ty<'tcx>]) -> FnType {
|
extra_args: &[Ty<'tcx>]) -> FnType {
|
||||||
let abi = self.ty.fn_abi();
|
let abi = self.ty.fn_abi();
|
||||||
let sig = ccx.tcx().erase_late_bound_regions(self.ty.fn_sig());
|
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(self.ty.fn_sig());
|
||||||
let sig = ccx.tcx().normalize_associated_type(&sig);
|
|
||||||
let mut fn_ty = FnType::unadjusted(ccx, abi, &sig, extra_args);
|
let mut fn_ty = FnType::unadjusted(ccx, abi, &sig, extra_args);
|
||||||
if let Virtual(_) = self.data {
|
if let Virtual(_) = self.data {
|
||||||
// Don't pass the vtable, it's not an argument of the virtual fn.
|
// Don't pass the vtable, it's not an argument of the virtual fn.
|
||||||
@ -327,8 +326,7 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
|
|||||||
bare_fn_ty);
|
bare_fn_ty);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = ccx.tcx().normalize_associated_type(&sig);
|
|
||||||
let tuple_input_ty = tcx.mk_tup(sig.inputs.to_vec());
|
let tuple_input_ty = tcx.mk_tup(sig.inputs.to_vec());
|
||||||
let sig = ty::FnSig {
|
let sig = ty::FnSig {
|
||||||
inputs: vec![bare_fn_ty_maybe_ref,
|
inputs: vec![bare_fn_ty_maybe_ref,
|
||||||
|
@ -61,8 +61,7 @@ fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
|
|
||||||
// Compute the rust-call form of the closure call method.
|
// Compute the rust-call form of the closure call method.
|
||||||
let sig = &tcx.closure_type(closure_id, substs).sig;
|
let sig = &tcx.closure_type(closure_id, substs).sig;
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = tcx.normalize_associated_type(&sig);
|
|
||||||
let closure_type = tcx.mk_closure_from_closure_substs(closure_id, substs);
|
let closure_type = tcx.mk_closure_from_closure_substs(closure_id, substs);
|
||||||
let function_type = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
|
let function_type = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
|
||||||
unsafety: hir::Unsafety::Normal,
|
unsafety: hir::Unsafety::Normal,
|
||||||
@ -126,8 +125,7 @@ pub fn trans_closure_body_via_mir<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
// of the closure expression.
|
// of the closure expression.
|
||||||
|
|
||||||
let sig = &tcx.closure_type(closure_def_id, closure_substs).sig;
|
let sig = &tcx.closure_type(closure_def_id, closure_substs).sig;
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = tcx.normalize_associated_type(&sig);
|
|
||||||
|
|
||||||
let closure_type = tcx.mk_closure_from_closure_substs(closure_def_id,
|
let closure_type = tcx.mk_closure_from_closure_substs(closure_def_id,
|
||||||
closure_substs);
|
closure_substs);
|
||||||
@ -249,8 +247,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
|
|||||||
assert_eq!(abi, Abi::RustCall);
|
assert_eq!(abi, Abi::RustCall);
|
||||||
sig.0.inputs[0] = closure_ty;
|
sig.0.inputs[0] = closure_ty;
|
||||||
|
|
||||||
let sig = tcx.erase_late_bound_regions(&sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(&sig);
|
||||||
let sig = tcx.normalize_associated_type(&sig);
|
|
||||||
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
|
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
|
||||||
|
|
||||||
let llonce_fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
|
let llonce_fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
|
||||||
|
@ -114,8 +114,7 @@ pub fn type_pair_fields<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
|
|||||||
if tys.len() != 2 {
|
if tys.len() != 2 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some([ccx.tcx().normalize_associated_type(&tys[0]),
|
Some([tys[0], tys[1]])
|
||||||
ccx.tcx().normalize_associated_type(&tys[1])])
|
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,8 @@ impl<'tcx> TypeMap<'tcx> {
|
|||||||
ty::TyTrait(ref trait_data) => {
|
ty::TyTrait(ref trait_data) => {
|
||||||
unique_type_id.push_str("trait ");
|
unique_type_id.push_str("trait ");
|
||||||
|
|
||||||
let principal = cx.tcx().erase_late_bound_regions(&trait_data.principal);
|
let principal = cx.tcx().erase_late_bound_regions_and_normalize(
|
||||||
|
&trait_data.principal);
|
||||||
|
|
||||||
from_def_id_and_substs(self,
|
from_def_id_and_substs(self,
|
||||||
cx,
|
cx,
|
||||||
@ -254,8 +255,7 @@ impl<'tcx> TypeMap<'tcx> {
|
|||||||
|
|
||||||
unique_type_id.push_str(" fn(");
|
unique_type_id.push_str(" fn(");
|
||||||
|
|
||||||
let sig = cx.tcx().erase_late_bound_regions(sig);
|
let sig = cx.tcx().erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = cx.tcx().normalize_associated_type(&sig);
|
|
||||||
|
|
||||||
for ¶meter_type in &sig.inputs {
|
for ¶meter_type in &sig.inputs {
|
||||||
let parameter_type_id =
|
let parameter_type_id =
|
||||||
|
@ -94,7 +94,8 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||||||
output.push(']');
|
output.push(']');
|
||||||
},
|
},
|
||||||
ty::TyTrait(ref trait_data) => {
|
ty::TyTrait(ref trait_data) => {
|
||||||
let principal = cx.tcx().erase_late_bound_regions(&trait_data.principal);
|
let principal = cx.tcx().erase_late_bound_regions_and_normalize(
|
||||||
|
&trait_data.principal);
|
||||||
push_item_name(cx, principal.def_id, false, output);
|
push_item_name(cx, principal.def_id, false, output);
|
||||||
push_type_params(cx, principal.substs, output);
|
push_type_params(cx, principal.substs, output);
|
||||||
},
|
},
|
||||||
@ -112,8 +113,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||||||
|
|
||||||
output.push_str("fn(");
|
output.push_str("fn(");
|
||||||
|
|
||||||
let sig = cx.tcx().erase_late_bound_regions(sig);
|
let sig = cx.tcx().erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = cx.tcx().normalize_associated_type(&sig);
|
|
||||||
if !sig.inputs.is_empty() {
|
if !sig.inputs.is_empty() {
|
||||||
for ¶meter_type in &sig.inputs {
|
for ¶meter_type in &sig.inputs {
|
||||||
push_debuginfo_type_name(cx, parameter_type, true, output);
|
push_debuginfo_type_name(cx, parameter_type, true, output);
|
||||||
|
@ -104,8 +104,7 @@ pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
|
|||||||
fn_type: ty::Ty<'tcx>) -> ValueRef {
|
fn_type: ty::Ty<'tcx>) -> ValueRef {
|
||||||
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
|
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
|
||||||
let abi = fn_type.fn_abi();
|
let abi = fn_type.fn_abi();
|
||||||
let sig = ccx.tcx().erase_late_bound_regions(fn_type.fn_sig());
|
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(fn_type.fn_sig());
|
||||||
let sig = ccx.tcx().normalize_associated_type(&sig);
|
|
||||||
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
|
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
|
||||||
|
|
||||||
let fty = FnType::new(ccx, abi, &sig, &[]);
|
let fty = FnType::new(ccx, abi, &sig, &[]);
|
||||||
|
@ -99,13 +99,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
|||||||
|
|
||||||
let _icx = push_ctxt("trans_intrinsic_call");
|
let _icx = push_ctxt("trans_intrinsic_call");
|
||||||
|
|
||||||
let (def_id, substs, sig) = match callee_ty.sty {
|
let (def_id, substs, fty) = match callee_ty.sty {
|
||||||
ty::TyFnDef(def_id, substs, fty) => {
|
ty::TyFnDef(def_id, substs, ref fty) => (def_id, substs, fty),
|
||||||
let sig = tcx.erase_late_bound_regions(&fty.sig);
|
|
||||||
(def_id, substs, tcx.normalize_associated_type(&sig))
|
|
||||||
}
|
|
||||||
_ => bug!("expected fn item type, found {}", callee_ty)
|
_ => bug!("expected fn item type, found {}", callee_ty)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let sig = tcx.erase_late_bound_regions_and_normalize(&fty.sig);
|
||||||
let arg_tys = sig.inputs;
|
let arg_tys = sig.inputs;
|
||||||
let ret_ty = sig.output;
|
let ret_ty = sig.output;
|
||||||
let name = tcx.item_name(def_id).as_str();
|
let name = tcx.item_name(def_id).as_str();
|
||||||
@ -1108,8 +1107,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
|
|||||||
|
|
||||||
|
|
||||||
let tcx = bcx.tcx();
|
let tcx = bcx.tcx();
|
||||||
let sig = tcx.erase_late_bound_regions(callee_ty.fn_sig());
|
let sig = tcx.erase_late_bound_regions_and_normalize(callee_ty.fn_sig());
|
||||||
let sig = tcx.normalize_associated_type(&sig);
|
|
||||||
let arg_tys = sig.inputs;
|
let arg_tys = sig.inputs;
|
||||||
|
|
||||||
// every intrinsic takes a SIMD vector as its first argument
|
// every intrinsic takes a SIMD vector as its first argument
|
||||||
|
@ -80,8 +80,7 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
|
|||||||
_ => bug!()
|
_ => bug!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
|
||||||
let sig = tcx.normalize_associated_type(&sig);
|
|
||||||
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
|
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
|
||||||
|
|
||||||
let llfn = declare::define_internal_fn(ccx, &function_name, callee.ty);
|
let llfn = declare::define_internal_fn(ccx, &function_name, callee.ty);
|
||||||
|
@ -418,7 +418,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
|||||||
_ => bug!("{} is not callable", callee.ty)
|
_ => bug!("{} is not callable", callee.ty)
|
||||||
};
|
};
|
||||||
|
|
||||||
let sig = bcx.tcx().erase_late_bound_regions(sig);
|
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(sig);
|
||||||
|
|
||||||
// Handle intrinsics old trans wants Expr's for, ourselves.
|
// Handle intrinsics old trans wants Expr's for, ourselves.
|
||||||
let intrinsic = match (&callee.ty.sty, &callee.data) {
|
let intrinsic = match (&callee.ty.sty, &callee.data) {
|
||||||
|
@ -452,7 +452,7 @@ pub fn push_unique_type_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
|
|
||||||
output.push_str("fn(");
|
output.push_str("fn(");
|
||||||
|
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
|
||||||
if !sig.inputs.is_empty() {
|
if !sig.inputs.is_empty() {
|
||||||
for ¶meter_type in &sig.inputs {
|
for ¶meter_type in &sig.inputs {
|
||||||
push_unique_type_name(tcx, parameter_type, output);
|
push_unique_type_name(tcx, parameter_type, output);
|
||||||
|
@ -264,8 +264,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
|
|||||||
|
|
||||||
ty::TyFnDef(..) => Type::nil(cx),
|
ty::TyFnDef(..) => Type::nil(cx),
|
||||||
ty::TyFnPtr(f) => {
|
ty::TyFnPtr(f) => {
|
||||||
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
|
let sig = cx.tcx().erase_late_bound_regions_and_normalize(&f.sig);
|
||||||
let sig = cx.tcx().normalize_associated_type(&sig);
|
|
||||||
FnType::new(cx, f.abi, &sig, &[]).llvm_type(cx).ptr_to()
|
FnType::new(cx, f.abi, &sig, &[]).llvm_type(cx).ptr_to()
|
||||||
}
|
}
|
||||||
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
|
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
|
||||||
|
Loading…
Reference in New Issue
Block a user