Skip to content
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
6 changes: 5 additions & 1 deletion lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,11 @@ ModuleFile::readConformanceChecked(llvm::BitstreamCursor &Cursor,
ProtocolConformanceXrefLayout::readRecord(scratch, protoID, nominalID,
moduleID);

auto nominal = cast<NominalTypeDecl>(getDecl(nominalID));
auto maybeNominal = getDeclChecked(nominalID);
if (!maybeNominal)
return maybeNominal.takeError();

auto nominal = cast<NominalTypeDecl>(maybeNominal.get());
PrettyStackTraceDecl trace("cross-referencing conformance for", nominal);
auto proto = cast<ProtocolDecl>(getDecl(protoID));
PrettyStackTraceDecl traceTo("... to", proto);
Expand Down
30 changes: 27 additions & 3 deletions lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,6 +3104,16 @@ void SILDeserializer::readWitnessTableEntries(

SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId,
SILWitnessTable *existingWt) {
auto deserialized = readWitnessTableChecked(WId, existingWt);
if (!deserialized) {
MF->fatal(deserialized.takeError());
}
return deserialized.get();
}

llvm::Expected<SILWitnessTable *>
SILDeserializer::readWitnessTableChecked(DeclID WId,
SILWitnessTable *existingWt) {
if (WId == 0)
return nullptr;
assert(WId <= WitnessTables.size() && "invalid WitnessTable ID");
Expand Down Expand Up @@ -3150,8 +3160,12 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId,
}

// Deserialize Conformance.
auto maybeConformance = MF->readConformanceChecked(SILCursor);
if (!maybeConformance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some comments why this error may happen? Otherwise LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added documentation on the prototype for readWitnessTableChecked and on the only client readWitnessTables.

return maybeConformance.takeError();

auto theConformance = cast<RootProtocolConformance>(
MF->readConformance(SILCursor).getConcrete());
maybeConformance.get().getConcrete());

PrettyStackTraceConformance trace(SILMod.getASTContext(),
"deserializing SIL witness table for",
Expand Down Expand Up @@ -3228,8 +3242,18 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId,
void SILDeserializer::getAllWitnessTables() {
if (!WitnessTableList)
return;
for (unsigned I = 0, E = WitnessTables.size(); I < E; I++)
readWitnessTable(I + 1, nullptr);
for (unsigned I = 0, E = WitnessTables.size(); I < E; I++) {
auto maybeTable = readWitnessTableChecked(I + 1, nullptr);
if (!maybeTable) {
if (maybeTable.errorIsA<XRefNonLoadedModuleError>()) {
// This is most likely caused by decls hidden by an implementation-only
// import, it is safe to ignore for this function's purpose.
consumeError(maybeTable.takeError());
} else {
MF->fatal(maybeTable.takeError());
}
}
}
}

SILWitnessTable *
Expand Down
11 changes: 10 additions & 1 deletion lib/Serialization/DeserializeSIL.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ namespace swift {
SILVTable *readVTable(serialization::DeclID);
SILGlobalVariable *getGlobalForReference(StringRef Name);
SILGlobalVariable *readGlobalVar(StringRef Name);
SILWitnessTable *readWitnessTable(serialization::DeclID,

/// Read and return the witness table identified with \p WId.
SILWitnessTable *readWitnessTable(serialization::DeclID WId,
SILWitnessTable *existingWt);

/// Read the witness table identified with \p WId, return the table or
/// the first error if any.
llvm::Expected<SILWitnessTable *>
readWitnessTableChecked(serialization::DeclID WId,
SILWitnessTable *existingWt);

void readWitnessTableEntries(
llvm::BitstreamEntry &entry,
std::vector<SILWitnessTable::Entry> &witnessEntries,
Expand Down
5 changes: 3 additions & 2 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,10 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
std::copy_if(
loadedModuleFile->getDependencies().begin(),
loadedModuleFile->getDependencies().end(), std::back_inserter(missing),
[&duplicates](const ModuleFile::Dependency &dependency) -> bool {
[&duplicates, &Ctx](const ModuleFile::Dependency &dependency) -> bool {
if (dependency.isLoaded() || dependency.isHeader() ||
dependency.isImplementationOnly()) {
(dependency.isImplementationOnly() &&
Ctx.LangOpts.DebuggerSupport)) {
return false;
}
return duplicates.insert(dependency.RawPath).second;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum __attribute__((flag_enum,enum_extensibility(open))) CEnum : int {
A = 1 << 0,
B = 1 << 1,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ module SuperclassObjC { header "SuperclassObjC.h" }
module Typedefs { header "Typedefs.h" }
module TypeRemovalObjC { header "TypeRemovalObjC.h" }
module Types { header "Types.h" }
module Conformance { header "Conformance.h" }
18 changes: 18 additions & 0 deletions test/Serialization/Recovery/missing-clang-module-conformance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// Recover from reading witness table involving a synthesized conformance
/// rdar://problem/58924131

// RUN: %empty-directory(%t)
// RUN: cp -r %S/Inputs/custom-modules %t/
// RUN: %target-swift-frontend -emit-module %s -module-name MyModule -emit-module-path %t/MyModule.swiftmodule -I %t/custom-modules -swift-version 5

/// Delete the clang module
// RUN: rm -r %t/custom-modules/

// RUN: not %target-sil-opt %t/MyModule.swiftmodule 2>&1 | %FileCheck %s

@_implementationOnly import Conformance
// CHECK: missing required module 'Conformance'

public func foo<T: OptionSet>(_ t: T) {}

foo(CEnum.A)