Skip to content

Commit 4ca97ab

Browse files
author
David Ungar
committed
Key cache by SourceFile.
1 parent ce17240 commit 4ca97ab

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ class ASTContext final {
942942
return !LangOpts.EnableAccessControl;
943943
}
944944

945-
llvm::SmallVectorImpl<Type> &getDefaultTypeRequestCache();
945+
/// Logically, there is a separate cache for each SourceFile.
946+
llvm::SmallVectorImpl<Type> &getDefaultTypeRequestCache(SourceFile*);
946947

947948
private:
948949
friend Decl;

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,10 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
290290
ProtocolConformanceRef>
291291
DefaultAssociatedConformanceWitnesses;
292292

293-
/// Cache of default types for DefaultTypeRequest.
293+
/// Caches of default types for DefaultTypeRequest.
294294
/// Used to be instance variables in the TypeChecker.
295-
/// Soon to become more specific.
296-
llvm::SmallVector<Type, NumKnownProtocols> DefaultTypeRequestCache{
297-
NumKnownProtocols, Type()};
295+
/// There is a logically separate cache for each SourceFile.
296+
llvm::DenseMap<SourceFile*, llvm::SmallVector<Type, NumKnownProtocols>> DefaultTypeRequestCaches;
298297

299298
/// Structure that captures data that is segregated into different
300299
/// arenas.
@@ -5080,6 +5079,6 @@ LayoutConstraint LayoutConstraint::getLayoutConstraint(LayoutConstraintKind Kind
50805079
return LayoutConstraint(New);
50815080
}
50825081

5083-
llvm::SmallVectorImpl<Type> &ASTContext::getDefaultTypeRequestCache() {
5084-
return getImpl().DefaultTypeRequestCache;
5082+
llvm::SmallVectorImpl<Type> &ASTContext::getDefaultTypeRequestCache(SourceFile* SF) {
5083+
return getImpl().DefaultTypeRequestCaches[SF];
50855084
}

lib/AST/TypeCheckRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ SourceFile *DefaultTypeRequest::getSourceFile() const {
457457
}
458458

459459
llvm::SmallVectorImpl<Type> &DefaultTypeRequest::getCache() const {
460-
return getDeclContext()->getASTContext().getDefaultTypeRequestCache();
460+
return getDeclContext()->getASTContext().getDefaultTypeRequestCache(getSourceFile());
461461
}
462462

463463
Optional<Type> DefaultTypeRequest::getCachedResult() const {

0 commit comments

Comments
 (0)