Skip to content

Commit 65b5f82

Browse files
committed
[Serialization|NFC] Extract some diagnostic logic into diagnoseModularizationError
1 parent a475f4c commit 65b5f82

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,15 @@ void ExtensionError::diagnose(const ModuleFile *MF) const {
232232
diag::modularization_issue_side_effect_extension_error);
233233
}
234234

235-
llvm::Error ModuleFile::diagnoseFatal(llvm::Error error) const {
236-
237-
auto &ctx = getContext();
238-
if (FileContext) {
239-
if (ctx.LangOpts.EnableDeserializationRecovery) {
240-
// Attempt to report relevant errors as diagnostics.
241-
// At this time, only ModularizationErrors are reported directly. They
242-
// can get here either directly or as underlying causes to a TypeError or
243-
// and ExtensionError.
244-
auto handleModularizationError =
245-
[&](const ModularizationError &modularError) -> llvm::Error {
246-
modularError.diagnose(this);
247-
return llvm::Error::success();
248-
};
249-
error = llvm::handleErrors(std::move(error),
235+
llvm::Error
236+
ModuleFile::diagnoseModularizationError(llvm::Error error,
237+
DiagnosticBehavior limit) const {
238+
auto handleModularizationError =
239+
[&](const ModularizationError &modularError) -> llvm::Error {
240+
modularError.diagnose(this, limit);
241+
return llvm::Error::success();
242+
};
243+
llvm::Error outError = llvm::handleErrors(std::move(error),
250244
handleModularizationError,
251245
[&](TypeError &typeError) -> llvm::Error {
252246
if (typeError.diagnoseUnderlyingReason(handleModularizationError)) {
@@ -263,6 +257,16 @@ llvm::Error ModuleFile::diagnoseFatal(llvm::Error error) const {
263257
return llvm::make_error<ExtensionError>(std::move(extError));
264258
});
265259

260+
return outError;
261+
}
262+
263+
llvm::Error ModuleFile::diagnoseFatal(llvm::Error error) const {
264+
265+
auto &ctx = getContext();
266+
if (FileContext) {
267+
if (ctx.LangOpts.EnableDeserializationRecovery) {
268+
error = diagnoseModularizationError(std::move(error));
269+
266270
// If no error is left, it was reported as a diagnostic. There's no
267271
// need to crash.
268272
if (!error)

lib/Serialization/ModuleFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ class ModuleFile
422422
/// silently.
423423
void diagnoseAndConsumeError(llvm::Error error) const;
424424

425+
/// Report modularization error, either directly or indirectly if it
426+
/// caused a \c TypeError or \c ExtensionError. Returns any unhandled errors.
427+
llvm::Error
428+
diagnoseModularizationError(llvm::Error error,
429+
DiagnosticBehavior limit = DiagnosticBehavior::Fatal) const;
430+
425431
/// Report an unexpected format error that could happen only from a
426432
/// memory-level inconsistency. Please prefer passing an error to
427433
/// `fatal(llvm::Error error)` when possible.

0 commit comments

Comments
 (0)