Skip to content

Commit 1972c48

Browse files
committed
Sema: Cache result of getUnsatisfiedAvailabilityConstraint()
This query is expensive and we call it a lot.
1 parent ec39484 commit 1972c48

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,10 @@ class ConstraintSystem {
24012401
llvm::DenseMap<std::pair<TypeBase *, ProtocolDecl *>, ProtocolConformanceRef>
24022402
Conformances;
24032403

2404+
/// A cache for unavailability checks peformed by the solver.
2405+
llvm::DenseMap<std::pair<const Decl *, ConstraintLocator *>, bool>
2406+
UnavailableDecls;
2407+
24042408
/// The list of all generic requirements fixed along the current
24052409
/// solver path.
24062410
using FixedRequirement =

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4810,13 +4810,20 @@ void ConstraintSystem::diagnoseFailureFor(SyntacticElementTarget target) {
48104810

48114811
bool ConstraintSystem::isDeclUnavailable(const Decl *D,
48124812
ConstraintLocator *locator) const {
4813+
auto found = UnavailableDecls.find(std::make_pair(D, locator));
4814+
if (found != UnavailableDecls.end())
4815+
return found->second;
4816+
48134817
SourceLoc loc;
48144818
if (locator) {
48154819
if (auto anchor = locator->getAnchor())
48164820
loc = getLoc(anchor);
48174821
}
48184822

4819-
return getUnsatisfiedAvailabilityConstraint(D, DC, loc).has_value();
4823+
auto result = getUnsatisfiedAvailabilityConstraint(D, DC, loc).has_value();
4824+
const_cast<ConstraintSystem *>(this)->UnavailableDecls.insert(
4825+
std::make_pair(std::make_pair(D, locator), result));
4826+
return result;
48204827
}
48214828

48224829
bool ConstraintSystem::isConformanceUnavailable(ProtocolConformanceRef conformance,

0 commit comments

Comments
 (0)