Skip to content

Commit 62b6d6b

Browse files
authored
Merge pull request #5782 from DougGregor/conforms-to-protocol-api
2 parents 337c71d + e045429 commit 62b6d6b

19 files changed

+327
-401
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ IDENTIFIER(hashValue)
4545
IDENTIFIER(init)
4646
IDENTIFIER(initStorage)
4747
IDENTIFIER(initialValue)
48+
IDENTIFIER(Key)
4849
IDENTIFIER(makeIterator)
4950
IDENTIFIER(Iterator)
5051
IDENTIFIER(load)

include/swift/AST/ProtocolConformance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
160160

161161
static Type
162162
getTypeWitnessByName(Type type,
163-
ProtocolConformance *conformance,
163+
ProtocolConformanceRef conformance,
164164
Identifier name,
165165
LazyResolver *resolver);
166166

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,7 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
38833883
// Find the Objective-C class type we bridge to.
38843884
if (conformance->isConcrete()) {
38853885
return ProtocolConformance::getTypeWitnessByName(
3886-
type, conformance->getConcrete(), Id_ObjectiveCType,
3886+
type, *conformance, Id_ObjectiveCType,
38873887
getLazyResolver());
38883888
} else {
38893889
return type->castTo<ArchetypeType>()->getNestedType(Id_ObjectiveCType)

lib/AST/ProtocolConformance.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ProtocolConformance::getTypeWitness(AssociatedTypeDecl *assocType,
156156

157157
Type
158158
ProtocolConformance::getTypeWitnessByName(Type type,
159-
ProtocolConformance *conformance,
159+
ProtocolConformanceRef conformance,
160160
Identifier name,
161161
LazyResolver *resolver) {
162162
// For an archetype, retrieve the nested type with the appropriate
@@ -167,21 +167,25 @@ ProtocolConformance::getTypeWitnessByName(Type type,
167167

168168
// Find the named requirement.
169169
AssociatedTypeDecl *assocType = nullptr;
170-
auto members = conformance->getProtocol()->lookupDirect(name);
170+
auto members = conformance.getRequirement()->lookupDirect(name);
171171
for (auto member : members) {
172172
assocType = dyn_cast<AssociatedTypeDecl>(member);
173173
if (assocType)
174174
break;
175175
}
176176

177+
// FIXME: Shouldn't this be a hard error?
177178
if (!assocType)
178179
return nullptr;
179-
180-
assert(conformance && "Missing conformance information");
181-
if (!conformance->hasTypeWitness(assocType, resolver)) {
180+
181+
if (conformance.isAbstract())
182+
return DependentMemberType::get(type, assocType);
183+
184+
auto concrete = conformance.getConcrete();
185+
if (!concrete->hasTypeWitness(assocType, resolver)) {
182186
return nullptr;
183187
}
184-
return conformance->getTypeWitness(assocType, resolver).getReplacement();
188+
return concrete->getTypeWitness(assocType, resolver).getReplacement();
185189
}
186190

187191
Witness ProtocolConformance::getWitness(ValueDecl *requirement,

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
875875
auto conformance = conformances.front();
876876
Type objcType = ProtocolConformance::getTypeWitnessByName(
877877
nominal->getDeclaredType(),
878-
conformance,
878+
ProtocolConformanceRef(conformance),
879879
ctx.Id_ObjectiveCType,
880880
nullptr);
881881
if (!objcType) return nullptr;

lib/SIL/Bridging.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
223223
assert(conformance && "Missing conformance?");
224224
Type bridgedTy =
225225
ProtocolConformance::getTypeWitnessByName(
226-
t, conformance, M.getASTContext().Id_ObjectiveCType,
226+
t, ProtocolConformanceRef(conformance),
227+
M.getASTContext().Id_ObjectiveCType,
227228
nullptr);
228229
assert(bridgedTy && "Missing _ObjectiveCType witness?");
229230
if (bridgedCollectionsAreOptional && clangTy)

0 commit comments

Comments
 (0)