Skip to content

Commit e7d1027

Browse files
authored
Merge pull request #8580 from jrose-apple/enable-experimental-deserialization-recovery
[Serialization] Proof-of-concept: drop overriding methods if the base is missing
2 parents 7ccef06 + 73d4526 commit e7d1027

File tree

10 files changed

+239
-39
lines changed

10 files changed

+239
-39
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ ERROR(serialization_target_too_new_repl,none,
549549
"module file's minimum deployment target is %0 v%1.%2%select{|.%3}3: %4",
550550
(StringRef, unsigned, unsigned, unsigned, StringRef))
551551

552+
ERROR(serialization_fatal,Fatal,
553+
"fatal error encountered while reading from module '%0'; "
554+
"please file a bug report with your project and the crash log",
555+
(StringRef))
556+
552557
ERROR(reserved_member_name,none,
553558
"type member may not be named %0, since it would conflict with the"
554559
" 'foo.%1' expression", (DeclName, StringRef))

include/swift/Basic/LangOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ namespace swift {
178178
/// new enough?
179179
bool EnableTargetOSChecking = true;
180180

181+
/// Whether to attempt to recover from missing cross-references and other
182+
/// errors when deserializing from a Swift module.
183+
///
184+
/// This is a staging flag; eventually it will be on by default.
185+
bool EnableDeserializationRecovery = false;
186+
181187
/// Should we use \c ASTScope-based resolution for unqualified name lookup?
182188
bool EnableASTScopeLookup = false;
183189

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def enable_experimental_property_behaviors :
263263
Flag<["-"], "enable-experimental-property-behaviors">,
264264
HelpText<"Enable experimental property behaviors">;
265265

266+
def enable_experimental_deserialization_recovery :
267+
Flag<["-"], "enable-experimental-deserialization-recovery">,
268+
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;
269+
266270
def enable_cow_existentials : Flag<["-"], "enable-cow-existentials">,
267271
HelpText<"Enable the copy-on-write existential implementation">;
268272

include/swift/Serialization/ModuleFile.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/ADT/DenseMap.h"
2727
#include "llvm/ADT/TinyPtrVector.h"
2828
#include "llvm/Bitcode/BitstreamReader.h"
29+
#include "llvm/Support/Error.h"
2930
#include "llvm/Support/MemoryBuffer.h"
3031

3132
namespace llvm {
@@ -435,6 +436,10 @@ class ModuleFile : public LazyMemberLoader {
435436
return getStatus();
436437
}
437438

439+
/// Emits one last diagnostic, logs the error, and then aborts for the stack
440+
/// trace.
441+
void fatal(llvm::Error error) LLVM_ATTRIBUTE_NORETURN;
442+
438443
ASTContext &getContext() const {
439444
assert(FileContext && "no associated context yet");
440445
return FileContext->getParentModule()->getASTContext();
@@ -542,12 +547,14 @@ class ModuleFile : public LazyMemberLoader {
542547
/// because it reads from the cursor, it is not possible to reset the cursor
543548
/// after reading. Nothing should ever follow an XREF record except
544549
/// XREF_PATH_PIECE records.
545-
Decl *resolveCrossReference(ModuleDecl *M, uint32_t pathLen);
550+
llvm::Expected<Decl *> resolveCrossReference(ModuleDecl *M, uint32_t pathLen);
546551

547552
/// Populates TopLevelIDs for name lookup.
548553
void buildTopLevelDeclMap();
549554

550-
void configureStorage(AbstractStorageDecl *storage, unsigned rawStorageKind,
555+
/// Sets the accessors for \p storage based on \p rawStorageKind.
556+
void configureStorage(AbstractStorageDecl *storage,
557+
unsigned rawStorageKind,
551558
serialization::DeclID getter,
552559
serialization::DeclID setter,
553560
serialization::DeclID materializeForSet,
@@ -743,8 +750,13 @@ class ModuleFile : public LazyMemberLoader {
743750
}
744751

745752
/// Returns the type with the given ID, deserializing it if needed.
753+
///
754+
/// \sa getTypeChecked
746755
Type getType(serialization::TypeID TID);
747756

757+
/// Returns the type with the given ID, deserializing it if needed.
758+
llvm::Expected<Type> getTypeChecked(serialization::TypeID TID);
759+
748760
/// Returns the identifier with the given ID, deserializing it if needed.
749761
Identifier getIdentifier(serialization::IdentifierID IID);
750762

@@ -754,9 +766,21 @@ class ModuleFile : public LazyMemberLoader {
754766
/// \param ForcedContext Optional override for the decl context of certain
755767
/// kinds of decls, used to avoid re-entrant
756768
/// deserialization.
769+
///
770+
/// \sa getDeclChecked
757771
Decl *getDecl(serialization::DeclID DID,
758772
Optional<DeclContext *> ForcedContext = None);
759773

774+
/// Returns the decl with the given ID, deserializing it if needed.
775+
///
776+
/// \param DID The ID for the decl within this module.
777+
/// \param ForcedContext Optional override for the decl context of certain
778+
/// kinds of decls, used to avoid re-entrant
779+
/// deserialization.
780+
llvm::Expected<Decl *>
781+
getDeclChecked(serialization::DeclID DID,
782+
Optional<DeclContext *> ForcedContext = None);
783+
760784
/// Returns the decl context with the given ID, deserializing it if needed.
761785
DeclContext *getDeclContext(serialization::DeclContextID DID);
762786

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
874874
Opts.EnableClassResilience |=
875875
Args.hasArg(OPT_enable_class_resilience);
876876

877+
Opts.EnableDeserializationRecovery |=
878+
Args.hasArg(OPT_enable_experimental_deserialization_recovery);
879+
877880
Opts.DisableAvailabilityChecking |=
878881
Args.hasArg(OPT_disable_availability_checking);
879882

0 commit comments

Comments
 (0)