Skip to content

Commit e814b3f

Browse files
committed
Serialization: Intro enableExtendedDeserializationRecovery
Introduce a new deserialization mode `enableExtendedDeserializationRecovery` for use when we can afford inconsistent information from a swiftmodule file. It's enabled automatically in debugger mode, when user errors are allowed and during index-while-building.
1 parent cc14548 commit e814b3f

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,10 @@ class ASTContext final {
381381
/// files?
382382
bool IgnoreAdjacentModules = false;
383383

384-
/// Override to accept reading errors from swiftmodules and being generally
385-
/// more tolerant to inconsistencies. This is enabled for
386-
/// index-while-building as it runs last and it can afford to read an AST
387-
/// with inconsistencies.
388-
bool ForceAllowModuleWithCompilerErrors = false;
384+
/// Accept recovering from more issues at deserialization, even if it can
385+
/// lead to an inconsistent state. This is enabled for index-while-building
386+
/// as it runs last and it can afford to read an AST with inconsistencies.
387+
bool ForceExtendedDeserializationRecovery = false;
389388

390389
// Define the set of known identifiers.
391390
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;

lib/Index/Index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ void index::indexModule(ModuleDecl *module, IndexDataConsumer &consumer) {
21682168
return;
21692169
}
21702170

2171-
llvm::SaveAndRestore<bool> S(ctx.ForceAllowModuleWithCompilerErrors, true);
2171+
llvm::SaveAndRestore<bool> S(ctx.ForceExtendedDeserializationRecovery, true);
21722172

21732173
IndexSwiftASTWalker walker(consumer, ctx);
21742174
walker.visitModule(*module);

lib/Serialization/ModuleFile.cpp

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

137137
bool ModuleFile::allowCompilerErrors() const {
138-
return getContext().LangOpts.AllowModuleWithCompilerErrors ||
139-
getContext().ForceAllowModuleWithCompilerErrors;
138+
return getContext().LangOpts.AllowModuleWithCompilerErrors;
139+
}
140+
141+
bool ModuleFile::enableExtendedDeserializationRecovery() const {
142+
ASTContext &ctx = getContext();
143+
return ctx.LangOpts.EnableDeserializationRecovery &&
144+
(allowCompilerErrors() ||
145+
ctx.LangOpts.DebuggerSupport ||
146+
ctx.ForceExtendedDeserializationRecovery);
140147
}
141148

142149
Status

lib/Serialization/ModuleFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ class ModuleFile
691691
/// '-experimental-allow-module-with-compiler-errors' is currently enabled).
692692
bool allowCompilerErrors() const;
693693

694+
/// Allow recovering from errors that could be unsafe when compiling
695+
/// the binary. Useful for the debugger and IDE support tools.
696+
bool enableExtendedDeserializationRecovery() const;
697+
694698
/// \c true if this module has incremental dependency information.
695699
bool hasIncrementalInfo() const { return Core->hasIncrementalInfo(); }
696700

0 commit comments

Comments
 (0)