Skip to content

Commit 22779d4

Browse files
committed
[Sema|Index] Ignore the cache when loading a system module for indexing
1 parent f92da36 commit 22779d4

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

include/swift/AST/ASTContext.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,12 @@ class ASTContext final {
11401140
///
11411141
/// \param ModulePath The module's \c ImportPath which describes
11421142
/// the name of the module being loaded, possibly including submodules.
1143-
1143+
/// \param AllowMemoryCached Should we allow reuse of an already loaded
1144+
/// module or force reloading from disk, defaults to true.
1145+
///
11441146
/// \returns The requested module, or NULL if the module cannot be found.
1145-
ModuleDecl *getModule(ImportPath::Module ModulePath);
1147+
ModuleDecl *
1148+
getModule(ImportPath::Module ModulePath, bool AllowMemoryCached = true);
11461149

11471150
/// Attempts to load the matching overlay module for the given clang
11481151
/// module into this ASTContext.

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,10 +2192,6 @@ void ASTContext::addLoadedModule(ModuleDecl *M) {
21922192
}
21932193

21942194
void ASTContext::setIgnoreAdjacentModules(bool value) {
2195-
// Clear the cache if we expect a different view on the same modules.
2196-
if (IgnoreAdjacentModules != value)
2197-
getImpl().LoadedModules.clear();
2198-
21992195
IgnoreAdjacentModules = value;
22002196
}
22012197

@@ -2449,11 +2445,12 @@ bool ASTContext::canImportModule(ImportPath::Module ModuleName,
24492445
}
24502446

24512447
ModuleDecl *
2452-
ASTContext::getModule(ImportPath::Module ModulePath) {
2448+
ASTContext::getModule(ImportPath::Module ModulePath, bool AllowMemoryCached) {
24532449
assert(!ModulePath.empty());
24542450

2455-
if (auto *M = getLoadedModule(ModulePath))
2456-
return M;
2451+
if (AllowMemoryCached)
2452+
if (auto *M = getLoadedModule(ModulePath))
2453+
return M;
24572454

24582455
auto moduleID = ModulePath[0];
24592456
if (PreModuleImportCallback)

lib/Index/IndexRecord.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
520520
module->getASTContext().setIgnoreAdjacentModules(true);
521521

522522
ImportPath::Module::Builder builder(module->getName());
523-
auto reloadedModule = module->getASTContext().getModule(builder.get());
523+
ASTContext &ctx = module->getASTContext();
524+
auto reloadedModule = ctx.getModule(builder.get(),
525+
/*AllowMemoryCached=*/false);
524526

525527
if (reloadedModule) {
526528
module = reloadedModule;

0 commit comments

Comments
 (0)