Skip to content

Commit e0014b4

Browse files
committed
[Serialization|NFC] Move free floating functions to methods
Move some deserialization error handling services to methods under ModuleFile. This will give access to the ASTContext and allow to report diagnostics. Also rename `consumeErrorIfXRefNonLoadedModule` into the more general `consumeExpectedError` that is more appropriate for future improvements.
1 parent f2b02c1 commit e0014b4

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ void UnsafeDeserializationError::anchor() {}
160160
const char ModularizationError::ID = '\0';
161161
void ModularizationError::anchor() {}
162162

163-
static llvm::Error consumeErrorIfXRefNonLoadedModule(llvm::Error &&error);
164-
165163
/// Skips a single record in the bitstream.
166164
///
167165
/// Destroys the stream position if the next entry is not a record.
@@ -3999,7 +3997,7 @@ class DeclDeserializer {
39993997
if (!subMapOrError) {
40003998
// If the underlying type references internal details, ignore it.
40013999
auto unconsumedError =
4002-
consumeErrorIfXRefNonLoadedModule(subMapOrError.takeError());
4000+
MF.consumeExpectedError(subMapOrError.takeError());
40034001
if (unconsumedError)
40044002
return std::move(unconsumedError);
40054003
} else {
@@ -7267,13 +7265,16 @@ Decl *handleErrorAndSupplyMissingProtoMember(ASTContext &context,
72677265
return suppliedMissingMember;
72687266
}
72697267

7270-
Decl *handleErrorAndSupplyMissingMiscMember(llvm::Error &&error) {
7271-
llvm::consumeError(std::move(error));
7268+
Decl *
7269+
ModuleFile::handleErrorAndSupplyMissingMiscMember(llvm::Error &&error) const {
7270+
diagnoseAndConsumeError(std::move(error));
72727271
return nullptr;
72737272
}
72747273

7275-
Decl *handleErrorAndSupplyMissingMember(ASTContext &context, Decl *container,
7276-
llvm::Error &&error) {
7274+
Decl *
7275+
ModuleFile::handleErrorAndSupplyMissingMember(ASTContext &context,
7276+
Decl *container,
7277+
llvm::Error &&error) const {
72777278
// Drop the member if it had a problem.
72787279
// FIXME: Handle overridable members in class extensions too, someday.
72797280
if (auto *containingClass = dyn_cast<ClassDecl>(container)) {
@@ -7347,7 +7348,7 @@ void ModuleFile::loadAllMembers(Decl *container, uint64_t contextData) {
73477348
}
73487349
}
73497350

7350-
static llvm::Error consumeErrorIfXRefNonLoadedModule(llvm::Error &&error) {
7351+
llvm::Error ModuleFile::consumeExpectedError(llvm::Error &&error) {
73517352
// Missing module errors are most likely caused by an
73527353
// implementation-only import hiding types and decls.
73537354
// rdar://problem/60291019
@@ -7441,7 +7442,7 @@ ModuleFile::loadAllConformances(const Decl *D, uint64_t contextData,
74417442

74427443
if (!conformance) {
74437444
auto unconsumedError =
7444-
consumeErrorIfXRefNonLoadedModule(conformance.takeError());
7445+
consumeExpectedError(conformance.takeError());
74457446
if (unconsumedError) {
74467447
// Ignore if allowing errors, it's just doing a best effort to produce
74477448
// *some* module anyway.

lib/Serialization/ModuleFile.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ class ModuleFile
341341
template <typename T, typename ...Args>
342342
T *createDecl(Args &&... args);
343343

344+
Decl *handleErrorAndSupplyMissingMiscMember(llvm::Error &&error) const;
345+
346+
Decl *handleErrorAndSupplyMissingMember(ASTContext &context,
347+
Decl *container,
348+
llvm::Error &&error) const;
349+
344350
public:
345351
/// Change the status of the current module.
346352
Status error(Status issue) {
@@ -404,6 +410,13 @@ class ModuleFile
404410
return llvm::consumeError(diagnoseFatal(msg));
405411
}
406412

413+
/// Consume errors that are usually safe to ignore because they
414+
/// are expected to support language features or caused by project
415+
/// misconfigurations.
416+
///
417+
/// If the error is handled, success is returned, otherwise the original
418+
/// error is returned.
419+
llvm::Error consumeExpectedError(llvm::Error &&error);
407420

408421
/// Report an unexpected format error that could happen only from a
409422
/// memory-level inconsistency. Please prefer passing an error to

0 commit comments

Comments
 (0)