Skip to content

Commit 302d6f1

Browse files
committed
Index: Accept compiler errors during index-while-building
Force allowing reading from modules with compiler errors during index-while-building as a way to recover from more deserialization issues.
1 parent 0ce7225 commit 302d6f1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ class ASTContext final {
380380
/// files?
381381
bool IgnoreAdjacentModules = false;
382382

383+
/// Override to accept reading errors from swiftmodules and being generally
384+
/// more tolerant to inconsistencies. This is enabled for
385+
/// index-while-building as it runs last and it can afford to read an AST
386+
/// with inconsistencies.
387+
bool ForceAllowModuleWithCompilerErrors = false;
388+
383389
// Define the set of known identifiers.
384390
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
385391
#include "swift/AST/KnownIdentifiers.def"

lib/Index/Index.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,14 +2156,19 @@ void index::indexSourceFile(SourceFile *SF, IndexDataConsumer &consumer) {
21562156

21572157
void index::indexModule(ModuleDecl *module, IndexDataConsumer &consumer) {
21582158
PrettyStackTraceDecl trace("indexing module", module);
2159+
ASTContext &ctx = module->getASTContext();
21592160
assert(module);
2161+
21602162
auto mName = module->getRealName().str();
2161-
if (module->getASTContext().blockListConfig.hasBlockListAction(mName,
2163+
if (ctx.blockListConfig.hasBlockListAction(mName,
21622164
BlockListKeyKind::ModuleName,
21632165
BlockListAction::SkipIndexingModule)) {
21642166
return;
21652167
}
2166-
IndexSwiftASTWalker walker(consumer, module->getASTContext());
2168+
2169+
llvm::SaveAndRestore<bool> S(ctx.ForceAllowModuleWithCompilerErrors, true);
2170+
2171+
IndexSwiftASTWalker walker(consumer, ctx);
21672172
walker.visitModule(*module);
21682173
consumer.finish();
21692174
}

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ ModuleFile::ModuleFile(std::shared_ptr<const ModuleFileSharedCore> core)
135135
}
136136

137137
bool ModuleFile::allowCompilerErrors() const {
138-
return getContext().LangOpts.AllowModuleWithCompilerErrors;
138+
return getContext().LangOpts.AllowModuleWithCompilerErrors ||
139+
getContext().ForceAllowModuleWithCompilerErrors;
139140
}
140141

141142
Status

0 commit comments

Comments
 (0)