Skip to content

Commit 50a6666

Browse files
authored
Merge pull request swiftlang#33214 from jckarter/prune-vtables-internal-method-descriptors
IRGen: Don't drop method descriptors for vtable-elided internal methods.
2 parents 4fb0287 + d2bff92 commit 50a6666

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class LinkEntity {
575575
static bool isValidResilientMethodRef(SILDeclRef declRef) {
576576
if (declRef.isForeign)
577577
return false;
578-
578+
579579
auto *decl = declRef.getDecl();
580580
return (isa<ClassDecl>(decl->getDeclContext()) ||
581581
isa<ProtocolDecl>(decl->getDeclContext()));

lib/IRGen/GenMeta.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ namespace {
14921492
void addMethod(SILDeclRef fn) {
14931493
if (!VTable || methodRequiresReifiedVTableEntry(IGM, VTable, fn)) {
14941494
VTableEntries.push_back(fn);
1495-
} else if (hasPublicVisibility(fn.getLinkage(NotForDefinition))) {
1495+
} else {
14961496
// Emit a stub method descriptor and lookup function for nonoverridden
14971497
// methods so that resilient code sequences can still use them.
14981498
emitNonoverriddenMethod(fn);
@@ -1609,8 +1609,9 @@ namespace {
16091609
}
16101610

16111611
void emitMethodDescriptor(SILDeclRef fn) {
1612+
16121613
// Define the method descriptor to point to the current position in the
1613-
// nominal type descriptor.
1614+
// nominal type descriptor, if it has a well-defined symbol name.
16141615
IGM.defineMethodDescriptor(fn, Type,
16151616
B.getAddrOfCurrentPosition(IGM.MethodDescriptorStructTy));
16161617

@@ -1628,13 +1629,21 @@ namespace {
16281629
}
16291630

16301631
void emitNonoverriddenMethod(SILDeclRef fn) {
1631-
HasNonoverriddenMethods = true;
1632+
// TODO: Derivative functions do not distinguish themselves in the mangled
1633+
// names of method descriptor symbols yet, causing symbol name collisions.
1634+
if (fn.derivativeFunctionIdentifier)
1635+
return;
1636+
1637+
HasNonoverriddenMethods = true;
16321638
// Although this method is non-overridden and therefore left out of the
16331639
// vtable, we still need to maintain the ABI of a potentially-overridden
16341640
// method for external clients.
16351641

16361642
// Emit method dispatch thunk.
1637-
IGM.emitDispatchThunk(fn);
1643+
if (hasPublicVisibility(fn.getLinkage(NotForDefinition))) {
1644+
IGM.emitDispatchThunk(fn);
1645+
}
1646+
16381647
// Emit a freestanding method descriptor structure. This doesn't have to
16391648
// exist in the table in the class's context descriptor since it isn't
16401649
// in the vtable, but external clients need to be able to link against the

test/IRGen/vtable_non_overridden.sil

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ sil_vtable InternalA {
2424
#InternalA.bas : @InternalA_bas [nonoverridden]
2525
}
2626

27+
// -- we should still generate method descriptors for the elided methods
28+
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3fooyyFTq" =
29+
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalAC3basyyFTq" =
30+
2731
// -- only overridden entries in internal method descriptor table
2832
// CHECK-LABEL: @"$s21vtable_non_overridden9InternalACMn" =
2933
// CHECK-SAME: i32 2, %swift.method_descriptor

0 commit comments

Comments
 (0)