2525#include " swift/AST/SubstitutionMap.h"
2626#include " swift/AST/TypeMatcher.h"
2727#include " swift/AST/Types.h"
28+ #include " swift/AST/TypeCheckRequests.h"
2829#include " swift/Basic/Defer.h"
2930#include " swift/ClangImporter/ClangModule.h"
3031#include " llvm/ADT/Statistic.h"
@@ -374,7 +375,6 @@ static bool isExtensionUsableForInference(const ExtensionDecl *extension,
374375
375376InferredAssociatedTypesByWitnesses
376377AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses (
377- ConformanceChecker &checker,
378378 const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
379379 ValueDecl *req) {
380380 // Conformances constructed by the ClangImporter should have explicit type
@@ -392,7 +392,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
392392 InferredAssociatedTypesByWitnesses result;
393393
394394 for (auto witness :
395- checker. lookupValueWitnesses (req, /* ignoringNames=*/ nullptr )) {
395+ lookupValueWitnesses (dc, req, /* ignoringNames=*/ nullptr )) {
396396 LLVM_DEBUG (llvm::dbgs () << " Inferring associated types from decl:\n " ;
397397 witness->dump (llvm::dbgs ()));
398398
@@ -582,9 +582,7 @@ next_witness:;
582582
583583InferredAssociatedTypes
584584AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses (
585- ConformanceChecker &checker,
586- const llvm::SetVector<AssociatedTypeDecl *> &assocTypes)
587- {
585+ const llvm::SetVector<AssociatedTypeDecl *> &assocTypes) {
588586 InferredAssociatedTypes result;
589587 for (auto member : proto->getMembers ()) {
590588 auto req = dyn_cast<ValueDecl>(member);
@@ -598,8 +596,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
598596 if (assocTypes.count (assocType) == 0 )
599597 continue ;
600598
601- auto reqInferred = inferTypeWitnessesViaAssociatedType (checker,
602- assocTypes,
599+ auto reqInferred = inferTypeWitnessesViaAssociatedType (assocTypes,
603600 assocType);
604601 if (!reqInferred.empty ())
605602 result.push_back ({req, std::move (reqInferred)});
@@ -623,7 +620,9 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
623620 // Check whether any of the associated types we care about are
624621 // referenced in this value requirement.
625622 {
626- const auto referenced = checker.getReferencedAssociatedTypes (req);
623+ auto referenced = evaluateOrDefault (ctx.evaluator ,
624+ ReferencedAssociatedTypesRequest{req},
625+ TinyPtrVector<AssociatedTypeDecl *>());
627626 if (llvm::find_if (referenced, [&](AssociatedTypeDecl *const assocType) {
628627 return assocTypes.count (assocType);
629628 }) == referenced.end ())
@@ -633,7 +632,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
633632 // Infer associated types from the potential value witnesses for
634633 // this requirement.
635634 auto reqInferred =
636- inferTypeWitnessesViaValueWitnesses (checker, assocTypes, req);
635+ inferTypeWitnessesViaValueWitnesses (assocTypes, req);
637636 if (reqInferred.empty ())
638637 continue ;
639638
@@ -738,7 +737,6 @@ static Type removeSelfParam(ValueDecl *value, Type type) {
738737
739738InferredAssociatedTypesByWitnesses
740739AssociatedTypeInference::inferTypeWitnessesViaAssociatedType (
741- ConformanceChecker &checker,
742740 const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
743741 AssociatedTypeDecl *assocType) {
744742 // Form the default name _Default_Foo.
@@ -2513,13 +2511,13 @@ bool AssociatedTypeInference::diagnoseAmbiguousSolutions(
25132511}
25142512
25152513bool AssociatedTypeInference::canAttemptEagerTypeWitnessDerivation (
2516- ConformanceChecker &checker,
2517- AssociatedTypeDecl *assocType) {
2514+ DeclContext *DC, AssociatedTypeDecl *assocType) {
25182515
25192516 // / Rather than locating the TypeID via the default implementation of
25202517 // / Identifiable, we need to find the type based on the associated ActorSystem
2521- if (checker.Adoptee ->isDistributedActor () &&
2522- assocType->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Identifiable)) {
2518+ if (auto *nominal = DC->getSelfNominalTypeDecl ())
2519+ if (nominal->isDistributedActor () &&
2520+ assocType->getProtocol ()->isSpecificProtocol (KnownProtocolKind::Identifiable)) {
25232521 return true ;
25242522 }
25252523
@@ -2550,7 +2548,7 @@ auto AssociatedTypeInference::solve(ConformanceChecker &checker)
25502548 if (conformance->hasTypeWitness (assocType))
25512549 continue ;
25522550
2553- if (canAttemptEagerTypeWitnessDerivation (checker , assocType)) {
2551+ if (canAttemptEagerTypeWitnessDerivation (dc , assocType)) {
25542552 auto derivedType = computeDerivedTypeWitness (assocType);
25552553 if (derivedType.first ) {
25562554 checker.recordTypeWitness (assocType,
@@ -2602,8 +2600,7 @@ auto AssociatedTypeInference::solve(ConformanceChecker &checker)
26022600 return result;
26032601
26042602 // Infer potential type witnesses from value witnesses.
2605- inferred = inferTypeWitnessesViaValueWitnesses (checker,
2606- unresolvedAssocTypes);
2603+ inferred = inferTypeWitnessesViaValueWitnesses (unresolvedAssocTypes);
26072604 LLVM_DEBUG (llvm::dbgs () << " Candidates for inference:\n " ;
26082605 dumpInferredAssociatedTypes (inferred));
26092606
@@ -3036,7 +3033,11 @@ void ConformanceChecker::resolveSingleWitness(ValueDecl *requirement) {
30363033
30373034 // If any of the type witnesses was erroneous, don't bother to check
30383035 // this value witness: it will fail.
3039- for (auto assocType : getReferencedAssociatedTypes (requirement)) {
3036+ auto assocTypes = evaluateOrDefault (getASTContext ().evaluator ,
3037+ ReferencedAssociatedTypesRequest{requirement},
3038+ TinyPtrVector<AssociatedTypeDecl *>());
3039+
3040+ for (auto assocType : assocTypes) {
30403041 if (Conformance->getTypeWitness (assocType)->hasError ()) {
30413042 Conformance->setInvalid ();
30423043 return ;
0 commit comments