Skip to content

[Serialization] Recover from deserializing an enum from a missing module #28911

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
merged 1 commit into from
Jan 6, 2020
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
19 changes: 17 additions & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,14 +1889,25 @@ DeclContext *ModuleFile::getLocalDeclContext(LocalDeclContextID DCID) {
}

DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) {
auto deserialized = getDeclContextChecked(DCID);
if (!deserialized) {
fatal(deserialized.takeError());
}
return deserialized.get();
}

Expected<DeclContext *> ModuleFile::getDeclContextChecked(DeclContextID DCID) {
if (!DCID)
return FileContext;

if (Optional<LocalDeclContextID> contextID = DCID.getAsLocalDeclContextID())
return getLocalDeclContext(contextID.getValue());

auto D = getDecl(DCID.getAsDeclID().getValue());
auto deserialized = getDeclChecked(DCID.getAsDeclID().getValue());
if (!deserialized)
return deserialized.takeError();

auto D = deserialized.get();
if (auto GTD = dyn_cast<GenericTypeDecl>(D))
return GTD;
if (auto ED = dyn_cast<ExtensionDecl>(D))
Expand Down Expand Up @@ -3496,7 +3507,6 @@ class swift::DeclDeserializer {
numConformances, numInherited,
rawInheritedAndDependencyIDs);

auto DC = MF.getDeclContext(contextID);
if (declOrOffset.isComplete())
return declOrOffset;

Expand All @@ -3510,6 +3520,11 @@ class swift::DeclDeserializer {
}
}

auto DCOrError = MF.getDeclContextChecked(contextID);
if (!DCOrError)
return DCOrError.takeError();
auto DC = DCOrError.get();

auto genericParams = MF.maybeReadGenericParams(DC);
if (declOrOffset.isComplete())
return declOrOffset;
Expand Down
5 changes: 5 additions & 0 deletions lib/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ class ModuleFile
/// Returns the decl context with the given ID, deserializing it if needed.
DeclContext *getDeclContext(serialization::DeclContextID DID);

/// Returns the decl context with the given ID, deserializing it if needed,
/// or the first error.
llvm::Expected<DeclContext *>
getDeclContextChecked(serialization::DeclContextID DCID);

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

Expand Down