Skip to content

Commit 6572a46

Browse files
authored
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
2 parents 6dc035e + ee338c3 commit 6572a46

File tree

13 files changed

+38
-38
lines changed

13 files changed

+38
-38
lines changed

src/librustc/infer/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ impl_trans_normalize!('gcx,
583583
ty::FnSig<'gcx>,
584584
&'gcx ty::BareFnTy<'gcx>,
585585
ty::ClosureSubsts<'gcx>,
586-
ty::PolyTraitRef<'gcx>
586+
ty::PolyTraitRef<'gcx>,
587+
ty::ExistentialTraitRef<'gcx>
587588
);
588589

589590
impl<'gcx> TransNormalize<'gcx> for LvalueTy<'gcx> {
@@ -603,6 +604,18 @@ impl<'gcx> TransNormalize<'gcx> for LvalueTy<'gcx> {
603604

604605
// NOTE: Callable from trans only!
605606
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
607+
/// Currently, higher-ranked type bounds inhibit normalization. Therefore,
608+
/// each time we erase them in translation, we need to normalize
609+
/// the contents.
610+
pub fn erase_late_bound_regions_and_normalize<T>(self, value: &ty::Binder<T>)
611+
-> T
612+
where T: TransNormalize<'tcx>
613+
{
614+
assert!(!value.needs_subst());
615+
let value = self.erase_late_bound_regions(value);
616+
self.normalize_associated_type(&value)
617+
}
618+
606619
pub fn normalize_associated_type<T>(self, value: &T) -> T
607620
where T: TransNormalize<'tcx>
608621
{

src/librustc_trans/base.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
10501050
let fn_ty = ccx.tcx().erase_regions(&fn_ty);
10511051
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &fn_ty);
10521052

1053-
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
1054-
let sig = ccx.tcx().normalize_associated_type(&sig);
1053+
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(fn_ty.fn_sig());
10551054
let abi = fn_ty.fn_abi();
10561055

10571056
let lldecl = match ccx.instances().borrow().get(&instance) {
@@ -1073,8 +1072,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10731072
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
10741073
let ctor_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &ctor_ty);
10751074

1076-
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
1077-
let sig = ccx.tcx().normalize_associated_type(&sig);
1075+
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&ctor_ty.fn_sig());
10781076
let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
10791077

10801078
let (arena, fcx): (TypedArena<_>, FunctionContext);

src/librustc_trans/callee.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ impl<'tcx> Callee<'tcx> {
184184
pub fn direct_fn_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
185185
extra_args: &[Ty<'tcx>]) -> FnType {
186186
let abi = self.ty.fn_abi();
187-
let sig = ccx.tcx().erase_late_bound_regions(self.ty.fn_sig());
188-
let sig = ccx.tcx().normalize_associated_type(&sig);
187+
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(self.ty.fn_sig());
189188
let mut fn_ty = FnType::unadjusted(ccx, abi, &sig, extra_args);
190189
if let Virtual(_) = self.data {
191190
// 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>(
327326
bare_fn_ty);
328327
}
329328
};
330-
let sig = tcx.erase_late_bound_regions(sig);
331-
let sig = ccx.tcx().normalize_associated_type(&sig);
329+
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
332330
let tuple_input_ty = tcx.mk_tup(sig.inputs.to_vec());
333331
let sig = ty::FnSig {
334332
inputs: vec![bare_fn_ty_maybe_ref,

src/librustc_trans/closure.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
6161

6262
// Compute the rust-call form of the closure call method.
6363
let sig = &tcx.closure_type(closure_id, substs).sig;
64-
let sig = tcx.erase_late_bound_regions(sig);
65-
let sig = tcx.normalize_associated_type(&sig);
64+
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
6665
let closure_type = tcx.mk_closure_from_closure_substs(closure_id, substs);
6766
let function_type = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {
6867
unsafety: hir::Unsafety::Normal,
@@ -126,8 +125,7 @@ pub fn trans_closure_body_via_mir<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
126125
// of the closure expression.
127126

128127
let sig = &tcx.closure_type(closure_def_id, closure_substs).sig;
129-
let sig = tcx.erase_late_bound_regions(sig);
130-
let sig = tcx.normalize_associated_type(&sig);
128+
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
131129

132130
let closure_type = tcx.mk_closure_from_closure_substs(closure_def_id,
133131
closure_substs);
@@ -249,8 +247,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
249247
assert_eq!(abi, Abi::RustCall);
250248
sig.0.inputs[0] = closure_ty;
251249

252-
let sig = tcx.erase_late_bound_regions(&sig);
253-
let sig = tcx.normalize_associated_type(&sig);
250+
let sig = tcx.erase_late_bound_regions_and_normalize(&sig);
254251
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
255252

256253
let llonce_fn_ty = tcx.mk_fn_ptr(tcx.mk_bare_fn(ty::BareFnTy {

src/librustc_trans/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ pub fn type_pair_fields<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
114114
if tys.len() != 2 {
115115
return None;
116116
}
117-
Some([ccx.tcx().normalize_associated_type(&tys[0]),
118-
ccx.tcx().normalize_associated_type(&tys[1])])
117+
Some([tys[0], tys[1]])
119118
}
120119
_ => None
121120
}

src/librustc_trans/debuginfo/metadata.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ impl<'tcx> TypeMap<'tcx> {
236236
ty::TyTrait(ref trait_data) => {
237237
unique_type_id.push_str("trait ");
238238

239-
let principal = cx.tcx().erase_late_bound_regions(&trait_data.principal);
239+
let principal = cx.tcx().erase_late_bound_regions_and_normalize(
240+
&trait_data.principal);
240241

241242
from_def_id_and_substs(self,
242243
cx,
@@ -254,8 +255,7 @@ impl<'tcx> TypeMap<'tcx> {
254255

255256
unique_type_id.push_str(" fn(");
256257

257-
let sig = cx.tcx().erase_late_bound_regions(sig);
258-
let sig = cx.tcx().normalize_associated_type(&sig);
258+
let sig = cx.tcx().erase_late_bound_regions_and_normalize(sig);
259259

260260
for &parameter_type in &sig.inputs {
261261
let parameter_type_id =

src/librustc_trans/debuginfo/type_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
9494
output.push(']');
9595
},
9696
ty::TyTrait(ref trait_data) => {
97-
let principal = cx.tcx().erase_late_bound_regions(&trait_data.principal);
97+
let principal = cx.tcx().erase_late_bound_regions_and_normalize(
98+
&trait_data.principal);
9899
push_item_name(cx, principal.def_id, false, output);
99100
push_type_params(cx, principal.substs, output);
100101
},
@@ -112,8 +113,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
112113

113114
output.push_str("fn(");
114115

115-
let sig = cx.tcx().erase_late_bound_regions(sig);
116-
let sig = cx.tcx().normalize_associated_type(&sig);
116+
let sig = cx.tcx().erase_late_bound_regions_and_normalize(sig);
117117
if !sig.inputs.is_empty() {
118118
for &parameter_type in &sig.inputs {
119119
push_debuginfo_type_name(cx, parameter_type, true, output);

src/librustc_trans/declare.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
104104
fn_type: ty::Ty<'tcx>) -> ValueRef {
105105
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
106106
let abi = fn_type.fn_abi();
107-
let sig = ccx.tcx().erase_late_bound_regions(fn_type.fn_sig());
108-
let sig = ccx.tcx().normalize_associated_type(&sig);
107+
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(fn_type.fn_sig());
109108
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
110109

111110
let fty = FnType::new(ccx, abi, &sig, &[]);

src/librustc_trans/intrinsic.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
9999

100100
let _icx = push_ctxt("trans_intrinsic_call");
101101

102-
let (def_id, substs, sig) = match callee_ty.sty {
103-
ty::TyFnDef(def_id, substs, fty) => {
104-
let sig = tcx.erase_late_bound_regions(&fty.sig);
105-
(def_id, substs, tcx.normalize_associated_type(&sig))
106-
}
102+
let (def_id, substs, fty) = match callee_ty.sty {
103+
ty::TyFnDef(def_id, substs, ref fty) => (def_id, substs, fty),
107104
_ => bug!("expected fn item type, found {}", callee_ty)
108105
};
106+
107+
let sig = tcx.erase_late_bound_regions_and_normalize(&fty.sig);
109108
let arg_tys = sig.inputs;
110109
let ret_ty = sig.output;
111110
let name = tcx.item_name(def_id).as_str();
@@ -1108,8 +1107,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
11081107

11091108

11101109
let tcx = bcx.tcx();
1111-
let sig = tcx.erase_late_bound_regions(callee_ty.fn_sig());
1112-
let sig = tcx.normalize_associated_type(&sig);
1110+
let sig = tcx.erase_late_bound_regions_and_normalize(callee_ty.fn_sig());
11131111
let arg_tys = sig.inputs;
11141112

11151113
// every intrinsic takes a SIMD vector as its first argument

src/librustc_trans/meth.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
8080
_ => bug!()
8181
};
8282

83-
let sig = tcx.erase_late_bound_regions(sig);
84-
let sig = tcx.normalize_associated_type(&sig);
83+
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
8584
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
8685

8786
let llfn = declare::define_internal_fn(ccx, &function_name, callee.ty);

src/librustc_trans/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
418418
_ => bug!("{} is not callable", callee.ty)
419419
};
420420

421-
let sig = bcx.tcx().erase_late_bound_regions(sig);
421+
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(sig);
422422

423423
// Handle intrinsics old trans wants Expr's for, ourselves.
424424
let intrinsic = match (&callee.ty.sty, &callee.data) {

src/librustc_trans/trans_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub fn push_unique_type_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
452452

453453
output.push_str("fn(");
454454

455-
let sig = tcx.erase_late_bound_regions(sig);
455+
let sig = tcx.erase_late_bound_regions_and_normalize(sig);
456456
if !sig.inputs.is_empty() {
457457
for &parameter_type in &sig.inputs {
458458
push_unique_type_name(tcx, parameter_type, output);

src/librustc_trans/type_of.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
264264

265265
ty::TyFnDef(..) => Type::nil(cx),
266266
ty::TyFnPtr(f) => {
267-
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
268-
let sig = cx.tcx().normalize_associated_type(&sig);
267+
let sig = cx.tcx().erase_late_bound_regions_and_normalize(&f.sig);
269268
FnType::new(cx, f.abi, &sig, &[]).llvm_type(cx).ptr_to()
270269
}
271270
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),

0 commit comments

Comments
 (0)