Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TBD 6: extension conformances, fix bad tests. #8836

Merged
merged 3 commits into from Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 additions & 14 deletions lib/TBDGen/TBDGen.cpp
Expand Up @@ -60,6 +60,23 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
addSymbol(linkage.getName());
}

void addConformances(DeclContext *DC) {
for (auto conformance : DC->getLocalConformances()) {
auto needsWTable = Lowering::TypeConverter::protocolRequiresWitnessTable(
conformance->getProtocol());
if (!needsWTable)
continue;

// Only normal conformances get symbols; the others get any public symbols
// from their parent normal conformance.
if (conformance->getKind() != ProtocolConformanceKind::Normal)
continue;

addSymbol(LinkEntity::forDirectProtocolWitnessTable(conformance));
addSymbol(LinkEntity::forProtocolWitnessTableAccessFunction(conformance));
}
}

public:
TBDGenVisitor(StringSet &symbols,
const UniversalLinkageInfo &universalLinkInfo,
Expand Down Expand Up @@ -95,6 +112,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {

void visitClassDecl(ClassDecl *CD);

void visitExtensionDecl(ExtensionDecl *ED);

void visitProtocolDecl(ProtocolDecl *PD) {
addSymbol(LinkEntity::forProtocolDescriptor(PD));

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

// There are symbols associated with any protocols this type conforms to.
for (auto conformance : NTD->getLocalConformances()) {
auto needsWTable = Lowering::TypeConverter::protocolRequiresWitnessTable(
conformance->getProtocol());
if (!needsWTable)
continue;

// Only normal conformances get symbols; the others get any public symbols
// from their parent normal conformance.
if (conformance->getKind() != ProtocolConformanceKind::Normal)
continue;

addSymbol(LinkEntity::forDirectProtocolWitnessTable(conformance));
addSymbol(LinkEntity::forProtocolWitnessTableAccessFunction(conformance));
}
addConformances(NTD);

visitMembers(NTD);
}
Expand Down Expand Up @@ -283,6 +289,14 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
visitNominalTypeDecl(CD);
}

void TBDGenVisitor::visitExtensionDecl(ExtensionDecl *ED) {
if (!ED->getExtendedType()->isExistentialType()) {
addConformances(ED);
}

visitMembers(ED);
}

void swift::enumeratePublicSymbols(FileUnit *file, StringSet &symbols,
bool hasMultipleIRGenThreads,
bool isWholeModule) {
Expand Down
4 changes: 4 additions & 0 deletions test/TBD/Inputs/extension_types.swift
@@ -0,0 +1,4 @@
public protocol Foreign {}

public struct ForeignStruct {}
public struct ForeignStruct2 {}
File renamed without changes.
2 changes: 1 addition & 1 deletion test/TBD/class.swift
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s

open class OpenNothing {}

Expand Down
2 changes: 1 addition & 1 deletion test/TBD/class_objc.swift
@@ -1,4 +1,4 @@
// 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
// 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

// REQUIRES: objc_interop

Expand Down
40 changes: 40 additions & 0 deletions test/TBD/extension.swift
@@ -0,0 +1,40 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/ExtensionTypes.swiftmodule
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir -I %t %s

import ExtensionTypes

public protocol Public {}
internal protocol Internal {}
private protocol Private {}

extension ForeignStruct: Foreign {}
extension ForeignStruct: Public {}
extension ForeignStruct: Internal {}
extension ForeignStruct: Private {}
extension ForeignStruct2: Foreign, Public, Internal, Private {}

public struct PublicStruct {}
public struct PublicStruct2 {}
internal struct InternalStruct {}
internal struct InternalStruct2 {}
private struct PrivateStruct {}
private struct PrivateStruct2 {}

extension PublicStruct: Foreign {}
extension PublicStruct: Public {}
extension PublicStruct: Internal {}
extension PublicStruct: Private {}
extension PublicStruct2: Foreign, Public, Internal, Private {}

extension InternalStruct: Foreign {}
extension InternalStruct: Public {}
extension InternalStruct: Internal {}
extension InternalStruct: Private {}
extension InternalStruct2: Foreign, Public, Internal, Private {}

extension PrivateStruct: Foreign {}
extension PrivateStruct: Public {}
extension PrivateStruct: Internal {}
extension PrivateStruct: Private {}
extension PrivateStruct2: Foreign, Public, Internal, Private {}
2 changes: 1 addition & 1 deletion test/TBD/function.swift
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s

public func publicNoArgs() {}
public func publicSomeArgs(_: Int, x: Int) {}
Expand Down
2 changes: 1 addition & 1 deletion test/TBD/global.swift
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s

public let publicLet: Int = 0
internal let internalLet: Int = 0
Expand Down
2 changes: 1 addition & 1 deletion test/TBD/main.swift
@@ -1,3 +1,3 @@
// RUN: %target-swift-frontend -c -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -module-name test -validate-tbd-against-ir %s

// Top-level code (i.e. implicit `main`) should be handled
2 changes: 1 addition & 1 deletion test/TBD/protocol.swift
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s

public protocol Public {
func publicMethod()
Expand Down
2 changes: 1 addition & 1 deletion test/TBD/struct.swift
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -c -parse-as-library -module-name test -validate-tbd-against-ir %s
// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -validate-tbd-against-ir %s

public struct PublicNothing {}

Expand Down