Skip to content

Commit 179166c

Browse files
author
David Ungar
committed
Since cache is keyed by SourceFile, only need to check if dependency is missing.
1 parent fe999d9 commit 179166c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class DefaultTypeRequest
362362
TypeChecker &getTypeChecker() const;
363363
SourceFile *getSourceFile() const;
364364
llvm::SmallVectorImpl<Type> &getCache() const;
365-
void recordDependencyOnCachedResult(Type result) const;
365+
bool isDependencyMissing(Type result) const;
366366
};
367367

368368
/// The zone number for the type checker.

lib/AST/TypeCheckRequests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,17 @@ Optional<Type> DefaultTypeRequest::getCachedResult() const {
466466
Type result = cache[size_t(getKnownProtocolKind())];
467467
if (!result)
468468
return None;
469-
recordDependencyOnCachedResult(result);
469+
assert(!isDependencyMissing(result) &&
470+
"Since the cache is now cached by SourceFile, the dependency should have been recorded when it was looked up.");
470471
return result;
471472
}
472473

473-
void DefaultTypeRequest::recordDependencyOnCachedResult(Type result) const {
474-
// An uncached result was looked up & the dependency was recorded there.
475-
// Here, record the dependency in case the cache spaces source files.
474+
bool DefaultTypeRequest::isDependencyMissing(Type result) const {
476475
if (const auto *NTD = result->getNominalOrBoundGenericNominal())
477476
if (auto *SF = getSourceFile())
478477
if (auto *tracker = SF->getReferencedNameTracker())
479-
tracker->addTopLevelName(NTD->getBaseName(), true);
478+
return tracker->getTopLevelNames().find(NTD->getBaseName()) == tracker->getTopLevelNames().end();
479+
return false;
480480
}
481481

482482
void DefaultTypeRequest::cacheResult(Type value) const {

0 commit comments

Comments
 (0)