Skip to content

Commit e619cef

Browse files
authored
Merge pull request #8836 from huonw/symbol-list-6
TBD 6: extension conformances, fix bad tests.
2 parents c2d5ffd + 6b92605 commit e619cef

File tree

11 files changed

+79
-21
lines changed

11 files changed

+79
-21
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
6060
addSymbol(linkage.getName());
6161
}
6262

63+
void addConformances(DeclContext *DC) {
64+
for (auto conformance : DC->getLocalConformances()) {
65+
auto needsWTable = Lowering::TypeConverter::protocolRequiresWitnessTable(
66+
conformance->getProtocol());
67+
if (!needsWTable)
68+
continue;
69+
70+
// Only normal conformances get symbols; the others get any public symbols
71+
// from their parent normal conformance.
72+
if (conformance->getKind() != ProtocolConformanceKind::Normal)
73+
continue;
74+
75+
addSymbol(LinkEntity::forDirectProtocolWitnessTable(conformance));
76+
addSymbol(LinkEntity::forProtocolWitnessTableAccessFunction(conformance));
77+
}
78+
}
79+
6380
public:
6481
TBDGenVisitor(StringSet &symbols,
6582
const UniversalLinkageInfo &universalLinkInfo,
@@ -95,6 +112,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
95112

96113
void visitClassDecl(ClassDecl *CD);
97114

115+
void visitExtensionDecl(ExtensionDecl *ED);
116+
98117
void visitProtocolDecl(ProtocolDecl *PD) {
99118
addSymbol(LinkEntity::forProtocolDescriptor(PD));
100119

@@ -208,20 +227,7 @@ void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) {
208227
addSymbol(LinkEntity::forTypeMetadataAccessFunction(declaredType));
209228

210229
// There are symbols associated with any protocols this type conforms to.
211-
for (auto conformance : NTD->getLocalConformances()) {
212-
auto needsWTable = Lowering::TypeConverter::protocolRequiresWitnessTable(
213-
conformance->getProtocol());
214-
if (!needsWTable)
215-
continue;
216-
217-
// Only normal conformances get symbols; the others get any public symbols
218-
// from their parent normal conformance.
219-
if (conformance->getKind() != ProtocolConformanceKind::Normal)
220-
continue;
221-
222-
addSymbol(LinkEntity::forDirectProtocolWitnessTable(conformance));
223-
addSymbol(LinkEntity::forProtocolWitnessTableAccessFunction(conformance));
224-
}
230+
addConformances(NTD);
225231

226232
visitMembers(NTD);
227233
}
@@ -283,6 +289,14 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
283289
visitNominalTypeDecl(CD);
284290
}
285291

292+
void TBDGenVisitor::visitExtensionDecl(ExtensionDecl *ED) {
293+
if (!ED->getExtendedType()->isExistentialType()) {
294+
addConformances(ED);
295+
}
296+
297+
visitMembers(ED);
298+
}
299+
286300
void swift::enumeratePublicSymbols(FileUnit *file, StringSet &symbols,
287301
bool hasMultipleIRGenThreads,
288302
bool isWholeModule) {

test/TBD/Inputs/extension_types.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public protocol Foreign {}
2+
3+
public struct ForeignStruct {}
4+
public struct ForeignStruct2 {}

test/TBD/class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s
22

33
open class OpenNothing {}
44

test/TBD/class_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -import-objc-header %S/Input/objc_class_header.h -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -import-objc-header %S/Inputs/objc_class_header.h -validate-tbd-against-ir %s
22

33
// REQUIRES: objc_interop
44

test/TBD/extension.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/ExtensionTypes.swiftmodule
3+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir -I %t %s
4+
5+
import ExtensionTypes
6+
7+
public protocol Public {}
8+
internal protocol Internal {}
9+
private protocol Private {}
10+
11+
extension ForeignStruct: Foreign {}
12+
extension ForeignStruct: Public {}
13+
extension ForeignStruct: Internal {}
14+
extension ForeignStruct: Private {}
15+
extension ForeignStruct2: Foreign, Public, Internal, Private {}
16+
17+
public struct PublicStruct {}
18+
public struct PublicStruct2 {}
19+
internal struct InternalStruct {}
20+
internal struct InternalStruct2 {}
21+
private struct PrivateStruct {}
22+
private struct PrivateStruct2 {}
23+
24+
extension PublicStruct: Foreign {}
25+
extension PublicStruct: Public {}
26+
extension PublicStruct: Internal {}
27+
extension PublicStruct: Private {}
28+
extension PublicStruct2: Foreign, Public, Internal, Private {}
29+
30+
extension InternalStruct: Foreign {}
31+
extension InternalStruct: Public {}
32+
extension InternalStruct: Internal {}
33+
extension InternalStruct: Private {}
34+
extension InternalStruct2: Foreign, Public, Internal, Private {}
35+
36+
extension PrivateStruct: Foreign {}
37+
extension PrivateStruct: Public {}
38+
extension PrivateStruct: Internal {}
39+
extension PrivateStruct: Private {}
40+
extension PrivateStruct2: Foreign, Public, Internal, Private {}

test/TBD/function.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s
22

33
public func publicNoArgs() {}
44
public func publicSomeArgs(_: Int, x: Int) {}

test/TBD/global.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s
22

33
public let publicLet: Int = 0
44
internal let internalLet: Int = 0

test/TBD/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// RUN: %target-swift-frontend -c -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -module-name test -validate-tbd-against-ir %s
22

33
// Top-level code (i.e. implicit `main`) should be handled

test/TBD/protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s
22

33
public protocol Public {
44
func publicMethod()

test/TBD/struct.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
1+
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s
22

33
public struct PublicNothing {}
44

0 commit comments

Comments
 (0)