@@ -62,12 +62,12 @@ ModuleDecl::collectExistentialConformances(CanType fromType,
62
62
conformances.push_back (conformance);
63
63
}
64
64
65
- return getASTContext ().AllocateCopy (conformances);
65
+ return fromType-> getASTContext ().AllocateCopy (conformances);
66
66
}
67
67
68
68
ProtocolConformanceRef
69
69
ModuleDecl::lookupExistentialConformance (Type type, ProtocolDecl *protocol) {
70
- ASTContext &ctx = getASTContext ();
70
+ ASTContext &ctx = protocol-> getASTContext ();
71
71
72
72
assert (type->isExistentialType ());
73
73
@@ -177,22 +177,24 @@ ProtocolConformanceRef ProtocolConformanceRef::forMissingOrInvalid(
177
177
ProtocolConformanceRef ModuleDecl::lookupConformance (Type type,
178
178
ProtocolDecl *protocol,
179
179
bool allowMissing) {
180
+ auto &eval = protocol->getASTContext ().evaluator ;
181
+
180
182
// If we are recursively checking for implicit conformance of a nominal
181
183
// type to a KnownProtocol, fail without evaluating this request. This
182
184
// squashes cycles.
183
- LookupConformanceInModuleRequest request{{this , type, protocol}};
185
+ LookupConformanceInModuleRequest request{{type, protocol}};
184
186
if (auto kp = protocol->getKnownProtocolKind ()) {
185
187
if (auto nominal = type->getAnyNominal ()) {
186
188
ImplicitKnownProtocolConformanceRequest icvRequest{nominal, *kp};
187
- if (getASTContext (). evaluator .hasActiveRequest (icvRequest) ||
188
- getASTContext (). evaluator .hasActiveRequest (request)) {
189
+ if (eval .hasActiveRequest (icvRequest) ||
190
+ eval .hasActiveRequest (request)) {
189
191
return ProtocolConformanceRef::forInvalid ();
190
192
}
191
193
}
192
194
}
193
195
194
196
auto result = evaluateOrDefault (
195
- getASTContext (). evaluator , request, ProtocolConformanceRef::forInvalid ());
197
+ eval , request, ProtocolConformanceRef::forInvalid ());
196
198
197
199
// If we aren't supposed to allow missing conformances but we have one,
198
200
// replace the result with an "invalid" result.
@@ -207,8 +209,7 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
207
209
// / Synthesize a builtin tuple type conformance to the given protocol, if
208
210
// / appropriate.
209
211
static ProtocolConformanceRef getBuiltinTupleTypeConformance (
210
- Type type, const TupleType *tupleType, ProtocolDecl *protocol,
211
- ModuleDecl *module ) {
212
+ Type type, const TupleType *tupleType, ProtocolDecl *protocol) {
212
213
ASTContext &ctx = protocol->getASTContext ();
213
214
214
215
auto *tupleDecl = ctx.getBuiltinTupleDecl ();
@@ -238,7 +239,7 @@ static ProtocolConformanceRef getBuiltinTupleTypeConformance(
238
239
}
239
240
240
241
auto *conformance = cast<NormalProtocolConformance>(conformances.front ());
241
- auto subMap = type->getContextSubstitutionMap (module ,
242
+ auto subMap = type->getContextSubstitutionMap (protocol-> getParentModule () ,
242
243
conformance->getDeclContext ());
243
244
244
245
// TODO: labels
@@ -432,7 +433,7 @@ getBuiltinBuiltinTypeConformance(Type type, const BuiltinType *builtinType,
432
433
}
433
434
434
435
static ProtocolConformanceRef getPackTypeConformance (
435
- PackType *type, ProtocolDecl *protocol, ModuleDecl *mod ) {
436
+ PackType *type, ProtocolDecl *protocol) {
436
437
SmallVector<ProtocolConformanceRef, 2 > patternConformances;
437
438
438
439
for (auto packElement : type->getElementTypes ()) {
@@ -442,17 +443,17 @@ static ProtocolConformanceRef getPackTypeConformance(
442
443
auto patternConformance =
443
444
(patternType->isTypeParameter ()
444
445
? ProtocolConformanceRef (protocol)
445
- : mod-> lookupConformance (patternType, protocol,
446
- /* allowMissing=*/ true ));
446
+ : ModuleDecl:: lookupConformance (patternType, protocol,
447
+ /* allowMissing=*/ true ));
447
448
patternConformances.push_back (patternConformance);
448
449
continue ;
449
450
}
450
451
451
452
auto patternConformance =
452
453
(packElement->isTypeParameter ()
453
454
? ProtocolConformanceRef (protocol)
454
- : mod-> lookupConformance (packElement, protocol,
455
- /* allowMissing=*/ true ));
455
+ : ModuleDecl:: lookupConformance (packElement, protocol,
456
+ /* allowMissing=*/ true ));
456
457
patternConformances.push_back (patternConformance);
457
458
}
458
459
@@ -463,10 +464,9 @@ static ProtocolConformanceRef getPackTypeConformance(
463
464
ProtocolConformanceRef
464
465
LookupConformanceInModuleRequest::evaluate (
465
466
Evaluator &evaluator, LookupConformanceDescriptor desc) const {
466
- auto *mod = desc.Mod ;
467
467
auto type = desc.Ty ;
468
468
auto *protocol = desc.PD ;
469
- ASTContext &ctx = mod ->getASTContext ();
469
+ ASTContext &ctx = protocol ->getASTContext ();
470
470
471
471
// Remove SIL reference ownership wrapper, if present.
472
472
type = type->getReferenceStorageReferent ();
@@ -491,7 +491,7 @@ LookupConformanceInModuleRequest::evaluate(
491
491
// able to be resolved by a substitution that makes the archetype
492
492
// concrete.
493
493
if (auto super = archetype->getSuperclass ()) {
494
- auto inheritedConformance = mod-> lookupConformance (
494
+ auto inheritedConformance = ModuleDecl:: lookupConformance (
495
495
super, protocol, /* allowMissing=*/ false );
496
496
if (protocol->isSpecificProtocol (KnownProtocolKind::Sendable) &&
497
497
inheritedConformance.hasUnavailableConformance ())
@@ -514,7 +514,7 @@ LookupConformanceInModuleRequest::evaluate(
514
514
// existential's list of conformances and the existential conforms to
515
515
// itself.
516
516
if (type->isExistentialType ()) {
517
- auto result = mod-> lookupExistentialConformance (type, protocol);
517
+ auto result = ModuleDecl:: lookupExistentialConformance (type, protocol);
518
518
if (result.isInvalid ())
519
519
return ProtocolConformanceRef::forMissingOrInvalid (type, protocol);
520
520
return result;
@@ -532,12 +532,12 @@ LookupConformanceInModuleRequest::evaluate(
532
532
533
533
// Pack types can conform to protocols.
534
534
if (auto packType = type->getAs <PackType>()) {
535
- return getPackTypeConformance (packType, protocol, mod );
535
+ return getPackTypeConformance (packType, protocol);
536
536
}
537
537
538
538
// Tuple types can conform to protocols.
539
539
if (auto tupleType = type->getAs <TupleType>()) {
540
- return getBuiltinTupleTypeConformance (type, tupleType, protocol, mod );
540
+ return getBuiltinTupleTypeConformance (type, tupleType, protocol);
541
541
}
542
542
543
543
// Function types can conform to protocols.
@@ -688,7 +688,7 @@ LookupConformanceInModuleRequest::evaluate(
688
688
auto superclassTy = type->getSuperclassForDecl (conformingClass);
689
689
690
690
// Compute the conformance for the inherited type.
691
- auto inheritedConformance = mod-> lookupConformance (
691
+ auto inheritedConformance = ModuleDecl:: lookupConformance (
692
692
superclassTy, protocol, /* allowMissing=*/ true );
693
693
assert (inheritedConformance &&
694
694
" We already found the inherited conformance" );
@@ -728,7 +728,8 @@ LookupConformanceInModuleRequest::evaluate(
728
728
conformanceDC = conformanceDC->getSelfNominalTypeDecl ();
729
729
}
730
730
731
- auto subMap = type->getContextSubstitutionMap (mod, conformanceDC);
731
+ auto subMap = type->getContextSubstitutionMap (protocol->getParentModule (),
732
+ conformanceDC);
732
733
return ProtocolConformanceRef (
733
734
ctx.getSpecializedConformance (type, normalConf, subMap));
734
735
}
0 commit comments