Skip to content

Commit 41ec454

Browse files
committed
[Serialization] Update error message on deserialization failure
This adds information about whether the module was built from source or from a swiftinterface, whether it's resilient or not, and tweaks the format.
1 parent 2854c1b commit 41ec454

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,17 @@ void ModuleFileSharedCore::fatal(llvm::Error error) const {
584584
}
585585

586586
void ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream &os) const {
587-
os << "module '" << Name << "' with full misc version '" << MiscVersion
588-
<< "'";
587+
bool resilient = ResilienceStrategy(Bits.ResilienceStrategy) ==
588+
ResilienceStrategy::Resilient;
589+
os << "module '" << Name
590+
<< "', builder version '" << MiscVersion
591+
<< "', built from "
592+
<< (Bits.IsBuiltFromInterface? "swiftinterface": "source")
593+
<< ", " << (resilient? "resilient": "non-resilient");
589594
if (Bits.IsAllowModuleWithCompilerErrorsEnabled)
590-
os << " (built with -experimental-allow-module-with-compiler-errors)";
595+
os << ", built with -experimental-allow-module-with-compiler-errors";
591596
if (ModuleInputBuffer)
592-
os << " at '" << ModuleInputBuffer->getBufferIdentifier() << "'";
597+
os << ", loaded from '" << ModuleInputBuffer->getBufferIdentifier() << "'";
593598
}
594599

595600
ModuleFileSharedCore::~ModuleFileSharedCore() { }

test/Serialization/Recovery/crash-recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public class Sub: Base {
1919
// CHECK-CRASH-LABEL: *** DESERIALIZATION FAILURE ***
2020
// CHECK-CRASH-LABEL: *** If any module named here was modified in the SDK, please delete the ***
2121
// CHECK-CRASH-LABEL: *** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
22-
// CHECK-CRASH: module 'Lib' with full misc version {{.*}}4.1.50
22+
// CHECK-CRASH: module 'Lib', builder version {{.*}}4.1.50
2323
// CHECK-CRASH: could not find 'disappearingMethod()' in parent class

test/Serialization/Recovery/crash-xref.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44
// RUN: %empty-directory(%t/partials)
55
// RUN: %empty-directory(%t/normal)
66
// RUN: %empty-directory(%t/errors)
7+
// RUN: %empty-directory(%t/cache)
78

89
/// Compile module A with a type and an empty module B.
9-
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/A.swiftmodule -module-name A -D LIB
10-
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/B.swiftmodule -module-name B
10+
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/A.swiftmodule -module-name A -D LIB -enable-library-evolution
11+
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/B.swiftmodule -module-name B -enable-library-evolution
1112

1213
/// Compile a client using the type from A.
13-
// RUN: %target-swift-frontend %s -emit-module-path %t/normal/Client.swiftmodule -module-name Client -D CLIENT -I %t/partials
14+
// RUN: %target-swift-frontend %s -emit-module-path %t/normal/Client.swiftmodule -module-name Client -D CLIENT -I %t/partials -enable-library-evolution -emit-module-interface-path %t/normal/Client.swiftinterface
1415
// RUN: %target-swift-frontend %s -emit-module-path %t/errors/Client.swiftmodule -module-name Client -D CLIENT -I %t/partials -experimental-allow-module-with-compiler-errors
1516

17+
/// Force rebuilding from the swiftinterface.
18+
// RUN: mv %t/normal/Client.swiftmodule %t/swap-Client.swiftmodule
19+
// RUN: echo "import Client" | %target-swift-frontend -typecheck - -I %t/partials -I %t/normal -module-cache-path %t/cache/
20+
//2> /dev/null
21+
// RUN: mv %t/swap-Client.swiftmodule %t/normal/Client.swiftmodule
22+
1623
/// Swap A and B around! A is now empty and B defines the type.
1724
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/A.swiftmodule -module-name A
1825
// RUN: %target-swift-frontend %s -emit-module-path %t/partials/B.swiftmodule -module-name B -D LIB
@@ -25,7 +32,7 @@
2532
// NORMALFAILURE-LABEL: *** DESERIALIZATION FAILURE ***
2633
// NORMALFAILURE-LABEL: *** If any module named here was modified in the SDK, please delete the ***
2734
// NORMALFAILURE-LABEL: *** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
28-
// NORMALFAILURE-NEXT: module 'Client' with full misc version {{.*}}'
35+
// NORMALFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source, resilient, loaded from
2936
// NORMALFAILURE-NEXT: Could not deserialize type for 'foo()'
3037
// NORMALFAILURE-NEXT: Caused by: top-level value not found
3138
// NORMALFAILURE-NEXT: Cross-reference to module 'A'
@@ -37,14 +44,19 @@
3744
// ALLOWFAILURE-LABEL: *** DESERIALIZATION FAILURE ***
3845
// ALLOWFAILURE-LABEL: *** If any module named here was modified in the SDK, please delete the ***
3946
// ALLOWFAILURE-LABEL: *** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
40-
// ALLOWFAILURE-NEXT: module 'Client' with full misc version {{.*}}' (built with -experimental-allow-module-with-compiler-errors)
47+
// ALLOWFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source, non-resilient, built with -experimental-allow-module-with-compiler-errors, loaded from
4148
// ALLOWFAILURE-NEXT: Could not deserialize type for 'foo()'
4249
// ALLOWFAILURE-NEXT: Caused by: top-level value not found
4350
// ALLOWFAILURE-NEXT: Cross-reference to module 'A'
4451
// ALLOWFAILURE-NEXT: ... SomeType
4552
// ALLOWFAILURE-NEXT: Notes:
4653
// ALLOWFAILURE-NEXT: * There is a matching 'SomeType' in module 'B'. If this is imported from clang, please make sure the header is part of a single clang module.
4754

55+
/// Test a swiftmodule rebuilt from the swiftinterface.
56+
// RUN: not --crash %target-swift-frontend -emit-sil %t/cache/Client-*.swiftmodule -module-name Client -I %t/partials -disable-deserialization-recovery 2> %t/cache_stderr
57+
// RUN: cat %t/cache_stderr | %FileCheck %s -check-prefixes=CACHEFAILURE
58+
// CACHEFAILURE: module 'Client', builder version {{.*}}', built from swiftinterface, resilient
59+
4860
#if LIB
4961
public struct SomeType {
5062
public init() {}

0 commit comments

Comments
 (0)