diff --git a/include/swift/Sema/ConstraintSystem.h b/include/swift/Sema/ConstraintSystem.h index 4992cfad31f81..2442df78f363a 100644 --- a/include/swift/Sema/ConstraintSystem.h +++ b/include/swift/Sema/ConstraintSystem.h @@ -2401,6 +2401,10 @@ class ConstraintSystem { llvm::DenseMap, ProtocolConformanceRef> Conformances; + /// A cache for unavailability checks peformed by the solver. + llvm::DenseMap, bool> + UnavailableDecls; + /// The list of all generic requirements fixed along the current /// solver path. using FixedRequirement = diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 97e8debcacb53..64e0ad0837ae8 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -4810,13 +4810,20 @@ void ConstraintSystem::diagnoseFailureFor(SyntacticElementTarget target) { bool ConstraintSystem::isDeclUnavailable(const Decl *D, ConstraintLocator *locator) const { + auto found = UnavailableDecls.find(std::make_pair(D, locator)); + if (found != UnavailableDecls.end()) + return found->second; + SourceLoc loc; if (locator) { if (auto anchor = locator->getAnchor()) loc = getLoc(anchor); } - return getUnsatisfiedAvailabilityConstraint(D, DC, loc).has_value(); + auto result = getUnsatisfiedAvailabilityConstraint(D, DC, loc).has_value(); + const_cast(this)->UnavailableDecls.insert( + std::make_pair(std::make_pair(D, locator), result)); + return result; } bool ConstraintSystem::isConformanceUnavailable(ProtocolConformanceRef conformance,