diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index 6e624e197a130..34cdcb5237210 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -916,11 +916,9 @@ class ModuleDecl void lookupTopLevelDeclsByObjCName(SmallVectorImpl &Results, DeclName name); - /// This is a hack for 'main' file parsing and the integrated REPL. - /// - /// FIXME: Refactor main file parsing to not pump the parser incrementally. - /// FIXME: Remove the integrated REPL. - void clearLookupCache(); + /// This is a hack for SynthesizedFileUnit and code completion. Do not add new + /// uses of it. + void clearLookupCache(bool includingImports = true); /// Finds all class members defined in this module. /// diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 02144fbd1853a..8ea0939e31b19 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -3239,8 +3239,9 @@ bool SourceFile::shouldCrossImport() const { getASTContext().LangOpts.EnableCrossImportOverlays; } -void ModuleDecl::clearLookupCache() { - getASTContext().getImportCache().clear(); +void ModuleDecl::clearLookupCache(bool includingImports) { + if (includingImports) + getASTContext().getImportCache().clear(); setIsObjCNameLookupCachePopulated(false); ObjCNameLookupCache.clear(); @@ -3495,6 +3496,8 @@ void SourceFile::addTopLevelDecl(Decl *d) { auto &ctx = getASTContext(); auto *mutableThis = const_cast(this); ctx.evaluator.clearCachedOutput(ParseTopLevelDeclsRequest{mutableThis}); + + getParentModule()->clearLookupCache(/*includingImports*/isa(d)); } void SourceFile::prependTopLevelDecl(Decl *d) { diff --git a/test/IDE/pr83369.swift b/test/IDE/pr83369.swift new file mode 100644 index 0000000000000..6fcd79c8ed64c --- /dev/null +++ b/test/IDE/pr83369.swift @@ -0,0 +1,9 @@ +// RUN: %batch-code-completion -module-name main + +extension Int {} + +// Make sure we can resolve P here. +protocol P where X: main.#^COMPLETE^# { + associatedtype X +} +// COMPLETE: Decl[Protocol]/CurrModule: P[#P#]; name=P