Skip to content

Commit 250979c

Browse files
committed
Implement vtable shim generation.
1 parent 1fb0855 commit 250979c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/librustc_mir/shim.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4343
let mut result = match instance {
4444
ty::InstanceDef::Item(..) =>
4545
bug!("item {:?} passed to make_shim", instance),
46-
ty::InstanceDef::VtableShim(..) => {
47-
unimplemented!("make_shim({:?})", instance);
46+
ty::InstanceDef::VtableShim(def_id) => {
47+
build_call_shim(
48+
tcx,
49+
def_id,
50+
Adjustment::DerefMove,
51+
CallKind::Direct(def_id),
52+
None,
53+
)
4854
}
4955
ty::InstanceDef::FnPtrShim(def_id, ty) => {
5056
let trait_ = tcx.trait_of_item(def_id).unwrap();
@@ -131,6 +137,7 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
131137
enum Adjustment {
132138
Identity,
133139
Deref,
140+
DerefMove,
134141
RefMut,
135142
}
136143

@@ -704,6 +711,14 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
704711
let rcvr = match rcvr_adjustment {
705712
Adjustment::Identity => Operand::Move(rcvr_l),
706713
Adjustment::Deref => Operand::Copy(rcvr_l.deref()),
714+
Adjustment::DerefMove => {
715+
// fn(Self, ...) -> fn(*mut Self, ...)
716+
let arg_ty = local_decls[rcvr_arg].ty;
717+
assert!(arg_ty.is_self());
718+
local_decls[rcvr_arg].ty = tcx.mk_mut_ptr(arg_ty);
719+
720+
Operand::Copy(rcvr_l.deref())
721+
}
707722
Adjustment::RefMut => {
708723
// let rcvr = &mut rcvr;
709724
let ref_rcvr = local_decls.push(temp_decl(

0 commit comments

Comments
 (0)