Skip to content

Commit cbbc29b

Browse files
committed
[Serialization] Add whether allowing errors to the pretty stack output
It's currently not obvious in crash reports whether compiling with errors is enabled or not. Since this option can make previously "impossible" paths now possible, add a message to both the pretty stack output and fatal deserialization diagnostics to point out that it is enabled.
1 parent b9a9758 commit cbbc29b

File tree

7 files changed

+62
-5
lines changed

7 files changed

+62
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,9 @@ ERROR(serialization_fatal,Fatal,
793793
SWIFT_BUG_REPORT_MESSAGE,
794794
(StringRef))
795795
NOTE(serialization_misc_version,none,
796-
"module '%0' full misc version is '%1'",
797-
(StringRef, StringRef))
796+
"module '%0' full misc version is '%1'"
797+
"%select{ (built while allowing compiler errors)|}2",
798+
(StringRef, StringRef, bool))
798799
NOTE(serialization_compatibility_version_mismatch,none,
799800
"compiling as Swift %0, with '%1' built as Swift %2 "
800801
"(this is supported but may expose additional compiler issues)",

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,11 @@ int swift::performFrontend(ArrayRef<const char *> Args,
20462046
return finishDiagProcessing(1, /*verifierEnabled*/ false);
20472047
}
20482048

2049+
Optional<llvm::PrettyStackTraceString> allowErrorsStackTrace;
2050+
if (Invocation.getFrontendOptions().AllowModuleWithCompilerErrors)
2051+
allowErrorsStackTrace.emplace("While allowing modules with compiler errors "
2052+
"enabled");
2053+
20492054
// Make an array of PrettyStackTrace objects to dump the configuration files
20502055
// we used to parse the arguments. These are RAII objects, so they and the
20512056
// buffers they refer to must be kept alive in order to be useful. (That is,

lib/Serialization/Deserialization.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ static void skipRecord(llvm::BitstreamCursor &cursor, unsigned recordKind) {
169169
void ModuleFile::fatal(llvm::Error error) {
170170
if (FileContext) {
171171
getContext().Diags.diagnose(SourceLoc(), diag::serialization_fatal, Core->Name);
172-
getContext().Diags.diagnose(SourceLoc(), diag::serialization_misc_version,
173-
Core->Name, Core->MiscVersion);
172+
getContext().Diags.diagnose(
173+
SourceLoc(), diag::serialization_misc_version, Core->Name,
174+
Core->MiscVersion, allowCompilerErrors());
174175

175176
if (!Core->CompatibilityVersion.empty()) {
176177
if (getContext().LangOpts.EffectiveLanguageVersion
@@ -6706,3 +6707,9 @@ Optional<ForeignAsyncConvention> ModuleFile::maybeReadForeignAsyncConvention() {
67066707
completionHandlerErrorFlagParamIndex,
67076708
errorFlagPolarity);
67086709
}
6710+
6711+
void serialization::PrettyStackTraceModuleFile::outputModuleBuildInfo(
6712+
raw_ostream &os) const {
6713+
if (MF.compiledAllowingCompilerErrors())
6714+
os << " (built while allowing compiler errors)";
6715+
}

lib/Serialization/DeserializationErrors.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,12 @@ class PrettyStackTraceModuleFile : public llvm::PrettyStackTraceEntry {
470470
: PrettyStackTraceModuleFile("While reading from", module) {}
471471

472472
void print(raw_ostream &os) const override {
473-
os << Action << " \'" << getNameOfModule(&MF) << "'\n";
473+
os << Action << " \'" << getNameOfModule(&MF) << "'";
474+
outputModuleBuildInfo(os);
475+
os << "\n";
474476
}
477+
478+
void outputModuleBuildInfo(raw_ostream &os) const;
475479
};
476480

477481
class PrettyStackTraceModuleFileCore : public llvm::PrettyStackTraceEntry {

test/Frontend/crash.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
// CHECK-NEXT: test{{[\\/]}}Frontend{{[\\/]}}crash.swift{{$}}
1111
// CHECK-NEXT: ---
1212

13+
// Check that a message when allowing errors is output
14+
// RUN: not --crash %target-swift-frontend -typecheck -debug-crash-after-parse -experimental-allow-module-with-compiler-errors %s 2>&1 | %FileCheck -check-prefix CHECK-ALLOW %s
15+
// CHECK-ALLOW-LABEL: Stack dump
16+
// CHECK-ALLOW: While allowing modules with compiler errors enabled
17+
1318
func anchor() {}
1419
anchor()
1520

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: touch %t/empty.swift
3+
4+
// RUN: %target-swift-frontend -emit-module -o %t/errors.partial.swiftmodule -module-name errors -experimental-allow-module-with-compiler-errors %s
5+
// RUN: %target-swift-frontend -emit-module -o %t/errorsempty.partial.swiftmodule -module-name errors %t/empty.swift
6+
7+
// Note - running the merge without allow errors to force a crash, we want
8+
// to check if there's a message about allowing compiler errors for the
9+
// deserialized module
10+
// RUN: not --crash %target-swift-frontend -module-name errors -emit-module -o %t/errors.swiftmodule %t/errors.partial.swiftmodule %t/errorsempty.partial.swiftmodule 2>&1 | %FileCheck %s
11+
12+
// REQUIRES: asserts
13+
14+
typealias AnAlias = SomeStruct
15+
16+
// CHECK: While reading from 'errors' (built while allowing compiler errors)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: touch %t/empty.swift
4+
// RUN: %{python} %utils/split_file.py -o %t %s
5+
6+
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.partial.swiftmodule -module-name errors -experimental-allow-module-with-compiler-errors %t/errors.swift
7+
// RUN: %target-swift-frontend -emit-module -o %t/errorsempty.partial.swiftmodule -module-name errors %t/empty.swift
8+
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/errors.partial.swiftmodule %t/errorsempty.partial.swiftmodule
10+
11+
// RUN: %target-swift-frontend -emit-module -o %t/mods/uses.swiftmodule -experimental-allow-module-with-compiler-errors -I %t/mods %t/uses.swift 2>&1 | %FileCheck -check-prefix=CHECK-USES %s
12+
13+
// BEGIN errors.swift
14+
typealias AnAlias = undefined // expected-error {{cannot find type 'undefined'}}
15+
16+
// BEGIN uses.swift
17+
import errors
18+
func test(a: AnAlias) {}
19+
// CHECK-USES-NOT: cannot find type 'AnAlias' in scope

0 commit comments

Comments
 (0)