mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Serialization] Intro -Rmodule-recovery to remark about silent errors
Deserialization recovery silently drops errors and the affected decls. This can lead to surprises when a function from an imported module simply disappears without an explanation. This commit introduces the flag -Rmodule-recovery to report as remarks some of these previously silently dropped issues. It can be used to debug project configuration issues.
This commit is contained in:
@@ -238,6 +238,9 @@ namespace swift {
|
||||
/// Emit a remark after loading a module.
|
||||
bool EnableModuleLoadingRemarks = false;
|
||||
|
||||
/// Emit remarks about contextual inconsistencies in loaded modules.
|
||||
bool EnableModuleRecoveryRemarks = false;
|
||||
|
||||
/// Emit a remark when indexing a system module.
|
||||
bool EnableIndexingSystemModuleRemarks = false;
|
||||
|
||||
|
||||
@@ -388,7 +388,10 @@ def emit_cross_import_remarks : Flag<["-"], "Rcross-import">,
|
||||
|
||||
def remark_loading_module : Flag<["-"], "Rmodule-loading">,
|
||||
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
||||
HelpText<"Emit a remark and file path of each loaded module">;
|
||||
HelpText<"Emit remarks about loaded module">;
|
||||
def remark_module_recovery : Flag<["-"], "Rmodule-recovery">,
|
||||
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
||||
HelpText<"Emit remarks about contextual inconsistencies in loaded modules">;
|
||||
|
||||
def remark_indexing_system_module : Flag<["-"], "Rindexing-system-module">,
|
||||
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
||||
|
||||
@@ -929,6 +929,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Opts.EnableCrossImportRemarks = Args.hasArg(OPT_emit_cross_import_remarks);
|
||||
|
||||
Opts.EnableModuleLoadingRemarks = Args.hasArg(OPT_remark_loading_module);
|
||||
Opts.EnableModuleRecoveryRemarks = Args.hasArg(OPT_remark_module_recovery);
|
||||
|
||||
Opts.EnableIndexingSystemModuleRemarks = Args.hasArg(OPT_remark_indexing_system_module);
|
||||
|
||||
|
||||
@@ -7384,6 +7384,14 @@ llvm::Error ModuleFile::consumeExpectedError(llvm::Error &&error) {
|
||||
}
|
||||
|
||||
void ModuleFile::diagnoseAndConsumeError(llvm::Error error) const {
|
||||
auto &ctx = getContext();
|
||||
if (ctx.LangOpts.EnableModuleRecoveryRemarks) {
|
||||
error = diagnoseModularizationError(std::move(error),
|
||||
DiagnosticBehavior::Remark);
|
||||
// If error was already diagnosed it was also consumed.
|
||||
if (!error)
|
||||
return;
|
||||
}
|
||||
|
||||
consumeError(std::move(error));
|
||||
}
|
||||
|
||||
49
test/Serialization/Recovery/module-recovery-remarks.swift
Normal file
49
test/Serialization/Recovery/module-recovery-remarks.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %empty-directory(%t/sdk)
|
||||
// RUN: split-file %s %t
|
||||
|
||||
/// Compile two library modules A and A_related, and a middle library LibWithXRef with a reference to a type in A.
|
||||
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
|
||||
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related
|
||||
// RUN: %target-swift-frontend %t/LibWithXRef.swift -emit-module-path %t/sdk/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -swift-version 5 -enable-library-evolution
|
||||
|
||||
/// Move MyType from A to A_related, triggering most notes.
|
||||
// RUN: %target-swift-frontend %t/EmptyOverlay.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
|
||||
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related -I %t
|
||||
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk -swift-version 4 2>&1 \
|
||||
// RUN: | %FileCheck --check-prefixes CHECK-MOVED %s
|
||||
|
||||
/// Main error downgraded to a remark.
|
||||
// CHECK-MOVED: LibWithXRef.swiftmodule:1:1: remark: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'A_related'
|
||||
//--- module.modulemap
|
||||
module A {
|
||||
header "A.h"
|
||||
}
|
||||
|
||||
//--- A.h
|
||||
void foo() {}
|
||||
|
||||
//--- Empty.swift
|
||||
|
||||
//--- EmptyOverlay.swift
|
||||
@_exported import A
|
||||
|
||||
//--- LibOriginal.swift
|
||||
@_exported import A
|
||||
|
||||
public struct MyType {
|
||||
public init() {}
|
||||
}
|
||||
|
||||
//--- LibWithXRef.swift
|
||||
import A
|
||||
import A_related
|
||||
|
||||
public func foo() -> MyType {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
//--- Client.swift
|
||||
import LibWithXRef
|
||||
|
||||
foo()
|
||||
Reference in New Issue
Block a user