Refactor part of codegen_call_terminator
This commit is contained in:
parent
e0dc8d7801
commit
b562f95963
1 changed files with 44 additions and 47 deletions
|
@ -798,7 +798,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
let mut op = self.codegen_operand(&mut bx, arg);
|
let mut op = self.codegen_operand(&mut bx, arg);
|
||||||
|
|
||||||
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
|
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
|
||||||
if let Pair(..) = op.val {
|
match op.val {
|
||||||
|
Pair(data_ptr, meta) => {
|
||||||
// In the case of Rc<Self>, we need to explicitly pass a
|
// In the case of Rc<Self>, we need to explicitly pass a
|
||||||
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
|
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
|
||||||
// that is understood elsewhere in the compiler as a method on
|
// that is understood elsewhere in the compiler as a method on
|
||||||
|
@ -825,8 +826,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
|
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
|
||||||
// data pointer and vtable. Look up the method in the vtable, and pass
|
// data pointer and vtable. Look up the method in the vtable, and pass
|
||||||
// the data pointer as the first argument
|
// the data pointer as the first argument
|
||||||
match op.val {
|
|
||||||
Pair(data_ptr, meta) => {
|
|
||||||
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
||||||
&mut bx,
|
&mut bx,
|
||||||
meta,
|
meta,
|
||||||
|
@ -836,9 +835,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
llargs.push(data_ptr);
|
llargs.push(data_ptr);
|
||||||
continue 'make_args;
|
continue 'make_args;
|
||||||
}
|
}
|
||||||
other => bug!("expected a Pair, got {:?}", other),
|
Ref(data_ptr, Some(meta), _) => {
|
||||||
}
|
|
||||||
} else if let Ref(data_ptr, Some(meta), _) = op.val {
|
|
||||||
// by-value dynamic dispatch
|
// by-value dynamic dispatch
|
||||||
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
|
||||||
&mut bx,
|
&mut bx,
|
||||||
|
@ -848,8 +845,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
));
|
));
|
||||||
llargs.push(data_ptr);
|
llargs.push(data_ptr);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
span_bug!(span, "can't codegen a virtual call on {:?}", op);
|
_ => span_bug!(span, "can't codegen a virtual call on {:?}", op),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue