Skip to content

Commit a9beecc

Browse files
authored
[ParseableInterface] Don't bother computing default witness tables (#20437)
These are only used within the original module today, so we can skip filling them in.
1 parent ff7d03f commit a9beecc

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

lib/SILGen/SILGenType.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,13 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
823823
genVTable.emitVTable();
824824
}
825825

826-
// Build a default witness table if this is a protocol.
826+
// Build a default witness table if this is a protocol that needs one.
827827
if (auto protocol = dyn_cast<ProtocolDecl>(theType)) {
828-
if (!protocol->isObjC() &&
829-
protocol->isResilient())
830-
SGM.emitDefaultWitnessTable(protocol);
828+
if (!protocol->isObjC() && protocol->isResilient()) {
829+
auto *SF = protocol->getParentSourceFile();
830+
if (!SF || SF->Kind != SourceFileKind::Interface)
831+
SGM.emitDefaultWitnessTable(protocol);
832+
}
831833
return;
832834
}
833835

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,14 +3155,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
31553155
if (!PD->hasValidSignature())
31563156
return;
31573157

3158+
auto *SF = PD->getParentSourceFile();
31583159
{
31593160
// Check for circular inheritance within the protocol.
31603161
SmallVector<ProtocolDecl *, 8> path;
31613162
path.push_back(PD);
31623163
checkCircularity(TC, PD, diag::circular_protocol_def,
31633164
DescriptiveDeclKind::Protocol, path);
31643165

3165-
if (auto *SF = PD->getParentSourceFile()) {
3166+
if (SF) {
31663167
if (auto *tracker = SF->getReferencedNameTracker()) {
31673168
bool isNonPrivate =
31683169
(PD->getFormalAccess() > AccessLevel::FilePrivate);
@@ -3184,7 +3185,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
31843185

31853186
TC.checkDeclCircularity(PD);
31863187
if (PD->isResilient())
3187-
TC.inferDefaultWitnesses(PD);
3188+
if (!SF || SF->Kind != SourceFileKind::Interface)
3189+
TC.inferDefaultWitnesses(PD);
31883190

31893191
if (TC.Context.LangOpts.DebugGenericSignatures) {
31903192
auto requirementsSig =

test/ParseableInterface/Conformances.swiftinterface

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// swift-module-flags:
33

44
// RUN: %empty-directory(%t)
5-
// RUN: %target-swift-frontend -emit-module -enable-resilience -o %t/Conformances.swiftmodule %s
5+
// RUN: %target-swift-frontend -emit-module-path %t/Conformances.swiftmodule -enable-resilience -emit-sil -o %t/Conformances.sil %s
6+
// RUN: %FileCheck -check-prefix CHECK-MODULE %s < %t/Conformances.sil
7+
// RUN: %FileCheck -check-prefix NEGATIVE-MODULE %s < %t/Conformances.sil
68
// RUN: %target-swift-frontend -emit-sil -I %t %S/Inputs/ConformancesUser.swift -O | %FileCheck %s
79

810
public protocol MyProto {
@@ -11,6 +13,15 @@ public protocol MyProto {
1113
var prop: Int { get set }
1214
subscript(index: Int) -> Int { get set }
1315
}
16+
extension MyProto {
17+
public func method() {}
18+
}
19+
20+
// Make sure there's no default witness table. (But also make sure we printed at
21+
// least some regular witness tables, or we'll have to change the test.)
22+
// CHECK-MODULE: sil_witness_table{{.+}}: MyProto module Conformances
23+
// NEGATIVE-MODULE-NOT: sil_default_witness_table{{.+}}MyProto
24+
1425

1526
@_fixed_layout // allow conformance devirtualization
1627
public struct FullStructImpl: MyProto {
@@ -31,7 +42,8 @@ public struct OpaqueStructImpl: MyProto {}
3142

3243
// CHECK-LABEL: sil @$s16ConformancesUser10testOpaqueSiyF
3344
// CHECK: function_ref @$s12Conformances7MyProtoPxycfC
34-
// CHECK: function_ref @$s12Conformances7MyProtoP6methodyyF
45+
// Note the default implementation is filled in here.
46+
// CHECK: function_ref @$s12Conformances7MyProtoPAAE6methodyyF
3547
// CHECK: function_ref @$s12Conformances7MyProtoP4propSivs
3648
// CHECK: function_ref @$s12Conformances7MyProtoPyS2icig
3749
// CHECK: end sil function '$s16ConformancesUser10testOpaqueSiyF'

0 commit comments

Comments
 (0)