Add ty_fn_sig_vtable for getting adjusted signature for vtable shims.

This commit is contained in:
Masaki Hara 2018-09-11 23:26:38 +09:00
parent 824315a722
commit fe3f606cda
3 changed files with 21 additions and 2 deletions

View File

@ -492,7 +492,7 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'
info!("codegen_instance({})", instance);
let fn_ty = instance.ty(cx.tcx);
let sig = common::ty_fn_sig(cx, fn_ty);
let sig = common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim());
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
let lldecl = cx.instances.borrow().get(&instance).cloned().unwrap_or_else(||

View File

@ -56,7 +56,7 @@ pub fn get_fn(
debug!("get_fn({:?}: {:?}) => {}", instance, fn_ty, sym);
// Create a fn pointer with the substituted signature.
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig(cx, fn_ty));
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim()));
let llptrty = cx.layout_of(fn_ptr_ty).llvm_type(cx);
let llfn = if let Some(llfn) = declare::get_declared_value(cx, &sym) {

View File

@ -453,3 +453,22 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
_ => bug!("unexpected type {:?} to ty_fn_sig", ty)
}
}
pub fn ty_fn_sig_vtable<'a, 'tcx>(
cx: &CodegenCx<'a, 'tcx>,
ty: Ty<'tcx>,
is_vtable_shim: bool
) -> ty::PolyFnSig<'tcx>
{
let mut fn_sig = ty_fn_sig(cx, ty);
if is_vtable_shim {
// Modify fn(self, ...) to fn(self: *mut Self, ...)
fn_sig = fn_sig.map_bound(|mut fn_sig| {
let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
inputs_and_output[0] = cx.tcx.mk_mut_ptr(inputs_and_output[0]);
fn_sig.inputs_and_output = cx.tcx.intern_type_list(&inputs_and_output);
fn_sig
});
}
fn_sig
}