Skip to content

Commit 5e3a6ac

Browse files
authored
Merge pull request #29044 from xymus/rdar58022345-5.2
[5.2][Serialization] Recover from deserializing an enum from a missing module
2 parents 03a76c7 + 310fe05 commit 5e3a6ac

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,14 +1889,25 @@ DeclContext *ModuleFile::getLocalDeclContext(LocalDeclContextID DCID) {
18891889
}
18901890

18911891
DeclContext *ModuleFile::getDeclContext(DeclContextID DCID) {
1892+
auto deserialized = getDeclContextChecked(DCID);
1893+
if (!deserialized) {
1894+
fatal(deserialized.takeError());
1895+
}
1896+
return deserialized.get();
1897+
}
1898+
1899+
Expected<DeclContext *> ModuleFile::getDeclContextChecked(DeclContextID DCID) {
18921900
if (!DCID)
18931901
return FileContext;
18941902

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

1898-
auto D = getDecl(DCID.getAsDeclID().getValue());
1906+
auto deserialized = getDeclChecked(DCID.getAsDeclID().getValue());
1907+
if (!deserialized)
1908+
return deserialized.takeError();
18991909

1910+
auto D = deserialized.get();
19001911
if (auto GTD = dyn_cast<GenericTypeDecl>(D))
19011912
return GTD;
19021913
if (auto ED = dyn_cast<ExtensionDecl>(D))
@@ -3485,7 +3496,6 @@ class swift::DeclDeserializer {
34853496
numConformances, numInherited,
34863497
rawInheritedAndDependencyIDs);
34873498

3488-
auto DC = MF.getDeclContext(contextID);
34893499
if (declOrOffset.isComplete())
34903500
return declOrOffset;
34913501

@@ -3499,6 +3509,11 @@ class swift::DeclDeserializer {
34993509
}
35003510
}
35013511

3512+
auto DCOrError = MF.getDeclContextChecked(contextID);
3513+
if (!DCOrError)
3514+
return DCOrError.takeError();
3515+
auto DC = DCOrError.get();
3516+
35023517
auto genericParams = MF.maybeReadGenericParams(DC);
35033518
if (declOrOffset.isComplete())
35043519
return declOrOffset;

lib/Serialization/ModuleFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,11 @@ class ModuleFile
913913
/// Returns the decl context with the given ID, deserializing it if needed.
914914
DeclContext *getDeclContext(serialization::DeclContextID DID);
915915

916+
/// Returns the decl context with the given ID, deserializing it if needed,
917+
/// or the first error.
918+
llvm::Expected<DeclContext *>
919+
getDeclContextChecked(serialization::DeclContextID DCID);
920+
916921
/// Returns the local decl context with the given ID, deserializing it if needed.
917922
DeclContext *getLocalDeclContext(serialization::LocalDeclContextID DID);
918923

0 commit comments

Comments
 (0)