Skip to content

Commit 192e7c4

Browse files
committed
Add comments explaining how codegen works for dyn Trait methods
1 parent a468da9 commit 192e7c4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/librustc_codegen_llvm/abi.rs

+5
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
315315
_ => bug!("receiver type has unsupported layout: {:?}", layout)
316316
}
317317

318+
// In the case of Rc<Self>, we need to explicitly pass a *mut RcBox<Self>
319+
// with a Scalar (not ScalarPair) ABI. This is a hack that is understood
320+
// elsewhere in the compiler as a method on a `dyn Trait`.
321+
// To get the type `*mut RcBox<Self>`, we just keep unwrapping newtypes until we
322+
// get a built-in pointer type
318323
let mut fat_pointer_layout = layout;
319324
'descend_newtypes: while !fat_pointer_layout.ty.is_unsafe_ptr()
320325
&& !fat_pointer_layout.ty.is_region_ptr()

src/librustc_codegen_llvm/mir/block.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,12 @@ impl FunctionCx<'a, 'll, 'tcx> {
647647

648648
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
649649
if let Pair(..) = op.val {
650-
// descend through newtype wrappers until `op` is a builtin pointer to
651-
// `dyn Trait`, e.g. `*const dyn Trait`, `&mut dyn Trait`
650+
// In the case of Rc<Self>, we need to explicitly pass a
651+
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
652+
// that is understood elsewhere in the compiler as a method on
653+
// `dyn Trait`.
654+
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
655+
// we get a value of a built-in pointer type
652656
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
653657
&& !op.layout.ty.is_region_ptr()
654658
{

0 commit comments

Comments
 (0)