Skip to content

[Serialization] Proof-of-concept: drop overriding methods if the base is missing #8580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@ ERROR(serialization_target_too_new_repl,none,
"module file's minimum deployment target is %0 v%1.%2%select{|.%3}3: %4",
(StringRef, unsigned, unsigned, unsigned, StringRef))

ERROR(serialization_fatal,Fatal,
"fatal error encountered while reading from module '%0'; "
"please file a bug report with your project and the crash log",
(StringRef))

ERROR(reserved_member_name,none,
"type member may not be named %0, since it would conflict with the"
" 'foo.%1' expression", (DeclName, StringRef))
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ namespace swift {
/// new enough?
bool EnableTargetOSChecking = true;

/// Whether to attempt to recover from missing cross-references and other
/// errors when deserializing from a Swift module.
///
/// This is a staging flag; eventually it will be on by default.
bool EnableDeserializationRecovery = false;

/// Should we use \c ASTScope-based resolution for unqualified name lookup?
bool EnableASTScopeLookup = false;

Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def enable_experimental_property_behaviors :
Flag<["-"], "enable-experimental-property-behaviors">,
HelpText<"Enable experimental property behaviors">;

def enable_experimental_deserialization_recovery :
Flag<["-"], "enable-experimental-deserialization-recovery">,
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;

def enable_cow_existentials : Flag<["-"], "enable-cow-existentials">,
HelpText<"Enable the copy-on-write existential implementation">;

Expand Down
28 changes: 26 additions & 2 deletions include/swift/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"

namespace llvm {
Expand Down Expand Up @@ -435,6 +436,10 @@ class ModuleFile : public LazyMemberLoader {
return getStatus();
}

/// Emits one last diagnostic, logs the error, and then aborts for the stack
/// trace.
void fatal(llvm::Error error) LLVM_ATTRIBUTE_NORETURN;

ASTContext &getContext() const {
assert(FileContext && "no associated context yet");
return FileContext->getParentModule()->getASTContext();
Expand Down Expand Up @@ -542,12 +547,14 @@ class ModuleFile : public LazyMemberLoader {
/// because it reads from the cursor, it is not possible to reset the cursor
/// after reading. Nothing should ever follow an XREF record except
/// XREF_PATH_PIECE records.
Decl *resolveCrossReference(ModuleDecl *M, uint32_t pathLen);
llvm::Expected<Decl *> resolveCrossReference(ModuleDecl *M, uint32_t pathLen);

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

void configureStorage(AbstractStorageDecl *storage, unsigned rawStorageKind,
/// Sets the accessors for \p storage based on \p rawStorageKind.
void configureStorage(AbstractStorageDecl *storage,
unsigned rawStorageKind,
serialization::DeclID getter,
serialization::DeclID setter,
serialization::DeclID materializeForSet,
Expand Down Expand Up @@ -743,8 +750,13 @@ class ModuleFile : public LazyMemberLoader {
}

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

/// Returns the type with the given ID, deserializing it if needed.
llvm::Expected<Type> getTypeChecked(serialization::TypeID TID);

/// Returns the identifier with the given ID, deserializing it if needed.
Identifier getIdentifier(serialization::IdentifierID IID);

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

/// Returns the decl with the given ID, deserializing it if needed.
///
/// \param DID The ID for the decl within this module.
/// \param ForcedContext Optional override for the decl context of certain
/// kinds of decls, used to avoid re-entrant
/// deserialization.
llvm::Expected<Decl *>
getDeclChecked(serialization::DeclID DID,
Optional<DeclContext *> ForcedContext = None);

/// Returns the decl context with the given ID, deserializing it if needed.
DeclContext *getDeclContext(serialization::DeclContextID DID);

Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableClassResilience |=
Args.hasArg(OPT_enable_class_resilience);

Opts.EnableDeserializationRecovery |=
Args.hasArg(OPT_enable_experimental_deserialization_recovery);

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);

Expand Down
Loading