Skip to content

Commit bd6281c

Browse files
committed
AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType
1 parent ebb1198 commit bd6281c

20 files changed

+63
-78
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class GenericSignatureBuilder {
508508
Optional<ProtocolConformanceRef>
509509
operator()(CanType dependentType,
510510
Type conformingReplacementType,
511-
ProtocolType *conformedProtocol) const {
511+
ProtocolDecl *conformedProtocol) const {
512512
return builder->lookupConformance(dependentType,
513513
conformingReplacementType,
514514
conformedProtocol);
@@ -522,7 +522,7 @@ class GenericSignatureBuilder {
522522
/// Lookup a protocol conformance in a module-agnostic manner.
523523
Optional<ProtocolConformanceRef>
524524
lookupConformance(CanType dependentType, Type conformingReplacementType,
525-
ProtocolType *conformedProtocol);
525+
ProtocolDecl *conformedProtocol);
526526

527527

528528
/// Retrieve the lazy resolver, if there is one.

include/swift/AST/SubstitutionMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class LookUpConformanceInSubstitutionMap {
289289
Optional<ProtocolConformanceRef>
290290
operator()(CanType dependentType,
291291
Type conformingReplacementType,
292-
ProtocolType *conformedProtocol) const;
292+
ProtocolDecl *conformedProtocol) const;
293293
};
294294

295295
} // end namespace swift

include/swift/AST/Type.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ struct QueryTypeSubstitutionMapOrIdentity {
9090

9191
/// Function used to resolve conformances.
9292
using GenericFunction = auto(CanType dependentType,
93-
Type conformingReplacementType,
94-
ProtocolType *conformedProtocol)
95-
->Optional<ProtocolConformanceRef>;
93+
Type conformingReplacementType,
94+
ProtocolDecl *conformedProtocol)
95+
-> Optional<ProtocolConformanceRef>;
9696
using LookupConformanceFn = llvm::function_ref<GenericFunction>;
9797

9898
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
@@ -106,7 +106,7 @@ class LookUpConformanceInModule {
106106
Optional<ProtocolConformanceRef>
107107
operator()(CanType dependentType,
108108
Type conformingReplacementType,
109-
ProtocolType *conformedProtocol) const;
109+
ProtocolDecl *conformedProtocol) const;
110110
};
111111

112112
/// Functor class suitable for use as a \c LookupConformanceFn that provides
@@ -117,7 +117,7 @@ class MakeAbstractConformanceForGenericType {
117117
Optional<ProtocolConformanceRef>
118118
operator()(CanType dependentType,
119119
Type conformingReplacementType,
120-
ProtocolType *conformedProtocol) const;
120+
ProtocolDecl *conformedProtocol) const;
121121
};
122122

123123
/// Functor class suitable for use as a \c LookupConformanceFn that fetches
@@ -131,7 +131,7 @@ class LookUpConformanceInSignature {
131131
Optional<ProtocolConformanceRef>
132132
operator()(CanType dependentType,
133133
Type conformingReplacementType,
134-
ProtocolType *conformedProtocol) const;
134+
ProtocolDecl *conformedProtocol) const;
135135
};
136136

137137
/// Flags that can be passed when substituting into a type.

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ bool GenericSignature::isRequirementSatisfied(Requirement requirement) {
556556
return conformsToProtocol(canFirstType, protocol);
557557
else
558558
return (bool)GSB->lookupConformance(/*dependentType=*/CanType(),
559-
canFirstType, protocolType);
559+
canFirstType, protocol);
560560
}
561561

562562
case RequirementKind::SameType: {

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,9 +2639,7 @@ GenericSignatureBuilder::resolveConcreteConformance(ResolvedType type,
26392639
// Lookup the conformance of the concrete type to this protocol.
26402640
auto conformance =
26412641
lookupConformance(type.getDependentType(*this)->getCanonicalType(),
2642-
concrete,
2643-
proto->getDeclaredInterfaceType()
2644-
->castTo<ProtocolType>());
2642+
concrete, proto);
26452643
if (!conformance) {
26462644
if (!concrete->hasError() && concreteSource->getLoc().isValid()) {
26472645
Impl->HadAnyError = true;
@@ -2672,9 +2670,7 @@ const RequirementSource *GenericSignatureBuilder::resolveSuperConformance(
26722670
// Lookup the conformance of the superclass to this protocol.
26732671
auto conformance =
26742672
lookupConformance(type.getDependentType(*this)->getCanonicalType(),
2675-
superclass,
2676-
proto->getDeclaredInterfaceType()
2677-
->castTo<ProtocolType>());
2673+
superclass, proto);
26782674
if (!conformance) return nullptr;
26792675

26802676
// Conformance to this protocol is redundant; update the requirement source
@@ -3825,16 +3821,16 @@ GenericSignatureBuilder::getLookupConformanceFn()
38253821
Optional<ProtocolConformanceRef>
38263822
GenericSignatureBuilder::lookupConformance(CanType dependentType,
38273823
Type conformingReplacementType,
3828-
ProtocolType *conformedProtocol) {
3824+
ProtocolDecl *conformedProtocol) {
38293825
if (conformingReplacementType->isTypeParameter())
3830-
return ProtocolConformanceRef(conformedProtocol->getDecl());
3826+
return ProtocolConformanceRef(conformedProtocol);
38313827

38323828
// Figure out which module to look into.
38333829
// FIXME: When lookupConformance() starts respecting modules, we'll need
38343830
// to do some filtering here.
3835-
ModuleDecl *searchModule = conformedProtocol->getDecl()->getParentModule();
3831+
ModuleDecl *searchModule = conformedProtocol->getParentModule();
38363832
auto result = searchModule->lookupConformance(conformingReplacementType,
3837-
conformedProtocol->getDecl());
3833+
conformedProtocol);
38383834
if (result && getLazyResolver())
38393835
getLazyResolver()->markConformanceUsed(*result, searchModule);
38403836

@@ -4726,7 +4722,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
47264722
// getLookupConformanceFns used in here don't use that parameter anyway.
47274723
auto dependentType = CanType();
47284724
auto conformance =
4729-
getLookupConformanceFn()(dependentType, subjectType, proto);
4725+
getLookupConformanceFn()(dependentType, subjectType, proto->getDecl());
47304726

47314727
// FIXME: diagnose if there's no conformance.
47324728
if (conformance) {

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ ProtocolConformanceRef::subst(Type origType,
118118

119119
// Check the conformance map.
120120
if (auto result = conformances(origType->getCanonicalType(),
121-
substType,
122-
proto->getDeclaredType())) {
121+
substType, proto)) {
123122
return *result;
124123
}
125124

lib/AST/RequirementEnvironment.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ RequirementEnvironment::RequirementEnvironment(
110110
return substGenericParam;
111111
},
112112
[selfType, substConcreteType, conformance, conformanceDC, &ctx](
113-
CanType type, Type replacement, ProtocolType *protoType)
113+
CanType type, Type replacement, ProtocolDecl *proto)
114114
-> Optional<ProtocolConformanceRef> {
115-
auto proto = protoType->getDecl();
116-
117115
// The protocol 'Self' conforms concretely to the conforming type.
118116
if (type->isEqual(selfType)) {
119117
ProtocolConformance *specialized = conformance;

lib/AST/SubstitutionMap.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ SubstitutionMap SubstitutionMap::get(GenericSignature *genericSig,
223223
SubstFlags::UseErrorType);
224224
auto protoType = req.getSecondType()->castTo<ProtocolType>();
225225
auto proto = protoType->getDecl();
226-
auto conformance = lookupConformance(depTy, replacement, protoType)
226+
auto conformance = lookupConformance(depTy, replacement, proto)
227227
.getValueOr(ProtocolConformanceRef(proto));
228228
conformances.push_back(conformance);
229229
}
@@ -338,7 +338,7 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
338338
return LookUpConformanceInSignature(*getGenericSignature())(
339339
type->getCanonicalType(),
340340
superclass,
341-
proto->getDeclaredType());
341+
proto);
342342
}
343343

344344
return None;
@@ -430,8 +430,7 @@ SubstitutionMap SubstitutionMap::subst(TypeSubstitutionFn subs,
430430
.subst(subs, conformances, SubstFlags::UseErrorType);
431431
},
432432
[&](CanType dependentType, Type replacementType,
433-
ProtocolType *conformedProtocol) ->Optional<ProtocolConformanceRef> {
434-
auto proto = conformedProtocol->getDecl();
433+
ProtocolDecl *proto) ->Optional<ProtocolConformanceRef> {
435434
auto conformance =
436435
lookupConformance(dependentType, proto)
437436
.getValueOr(ProtocolConformanceRef(proto));
@@ -455,10 +454,9 @@ SubstitutionMap::getProtocolSubstitutions(ProtocolDecl *protocol,
455454
// inside generic types.
456455
return Type();
457456
},
458-
[&](CanType origType, Type replacementType, ProtocolType *protoType)
457+
[&](CanType origType, Type replacementType, ProtocolDecl *protoType)
459458
-> Optional<ProtocolConformanceRef> {
460-
if (origType->isEqual(protocolSelfType) &&
461-
protoType->getDecl() == protocol)
459+
if (origType->isEqual(protocolSelfType) && protoType == protocol)
462460
return conformance;
463461

464462
// This will need to change if we ever support protocols
@@ -568,13 +566,12 @@ SubstitutionMap::combineSubstitutionMaps(SubstitutionMap firstSubMap,
568566
return Type(replacement).subst(secondSubMap);
569567
return Type(type).subst(firstSubMap);
570568
},
571-
[&](CanType type, Type substType, ProtocolType *conformedProtocol) {
569+
[&](CanType type, Type substType, ProtocolDecl *conformedProtocol) {
572570
auto replacement = type.transform(replaceGenericParameter);
573571
if (replacement)
574572
return secondSubMap.lookupConformance(replacement->getCanonicalType(),
575-
conformedProtocol->getDecl());
576-
return firstSubMap.lookupConformance(type,
577-
conformedProtocol->getDecl());
573+
conformedProtocol);
574+
return firstSubMap.lookupConformance(type, conformedProtocol);
578575
});
579576
}
580577

lib/AST/Type.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,8 +2842,7 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
28422842
auto proto = assocType->getProtocol();
28432843
Optional<ProtocolConformanceRef> conformance
28442844
= lookupConformances(origBase->getCanonicalType(),
2845-
substBase,
2846-
proto->getDeclaredType());
2845+
substBase, proto);
28472846

28482847
if (!conformance) return failed();
28492848
if (!conformance->isConcrete()) return failed();
@@ -2876,39 +2875,39 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
28762875
Optional<ProtocolConformanceRef>
28772876
LookUpConformanceInModule::operator()(CanType dependentType,
28782877
Type conformingReplacementType,
2879-
ProtocolType *conformedProtocol) const {
2878+
ProtocolDecl *conformedProtocol) const {
28802879
if (conformingReplacementType->isTypeParameter())
2881-
return ProtocolConformanceRef(conformedProtocol->getDecl());
2880+
return ProtocolConformanceRef(conformedProtocol);
28822881

28832882
return M->lookupConformance(conformingReplacementType,
2884-
conformedProtocol->getDecl());
2883+
conformedProtocol);
28852884
}
28862885

28872886
Optional<ProtocolConformanceRef>
28882887
LookUpConformanceInSubstitutionMap::operator()(CanType dependentType,
28892888
Type conformingReplacementType,
2890-
ProtocolType *conformedProtocol) const {
2891-
return Subs.lookupConformance(dependentType, conformedProtocol->getDecl());
2889+
ProtocolDecl *conformedProtocol) const {
2890+
return Subs.lookupConformance(dependentType, conformedProtocol);
28922891
}
28932892

28942893
Optional<ProtocolConformanceRef>
28952894
MakeAbstractConformanceForGenericType::operator()(CanType dependentType,
28962895
Type conformingReplacementType,
2897-
ProtocolType *conformedProtocol) const {
2896+
ProtocolDecl *conformedProtocol) const {
28982897
assert((conformingReplacementType->is<SubstitutableType>()
28992898
|| conformingReplacementType->is<DependentMemberType>())
29002899
&& "replacement requires looking up a concrete conformance");
2901-
return ProtocolConformanceRef(conformedProtocol->getDecl());
2900+
return ProtocolConformanceRef(conformedProtocol);
29022901
}
29032902

29042903
Optional<ProtocolConformanceRef>
29052904
LookUpConformanceInSignature::operator()(CanType dependentType,
29062905
Type conformingReplacementType,
2907-
ProtocolType *conformedProtocol) const {
2906+
ProtocolDecl *conformedProtocol) const {
29082907
// FIXME: Should pass dependentType instead, once
29092908
// GenericSignature::lookupConformance() does the right thing
29102909
return Sig.lookupConformance(conformingReplacementType->getCanonicalType(),
2911-
conformedProtocol->getDecl());
2910+
conformedProtocol);
29122911
}
29132912

29142913
Type DependentMemberType::substBaseType(ModuleDecl *module,

lib/ParseSIL/ParseSIL.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,17 +1604,16 @@ SubstitutionMap getApplySubstitutionsFromParsed(
16041604
return parses[index].replacement;
16051605
},
16061606
[&](CanType dependentType, Type replacementType,
1607-
ProtocolType *protoTy) ->Optional<ProtocolConformanceRef> {
1607+
ProtocolDecl *proto) ->Optional<ProtocolConformanceRef> {
16081608
auto M = SP.P.SF.getParentModule();
1609-
auto conformance = M->lookupConformance(replacementType,
1610-
protoTy->getDecl());
1609+
auto conformance = M->lookupConformance(replacementType, proto);
16111610
if (conformance) return conformance;
16121611

16131612
SP.P.diagnose(loc, diag::sil_substitution_mismatch, replacementType,
1614-
protoTy);
1613+
proto->getDeclaredType());
16151614
failed = true;
16161615

1617-
return ProtocolConformanceRef(protoTy->getDecl());
1616+
return ProtocolConformanceRef(proto);
16181617
});
16191618

16201619
return failed ? SubstitutionMap() : subMap;

0 commit comments

Comments
 (0)