Skip to content

Commit 96bea7a

Browse files
Use ExistentialTraitRef throughout codegen
1 parent 9f44caa commit 96bea7a

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Diff for: src/constant.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cranelift_module::*;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88
use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint};
9-
use rustc_middle::ty::{Binder, ExistentialTraitRef, ScalarInt};
9+
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};
1010

1111
use crate::prelude::*;
1212

@@ -167,7 +167,9 @@ pub(crate) fn codegen_const_value<'tcx>(
167167
&mut fx.constants_cx,
168168
fx.module,
169169
ty,
170-
dyn_ty.principal(),
170+
dyn_ty.principal().map(|principal| {
171+
fx.tcx.instantiate_bound_regions_with_erased(principal)
172+
}),
171173
);
172174
let local_data_id =
173175
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
@@ -243,12 +245,9 @@ pub(crate) fn data_id_for_vtable<'tcx>(
243245
cx: &mut ConstantCx,
244246
module: &mut dyn Module,
245247
ty: Ty<'tcx>,
246-
trait_ref: Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>,
248+
trait_ref: Option<ExistentialTraitRef<'tcx>>,
247249
) -> DataId {
248-
let alloc_id = tcx.vtable_allocation((
249-
ty,
250-
trait_ref.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
251-
));
250+
let alloc_id = tcx.vtable_allocation((ty, trait_ref));
252251
data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not)
253252
}
254253

@@ -463,9 +462,15 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
463462
GlobalAlloc::Memory(target_alloc) => {
464463
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
465464
}
466-
GlobalAlloc::VTable(ty, dyn_ty) => {
467-
data_id_for_vtable(tcx, cx, module, ty, dyn_ty.principal())
468-
}
465+
GlobalAlloc::VTable(ty, dyn_ty) => data_id_for_vtable(
466+
tcx,
467+
cx,
468+
module,
469+
ty,
470+
dyn_ty
471+
.principal()
472+
.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
473+
),
469474
GlobalAlloc::Static(def_id) => {
470475
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
471476
{

Diff for: src/unsize.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ pub(crate) fn unsized_info<'tcx>(
6161
old_info
6262
}
6363
}
64-
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(fx, source, data.principal()),
64+
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(
65+
fx,
66+
source,
67+
data.principal()
68+
.map(|principal| fx.tcx.instantiate_bound_regions_with_erased(principal)),
69+
),
6570
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target),
6671
}
6772
}

Diff for: src/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
9090
pub(crate) fn get_vtable<'tcx>(
9191
fx: &mut FunctionCx<'_, '_, 'tcx>,
9292
ty: Ty<'tcx>,
93-
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
93+
trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
9494
) -> Value {
9595
let data_id = data_id_for_vtable(fx.tcx, &mut fx.constants_cx, fx.module, ty, trait_ref);
9696
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);

0 commit comments

Comments
 (0)