Skip to content

Commit e919d44

Browse files
committed
---
yaml --- r: 345973 b: refs/heads/master c: e9e357d h: refs/heads/master i: 345971: f228f5a
1 parent f599646 commit e919d44

File tree

20 files changed

+160
-127
lines changed

20 files changed

+160
-127
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 08be226ac3ae1f217456555a42369be4cc9f7440
2+
refs/heads/master: e9e357d3b68012a143ef8311cdb0ba48e497fb98
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Module.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ class ModuleDecl : public DeclContext, public TypeDecl {
385385
Optional<ProtocolConformanceRef>
386386
lookupConformance(Type type, ProtocolDecl *protocol);
387387

388+
/// Look for the conformance of the given existential type to the given
389+
/// protocol.
390+
Optional<ProtocolConformanceRef>
391+
lookupExistentialConformance(Type type, ProtocolDecl *protocol);
392+
388393
/// Find a member named \p name in \p container that was declared in this
389394
/// module.
390395
///

trunk/lib/AST/Module.cpp

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,57 @@ void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
570570
FORWARD(getDisplayDecls, (Results));
571571
}
572572

573+
Optional<ProtocolConformanceRef>
574+
ModuleDecl::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
575+
assert(type->isExistentialType());
576+
577+
// If the existential type cannot be represented or the protocol does not
578+
// conform to itself, there's no point in looking further.
579+
if (!protocol->existentialConformsToSelf())
580+
return None;
581+
582+
auto layout = type->getExistentialLayout();
583+
584+
// Due to an IRGen limitation, witness tables cannot be passed from an
585+
// existential to an archetype parameter, so for now we restrict this to
586+
// @objc protocols.
587+
if (!layout.isObjC()) {
588+
return None;
589+
}
590+
591+
// If the existential is class-constrained, the class might conform
592+
// concretely.
593+
if (auto superclass = layout.explicitSuperclass) {
594+
if (auto result = lookupConformance(superclass, protocol))
595+
return result;
596+
}
597+
598+
// Otherwise, the existential might conform abstractly.
599+
for (auto proto : layout.getProtocols()) {
600+
auto *protoDecl = proto->getDecl();
601+
602+
// If we found the protocol we're looking for, return an abstract
603+
// conformance to it.
604+
if (protoDecl == protocol)
605+
return ProtocolConformanceRef(protocol);
606+
607+
// If the protocol has a superclass constraint, we might conform
608+
// concretely.
609+
if (auto superclass = protoDecl->getSuperclass()) {
610+
if (auto result = lookupConformance(superclass, protocol))
611+
return result;
612+
}
613+
614+
// Now check refined protocols.
615+
if (protoDecl->inheritsFrom(protocol))
616+
return ProtocolConformanceRef(protocol);
617+
}
618+
619+
// We didn't find our protocol in the existential's list; it doesn't
620+
// conform.
621+
return None;
622+
}
623+
573624
Optional<ProtocolConformanceRef>
574625
ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol) {
575626
ASTContext &ctx = getASTContext();
@@ -609,52 +660,8 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol) {
609660
// An existential conforms to a protocol if the protocol is listed in the
610661
// existential's list of conformances and the existential conforms to
611662
// itself.
612-
if (type->isExistentialType()) {
613-
// If the existential type cannot be represented or the protocol does not
614-
// conform to itself, there's no point in looking further.
615-
if (!protocol->existentialConformsToSelf())
616-
return None;
617-
618-
auto layout = type->getExistentialLayout();
619-
620-
// Due to an IRGen limitation, witness tables cannot be passed from an
621-
// existential to an archetype parameter, so for now we restrict this to
622-
// @objc protocols.
623-
if (!layout.isObjC())
624-
return None;
625-
626-
// If the existential is class-constrained, the class might conform
627-
// concretely.
628-
if (auto superclass = layout.explicitSuperclass) {
629-
if (auto result = lookupConformance(superclass, protocol))
630-
return result;
631-
}
632-
633-
// Otherwise, the existential might conform abstractly.
634-
for (auto proto : layout.getProtocols()) {
635-
auto *protoDecl = proto->getDecl();
636-
637-
// If we found the protocol we're looking for, return an abstract
638-
// conformance to it.
639-
if (protoDecl == protocol)
640-
return ProtocolConformanceRef(protocol);
641-
642-
// If the protocol has a superclass constraint, we might conform
643-
// concretely.
644-
if (auto superclass = protoDecl->getSuperclass()) {
645-
if (auto result = lookupConformance(superclass, protocol))
646-
return result;
647-
}
648-
649-
// Now check refined protocols.
650-
if (protoDecl->inheritsFrom(protocol))
651-
return ProtocolConformanceRef(protocol);
652-
}
653-
654-
// We didn't find our protocol in the existential's list; it doesn't
655-
// conform.
656-
return None;
657-
}
663+
if (type->isExistentialType())
664+
return lookupExistentialConformance(type, protocol);
658665

659666
// Type variables have trivial conformances.
660667
if (type->isTypeVariableOrMember())

trunk/lib/AST/ProtocolConformance.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ ProtocolConformanceRef::subst(Type origType,
112112
if (substType->isOpenedExistential())
113113
return *this;
114114

115-
// If the substituted type is an existential, we have a self-conforming
116-
// existential being substituted in place of itself. There's no
117-
// conformance information in this case, so just return.
118-
if (substType->isObjCExistentialType())
119-
return *this;
120-
121115
auto *proto = getRequirement();
122116

123117
// Check the conformance map.
@@ -126,7 +120,13 @@ ProtocolConformanceRef::subst(Type origType,
126120
return *result;
127121
}
128122

129-
llvm_unreachable("Invalid conformance substitution");
123+
// The only remaining case is that the type is an existential that
124+
// self-conforms.
125+
assert(substType->isExistentialType());
126+
auto optConformance =
127+
proto->getModuleContext()->lookupExistentialConformance(substType, proto);
128+
assert(optConformance && "existential type didn't self-conform");
129+
return *optConformance;
130130
}
131131

132132
Type

trunk/tools/driver/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ add_swift_host_tool(swift
44
autolink_extract_main.cpp
55
modulewrap_main.cpp
66
swift_format_main.cpp
7-
LINK_LIBRARIES
8-
swiftDriver
9-
swiftFrontendTool
107
SWIFT_COMPONENT compiler
118
)
12-
9+
target_link_libraries(swift
10+
PRIVATE
11+
swiftDriver
12+
swiftFrontendTool)
1313
if(HAVE_UNICODE_LIBEDIT)
1414
target_link_libraries(swift PRIVATE edit)
1515
endif()
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
add_swift_host_tool(lldb-moduleimport-test
22
lldb-moduleimport-test.cpp
3-
LINK_LIBRARIES
4-
swiftASTSectionImporter swiftFrontend swiftClangImporter
53
SWIFT_COMPONENT tools
64
)
5+
target_link_libraries(lldb-moduleimport-test
6+
PRIVATE
7+
swiftASTSectionImporter
8+
swiftClangImporter
9+
swiftFrontend)
710

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
add_swift_host_tool(sil-func-extractor
22
SILFunctionExtractor.cpp
3-
LINK_LIBRARIES
4-
swiftFrontend
5-
swiftSILGen
6-
swiftSILOptimizer
7-
swiftSerialization
8-
swiftClangImporter
93
SWIFT_COMPONENT tools
104
)
5+
target_link_libraries(sil-func-extractor
6+
PRIVATE
7+
swiftClangImporter
8+
swiftFrontend
9+
swiftSerialization
10+
swiftSILGen
11+
swiftSILOptimizer)
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
add_swift_host_tool(sil-llvm-gen
22
SILLLVMGen.cpp
3-
LINK_LIBRARIES
4-
swiftFrontend
5-
swiftIRGen
6-
swiftSILGen
7-
swiftSILOptimizer
8-
# Clang libraries included to appease the linker on linux.
9-
clangBasic
10-
clangCodeGen
113
SWIFT_COMPONENT tools
124
)
5+
target_link_libraries(sil-llvm-gen
6+
PRIVATE
7+
swiftFrontend
8+
swiftIRGen
9+
swiftSILGen
10+
swiftSILOptimizer
11+
# Clang libraries included to appease the linker on linux.
12+
clangBasic
13+
clangCodeGen)

trunk/tools/sil-nm/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
add_swift_host_tool(sil-nm
22
SILNM.cpp
3-
LINK_LIBRARIES
4-
swiftFrontend
5-
swiftSILGen
6-
swiftSILOptimizer
7-
swiftSerialization
8-
swiftClangImporter
93
SWIFT_COMPONENT tools
104
)
5+
target_link_libraries(sil-nm
6+
PRIVATE
7+
swiftClangImporter
8+
swiftFrontend
9+
swiftSerialization
10+
swiftSILGen
11+
swiftSILOptimizer)

trunk/tools/sil-opt/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
add_swift_host_tool(sil-opt
22
SILOpt.cpp
3-
LINK_LIBRARIES
4-
swiftFrontend
5-
swiftIRGen
6-
swiftSILGen
7-
swiftSILOptimizer
8-
# Clang libraries included to appease the linker on linux.
9-
clangBasic
10-
clangCodeGen
113
SWIFT_COMPONENT tools
124
)
5+
target_link_libraries(sil-opt
6+
PRIVATE
7+
swiftFrontend
8+
swiftIRGen
9+
swiftSILGen
10+
swiftSILOptimizer
11+
# Clang libraries included to appease the linker on linux.
12+
clangBasic
13+
clangCodeGen)
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
add_swift_host_tool(sil-passpipeline-dumper
22
SILPassPipelineDumper.cpp
3-
LINK_LIBRARIES
4-
swiftFrontend
5-
swiftSILGen
6-
swiftSILOptimizer
7-
swiftSerialization
8-
swiftClangImporter
9-
# FIXME: Circular dependencies require re-listing these libraries.
10-
swiftSema
11-
swiftAST
123
SWIFT_COMPONENT tools
134
)
5+
target_link_libraries(sil-passpipeline-dumper
6+
PRIVATE
7+
swiftClangImporter
8+
swiftFrontend
9+
swiftSerialization
10+
swiftSILGen
11+
swiftSILOptimizer
12+
# FIXME: Circular dependencies require re-listing these libraries.
13+
swiftAST
14+
swiftSema)

trunk/tools/swift-api-digester/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ add_swift_host_tool(swift-api-digester
22
swift-api-digester.cpp
33
ModuleAnalyzerNodes.cpp
44
ModuleDiagsConsumer.cpp
5-
LINK_LIBRARIES swiftFrontend swiftIDE
65
SWIFT_COMPONENT tools
76
)
7+
target_link_libraries(swift-api-digester
8+
PRIVATE
9+
swiftFrontend
10+
swiftIDE)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
add_swift_fuzzer_host_tool(swift-demangle-fuzzer
22
swift-demangle-fuzzer.cpp
3-
LINK_LIBRARIES swiftDemangling
43
LLVM_COMPONENT_DEPENDS support
54
SWIFT_COMPONENT compiler
65
)
6+
target_link_libraries(swift-demangle-fuzzer
7+
PRIVATE
8+
swiftDemangling)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
add_swift_host_tool(swift-demangle-yamldump
22
swift-demangle-yamldump.cpp
3-
LINK_LIBRARIES swiftDemangling
43
LLVM_COMPONENT_DEPENDS support
54
SWIFT_COMPONENT tools
65
)
6+
target_link_libraries(swift-demangle-yamldump
7+
PRIVATE
8+
swiftDemangling)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
add_swift_host_tool(swift-demangle
22
swift-demangle.cpp
3-
LINK_LIBRARIES swiftDemangling
43
LLVM_COMPONENT_DEPENDS support
54
SWIFT_COMPONENT compiler
65
)
6+
target_link_libraries(swift-demangle
7+
PRIVATE
8+
swiftDemangling)

trunk/tools/swift-ide-test/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ add_swift_host_tool(swift-ide-test
22
swift-ide-test.cpp
33
ModuleAPIDiff.cpp
44
XMLValidator.cpp
5-
LINK_LIBRARIES
6-
swiftDriver
7-
swiftFrontend
8-
swiftIDE
95
SWIFT_COMPONENT tools
106
)
7+
target_link_libraries(swift-ide-test
8+
PRIVATE
9+
swiftDriver
10+
swiftFrontend
11+
swiftIDE)
1112

1213
# If libxml2 is available, make it available for swift-ide-test.
1314
if(SWIFT_HAVE_LIBXML)
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
add_swift_host_tool(swift-llvm-opt
22
LLVMOpt.cpp
3-
LINK_LIBRARIES
4-
swiftIRGen
5-
6-
# Swift libraries included to appease the linker on linux.
7-
swiftSema
8-
swiftAST
9-
10-
# Clang libraries included to appease the linker on linux.
11-
clangBasic
12-
clangCodeGen
13-
143
SWIFT_COMPONENT tools
154
)
5+
target_link_libraries(swift-llvm-opt
6+
PRIVATE
7+
swiftIRGen
8+
# Swift libraries included to appease the linker on linux.
9+
swiftSema
10+
swiftAST
11+
# Clang libraries included to appease the linker on linux.
12+
clangBasic
13+
clangCodeGen)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
add_swift_host_tool(swift-refactor
22
swift-refactor.cpp
3-
LINK_LIBRARIES swiftDriver swiftFrontend swiftIDE
43
SWIFT_COMPONENT tools
54
)
5+
target_link_libraries(swift-refactor
6+
PRIVATE
7+
swiftDriver
8+
swiftFrontend
9+
swiftIDE)

0 commit comments

Comments
 (0)