Skip to content

Commit e250539

Browse files
committed
Adopt abortWithPrettyStackTraceMessage throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling `abort` over to using `abortWithPrettyStackTraceMessage` such that the message gets printed to the pretty stack trace. This ensures it gets picked up by CrashReporter.
1 parent 7f8bcea commit e250539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+781
-651
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/GenericEnvironment.h"
2222
#include "swift/AST/LocalArchetypeRequirementCollector.h"
2323
#include "swift/AST/ProtocolConformance.h"
24+
#include "swift/Basic/PrettyStackTrace.h"
2425
#include "swift/SIL/BasicBlockUtils.h"
2526
#include "swift/SIL/DebugUtils.h"
2627
#include "swift/SIL/Dominance.h"
@@ -557,11 +558,12 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
557558
}
558559

559560
if (substConf.isInvalid()) {
560-
llvm::errs() << "Invalid substituted conformance in SIL cloner:\n";
561-
Functor.dump(llvm::errs());
562-
llvm::errs() << "\noriginal conformance:\n";
563-
conformance.dump(llvm::errs());
564-
abort();
561+
abortWithPrettyStackTraceMessage([&](auto &out) {
562+
out << "Invalid substituted conformance in SIL cloner:\n";
563+
Functor.dump(out);
564+
out << "\noriginal conformance:\n";
565+
conformance.dump(out);
566+
});
565567
}
566568

567569
if (asImpl().shouldSubstOpaqueArchetypes()) {

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "swift/Basic/Assertions.h"
6464
#include "swift/Basic/BlockList.h"
6565
#include "swift/Basic/Compiler.h"
66+
#include "swift/Basic/PrettyStackTrace.h"
6667
#include "swift/Basic/SourceManager.h"
6768
#include "swift/Basic/Statistic.h"
6869
#include "swift/Basic/StringExtras.h"
@@ -5819,9 +5820,10 @@ ProtocolConformanceRef ProtocolConformanceRef::forAbstract(
58195820
break;
58205821

58215822
default:
5822-
llvm::errs() << "Abstract conformance with bad subject type:\n";
5823-
conformingType->dump(llvm::errs());
5824-
abort();
5823+
abortWithPrettyStackTraceMessage([&](auto &out) {
5824+
out << "Abstract conformance with bad subject type:\n";
5825+
conformingType->dump(out);
5826+
});
58255827
}
58265828

58275829
// Figure out which arena this should go in.

lib/AST/ASTMangler.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "swift/AST/TypeCheckRequests.h"
4040
#include "swift/Basic/Assertions.h"
4141
#include "swift/Basic/Defer.h"
42+
#include "swift/Basic/PrettyStackTrace.h"
4243
#include "swift/Basic/SourceManager.h"
4344
#include "swift/ClangImporter/ClangImporter.h"
4445
#include "swift/ClangImporter/ClangModule.h"
@@ -1446,8 +1447,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
14461447
case TypeKind::BuiltinUnsafeValueBuffer:
14471448
return appendOperator("BB");
14481449
case TypeKind::BuiltinUnboundGeneric:
1449-
llvm::errs() << "Don't know how to mangle a BuiltinUnboundGenericType\n";
1450-
abort();
1450+
abortWithPrettyStackTraceMessage(
1451+
"Don't know how to mangle a BuiltinUnboundGenericType");
14511452
case TypeKind::Locatable: {
14521453
auto loc = cast<LocatableType>(tybase);
14531454
return appendType(loc->getSinglyDesugaredType(), sig, forDecl);
@@ -1756,9 +1757,10 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
17561757
case TypeKind::PackArchetype:
17571758
case TypeKind::ElementArchetype:
17581759
case TypeKind::ExistentialArchetype:
1759-
llvm::errs() << "Cannot mangle free-standing archetype: ";
1760-
tybase->dump(llvm::errs());
1761-
abort();
1760+
abortWithPrettyStackTraceMessage([&](auto &out) {
1761+
out << "Cannot mangle free-standing archetype: ";
1762+
tybase->dump(out);
1763+
});
17621764

17631765
case TypeKind::OpaqueTypeArchetype: {
17641766
auto opaqueType = cast<OpaqueTypeArchetypeType>(tybase);
@@ -4468,8 +4470,8 @@ static unsigned conformanceRequirementIndex(
44684470
++result;
44694471
}
44704472

4471-
llvm::errs() <<"Conformance access path step is missing from requirements";
4472-
abort();
4473+
abortWithPrettyStackTraceMessage(
4474+
"Conformance access path step is missing from requirements");
44734475
}
44744476

44754477
void ASTMangler::appendDependentProtocolConformance(
@@ -4573,9 +4575,10 @@ void ASTMangler::appendAnyProtocolConformance(
45734575
} else if (conformance.isPack()) {
45744576
appendPackProtocolConformance(conformance.getPack(), genericSig);
45754577
} else {
4576-
llvm::errs() << "Bad conformance in mangler: ";
4577-
conformance.dump(llvm::errs());
4578-
abort();
4578+
abortWithPrettyStackTraceMessage([&](auto &out) {
4579+
out << "Bad conformance in mangler: ";
4580+
conformance.dump(out);
4581+
});
45794582
}
45804583
}
45814584

lib/AST/AvailabilityScope.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/Stmt.h"
2727
#include "swift/AST/TypeCheckRequests.h"
2828
#include "swift/Basic/Assertions.h"
29+
#include "swift/Basic/PrettyStackTrace.h"
2930
#include "swift/Basic/SourceManager.h"
3031

3132
using namespace swift;
@@ -519,15 +520,16 @@ static void verificationError(
519520
ASTContext &ctx, llvm::StringRef msg,
520521
std::initializer_list<std::pair<const char *, const AvailabilityScope *>>
521522
labelsAndNodes) {
522-
llvm::errs() << msg << "\n";
523-
for (auto pair : labelsAndNodes) {
524-
auto label = std::get<0>(pair);
525-
auto scope = std::get<1>(pair);
526-
llvm::errs() << label << ":\n";
527-
scope->print(llvm::errs(), ctx.SourceMgr);
528-
llvm::errs() << "\n";
529-
}
530-
abort();
523+
abortWithPrettyStackTraceMessage([&](auto &out) {
524+
out << msg << "\n";
525+
for (auto pair : labelsAndNodes) {
526+
auto label = std::get<0>(pair);
527+
auto scope = std::get<1>(pair);
528+
out << label << ":\n";
529+
scope->print(out, ctx.SourceMgr);
530+
out << "\n";
531+
}
532+
});
531533
}
532534

533535
void AvailabilityScope::verify(const AvailabilityScope *parent,

lib/AST/Bridging/MiscBridging.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/Stmt.h"
2020
#include "swift/AST/TypeRepr.h"
2121
#include "swift/Basic/Assertions.h"
22+
#include "swift/Basic/PrettyStackTrace.h"
2223

2324
#ifdef PURE_BRIDGING_MODE
2425
// In PURE_BRIDGING_MODE, bridging functions are not inlined and therefore
@@ -64,8 +65,9 @@ static SwiftMetatype declMetatypes[(unsigned)DeclKind::Last_Decl + 1];
6465
SwiftMetatype Decl::getDeclMetatype(DeclKind kind) {
6566
SwiftMetatype metatype = declMetatypes[(unsigned)kind];
6667
if (declMetatypesInitialized && !metatype) {
67-
llvm::errs() << "Decl " << getKindName(kind) << " not registered\n";
68-
abort();
68+
abortWithPrettyStackTraceMessage([&](auto &out) {
69+
out << "Decl " << getKindName(kind) << " not registered";
70+
});
6971
}
7072
return metatype;
7173
}
@@ -83,9 +85,9 @@ void registerBridgedDecl(BridgedStringRef bridgedClassName,
8385
.Default(std::nullopt);
8486

8587
if (!declKind) {
86-
llvm::errs() << "Unknown Decl class " << bridgedClassName.unbridged()
87-
<< "\n";
88-
abort();
88+
abortWithPrettyStackTraceMessage([&](auto &out) {
89+
out << "Unknown Decl class " << bridgedClassName.unbridged();
90+
});
8991
}
9092
declMetatypes[(unsigned)declKind.value()] = metatype;
9193
}

lib/AST/Expr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "swift/AST/Expr.h"
1818
#include "swift/Basic/Assertions.h"
19+
#include "swift/Basic/PrettyStackTrace.h"
1920
#include "swift/Basic/Statistic.h"
2021
#include "swift/Basic/Unicode.h"
2122
#include "swift/Basic/SourceManager.h"
@@ -1994,9 +1995,10 @@ unsigned AbstractClosureExpr::getDiscriminator() const {
19941995
}
19951996

19961997
if (getRawDiscriminator() == InvalidDiscriminator) {
1997-
llvm::errs() << "Closure does not have an assigned discriminator:\n";
1998-
dump(llvm::errs());
1999-
abort();
1998+
abortWithPrettyStackTraceMessage([&](auto &out) {
1999+
out << "Closure does not have an assigned discriminator:\n";
2000+
this->dump(out);
2001+
});
20002002
}
20012003

20022004
return getRawDiscriminator();

0 commit comments

Comments
 (0)