@@ -62,12 +62,12 @@ ModuleDecl::collectExistentialConformances(CanType fromType,
6262 conformances.push_back (conformance);
6363 }
6464
65- return getASTContext ().AllocateCopy (conformances);
65+ return fromType-> getASTContext ().AllocateCopy (conformances);
6666}
6767
6868ProtocolConformanceRef
6969ModuleDecl::lookupExistentialConformance (Type type, ProtocolDecl *protocol) {
70- ASTContext &ctx = getASTContext ();
70+ ASTContext &ctx = protocol-> getASTContext ();
7171
7272 assert (type->isExistentialType ());
7373
@@ -177,22 +177,24 @@ ProtocolConformanceRef ProtocolConformanceRef::forMissingOrInvalid(
177177ProtocolConformanceRef ModuleDecl::lookupConformance (Type type,
178178 ProtocolDecl *protocol,
179179 bool allowMissing) {
180+ auto &eval = protocol->getASTContext ().evaluator ;
181+
180182 // If we are recursively checking for implicit conformance of a nominal
181183 // type to a KnownProtocol, fail without evaluating this request. This
182184 // squashes cycles.
183- LookupConformanceInModuleRequest request{{this , type, protocol}};
185+ LookupConformanceInModuleRequest request{{type, protocol}};
184186 if (auto kp = protocol->getKnownProtocolKind ()) {
185187 if (auto nominal = type->getAnyNominal ()) {
186188 ImplicitKnownProtocolConformanceRequest icvRequest{nominal, *kp};
187- if (getASTContext (). evaluator .hasActiveRequest (icvRequest) ||
188- getASTContext (). evaluator .hasActiveRequest (request)) {
189+ if (eval .hasActiveRequest (icvRequest) ||
190+ eval .hasActiveRequest (request)) {
189191 return ProtocolConformanceRef::forInvalid ();
190192 }
191193 }
192194 }
193195
194196 auto result = evaluateOrDefault (
195- getASTContext (). evaluator , request, ProtocolConformanceRef::forInvalid ());
197+ eval , request, ProtocolConformanceRef::forInvalid ());
196198
197199 // If we aren't supposed to allow missing conformances but we have one,
198200 // replace the result with an "invalid" result.
@@ -207,8 +209,7 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
207209// / Synthesize a builtin tuple type conformance to the given protocol, if
208210// / appropriate.
209211static ProtocolConformanceRef getBuiltinTupleTypeConformance (
210- Type type, const TupleType *tupleType, ProtocolDecl *protocol,
211- ModuleDecl *module ) {
212+ Type type, const TupleType *tupleType, ProtocolDecl *protocol) {
212213 ASTContext &ctx = protocol->getASTContext ();
213214
214215 auto *tupleDecl = ctx.getBuiltinTupleDecl ();
@@ -238,7 +239,7 @@ static ProtocolConformanceRef getBuiltinTupleTypeConformance(
238239 }
239240
240241 auto *conformance = cast<NormalProtocolConformance>(conformances.front ());
241- auto subMap = type->getContextSubstitutionMap (module ,
242+ auto subMap = type->getContextSubstitutionMap (protocol-> getParentModule () ,
242243 conformance->getDeclContext ());
243244
244245 // TODO: labels
@@ -432,7 +433,7 @@ getBuiltinBuiltinTypeConformance(Type type, const BuiltinType *builtinType,
432433}
433434
434435static ProtocolConformanceRef getPackTypeConformance (
435- PackType *type, ProtocolDecl *protocol, ModuleDecl *mod ) {
436+ PackType *type, ProtocolDecl *protocol) {
436437 SmallVector<ProtocolConformanceRef, 2 > patternConformances;
437438
438439 for (auto packElement : type->getElementTypes ()) {
@@ -442,17 +443,17 @@ static ProtocolConformanceRef getPackTypeConformance(
442443 auto patternConformance =
443444 (patternType->isTypeParameter ()
444445 ? ProtocolConformanceRef (protocol)
445- : mod-> lookupConformance (patternType, protocol,
446- /* allowMissing=*/ true ));
446+ : ModuleDecl:: lookupConformance (patternType, protocol,
447+ /* allowMissing=*/ true ));
447448 patternConformances.push_back (patternConformance);
448449 continue ;
449450 }
450451
451452 auto patternConformance =
452453 (packElement->isTypeParameter ()
453454 ? ProtocolConformanceRef (protocol)
454- : mod-> lookupConformance (packElement, protocol,
455- /* allowMissing=*/ true ));
455+ : ModuleDecl:: lookupConformance (packElement, protocol,
456+ /* allowMissing=*/ true ));
456457 patternConformances.push_back (patternConformance);
457458 }
458459
@@ -463,10 +464,9 @@ static ProtocolConformanceRef getPackTypeConformance(
463464ProtocolConformanceRef
464465LookupConformanceInModuleRequest::evaluate (
465466 Evaluator &evaluator, LookupConformanceDescriptor desc) const {
466- auto *mod = desc.Mod ;
467467 auto type = desc.Ty ;
468468 auto *protocol = desc.PD ;
469- ASTContext &ctx = mod ->getASTContext ();
469+ ASTContext &ctx = protocol ->getASTContext ();
470470
471471 // Remove SIL reference ownership wrapper, if present.
472472 type = type->getReferenceStorageReferent ();
@@ -491,7 +491,7 @@ LookupConformanceInModuleRequest::evaluate(
491491 // able to be resolved by a substitution that makes the archetype
492492 // concrete.
493493 if (auto super = archetype->getSuperclass ()) {
494- auto inheritedConformance = mod-> lookupConformance (
494+ auto inheritedConformance = ModuleDecl:: lookupConformance (
495495 super, protocol, /* allowMissing=*/ false );
496496 if (protocol->isSpecificProtocol (KnownProtocolKind::Sendable) &&
497497 inheritedConformance.hasUnavailableConformance ())
@@ -514,7 +514,7 @@ LookupConformanceInModuleRequest::evaluate(
514514 // existential's list of conformances and the existential conforms to
515515 // itself.
516516 if (type->isExistentialType ()) {
517- auto result = mod-> lookupExistentialConformance (type, protocol);
517+ auto result = ModuleDecl:: lookupExistentialConformance (type, protocol);
518518 if (result.isInvalid ())
519519 return ProtocolConformanceRef::forMissingOrInvalid (type, protocol);
520520 return result;
@@ -532,12 +532,12 @@ LookupConformanceInModuleRequest::evaluate(
532532
533533 // Pack types can conform to protocols.
534534 if (auto packType = type->getAs <PackType>()) {
535- return getPackTypeConformance (packType, protocol, mod );
535+ return getPackTypeConformance (packType, protocol);
536536 }
537537
538538 // Tuple types can conform to protocols.
539539 if (auto tupleType = type->getAs <TupleType>()) {
540- return getBuiltinTupleTypeConformance (type, tupleType, protocol, mod );
540+ return getBuiltinTupleTypeConformance (type, tupleType, protocol);
541541 }
542542
543543 // Function types can conform to protocols.
@@ -688,7 +688,7 @@ LookupConformanceInModuleRequest::evaluate(
688688 auto superclassTy = type->getSuperclassForDecl (conformingClass);
689689
690690 // Compute the conformance for the inherited type.
691- auto inheritedConformance = mod-> lookupConformance (
691+ auto inheritedConformance = ModuleDecl:: lookupConformance (
692692 superclassTy, protocol, /* allowMissing=*/ true );
693693 assert (inheritedConformance &&
694694 " We already found the inherited conformance" );
@@ -728,7 +728,8 @@ LookupConformanceInModuleRequest::evaluate(
728728 conformanceDC = conformanceDC->getSelfNominalTypeDecl ();
729729 }
730730
731- auto subMap = type->getContextSubstitutionMap (mod, conformanceDC);
731+ auto subMap = type->getContextSubstitutionMap (protocol->getParentModule (),
732+ conformanceDC);
732733 return ProtocolConformanceRef (
733734 ctx.getSpecializedConformance (type, normalConf, subMap));
734735 }
0 commit comments