Use ExistentialTraitRef throughout codegen
This commit is contained in:
parent
739ef83f31
commit
9dc41a048d
16 changed files with 71 additions and 63 deletions
|
@ -6,7 +6,7 @@ use cranelift_module::*;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint};
|
||||
use rustc_middle::ty::{Binder, ExistentialTraitRef, ScalarInt};
|
||||
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -167,7 +167,9 @@ pub(crate) fn codegen_const_value<'tcx>(
|
|||
&mut fx.constants_cx,
|
||||
fx.module,
|
||||
ty,
|
||||
dyn_ty.principal(),
|
||||
dyn_ty.principal().map(|principal| {
|
||||
fx.tcx.instantiate_bound_regions_with_erased(principal)
|
||||
}),
|
||||
);
|
||||
let local_data_id =
|
||||
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
|
@ -243,12 +245,9 @@ pub(crate) fn data_id_for_vtable<'tcx>(
|
|||
cx: &mut ConstantCx,
|
||||
module: &mut dyn Module,
|
||||
ty: Ty<'tcx>,
|
||||
trait_ref: Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>,
|
||||
trait_ref: Option<ExistentialTraitRef<'tcx>>,
|
||||
) -> DataId {
|
||||
let alloc_id = tcx.vtable_allocation((
|
||||
ty,
|
||||
trait_ref.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
|
||||
));
|
||||
let alloc_id = tcx.vtable_allocation((ty, trait_ref));
|
||||
data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not)
|
||||
}
|
||||
|
||||
|
@ -463,9 +462,15 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
|
|||
GlobalAlloc::Memory(target_alloc) => {
|
||||
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
|
||||
}
|
||||
GlobalAlloc::VTable(ty, dyn_ty) => {
|
||||
data_id_for_vtable(tcx, cx, module, ty, dyn_ty.principal())
|
||||
}
|
||||
GlobalAlloc::VTable(ty, dyn_ty) => data_id_for_vtable(
|
||||
tcx,
|
||||
cx,
|
||||
module,
|
||||
ty,
|
||||
dyn_ty
|
||||
.principal()
|
||||
.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
|
||||
),
|
||||
GlobalAlloc::Static(def_id) => {
|
||||
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
|
||||
{
|
||||
|
|
|
@ -61,7 +61,12 @@ pub(crate) fn unsized_info<'tcx>(
|
|||
old_info
|
||||
}
|
||||
}
|
||||
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(fx, source, data.principal()),
|
||||
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(
|
||||
fx,
|
||||
source,
|
||||
data.principal()
|
||||
.map(|principal| fx.tcx.instantiate_bound_regions_with_erased(principal)),
|
||||
),
|
||||
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
|
|||
pub(crate) fn get_vtable<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||
trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
|
||||
) -> Value {
|
||||
let data_id = data_id_for_vtable(fx.tcx, &mut fx.constants_cx, fx.module, ty, trait_ref);
|
||||
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue