Skip to content

Commit 822e1a9

Browse files
committed
[NFC] Add some pretty stack traces
These would have helped us to debug rdar://142693093 more quickly.
1 parent 4cc5def commit 822e1a9

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

include/swift/SIL/PrettyStackTrace.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "swift/SIL/SILLocation.h"
2222
#include "swift/SIL/SILNode.h"
23+
#include "swift/SIL/SILDeclRef.h"
2324
#include "llvm/ADT/SmallString.h"
2425
#include "llvm/ADT/Twine.h"
2526
#include "llvm/Support/PrettyStackTrace.h"
@@ -82,6 +83,18 @@ class PrettyStackTraceSILNode : public llvm::PrettyStackTraceEntry {
8283
virtual void print(llvm::raw_ostream &OS) const override;
8384
};
8485

86+
/// Observe that we are processing a reference to a SIL decl.
87+
class PrettyStackTraceSILDeclRef : public llvm::PrettyStackTraceEntry {
88+
SILDeclRef declRef;
89+
StringRef action;
90+
91+
public:
92+
PrettyStackTraceSILDeclRef(const char *action, SILDeclRef declRef)
93+
: declRef(declRef), action(action) {}
94+
95+
virtual void print(llvm::raw_ostream &os) const override;
96+
};
97+
8598
} // end namespace swift
8699

87100
#endif

lib/IRGen/GenCall.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/ASTContext.h"
2121
#include "swift/AST/ClangModuleLoader.h"
2222
#include "swift/AST/GenericEnvironment.h"
23+
#include "swift/AST/PrettyStackTrace.h"
2324
#include "swift/Basic/Assertions.h"
2425
#include "swift/IRGen/Linking.h"
2526
#include "swift/Runtime/Config.h"
@@ -1473,6 +1474,8 @@ static bool doesClangExpansionMatchSchema(IRGenModule &IGM,
14731474
/// Expand the result and parameter types to the appropriate LLVM IR
14741475
/// types for C, C++ and Objective-C signatures.
14751476
void SignatureExpansion::expandExternalSignatureTypes() {
1477+
PrettyStackTraceType entry(IGM.Context, "using clang to expand signature for",
1478+
FnType);
14761479
assert(FnType->getLanguage() == SILFunctionLanguage::C);
14771480

14781481
auto SILResultTy = [&]() {

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "swift/IRGen/Linking.h"
3535
#include "swift/Runtime/HeapObject.h"
3636
#include "swift/SIL/FormalLinkage.h"
37+
#include "swift/SIL/PrettyStackTrace.h"
3738
#include "swift/SIL/SILDebugScope.h"
3839
#include "swift/SIL/SILModule.h"
3940
#include "swift/Subsystems.h"
@@ -3512,6 +3513,7 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
35123513
assert(forDefinition || !isDynamicallyReplaceableImplementation);
35133514
assert(!forDefinition || !shouldCallPreviousImplementation);
35143515

3516+
PrettyStackTraceSILFunction entry("lowering address of", f);
35153517
LinkEntity entity =
35163518
LinkEntity::forSILFunction(f, shouldCallPreviousImplementation);
35173519

lib/IRGen/GenObjC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "swift/ClangImporter/ClangImporter.h"
3434
#include "swift/Demangling/ManglingMacros.h"
3535
#include "swift/IRGen/Linking.h"
36+
#include "swift/SIL/PrettyStackTrace.h"
3637
#include "swift/SIL/SILModule.h"
3738
#include "clang/AST/Attr.h"
3839
#include "clang/AST/DeclObjC.h"
@@ -779,6 +780,8 @@ Callee irgen::getObjCMethodCallee(IRGenFunction &IGF,
779780
llvm::Value *selfValue,
780781
CalleeInfo &&info) {
781782
SILDeclRef method = methodInfo.getMethod();
783+
PrettyStackTraceSILDeclRef entry("lowering reference to ObjC method", method);
784+
782785
// Note that isolated deallocator is never called directly, only from regular
783786
// deallocator
784787
assert((method.kind == SILDeclRef::Kind::Initializer

lib/IRGen/IRGenSIL.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,8 @@ static bool mayDirectlyCallAsync(SILFunction *fn) {
31183118

31193119
void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
31203120
auto fn = i->getInitiallyReferencedFunction();
3121+
PrettyStackTraceSILFunction entry("lowering reference to", fn);
3122+
31213123
auto fnType = fn->getLoweredFunctionType();
31223124

31233125
auto fpKind = irgen::classifyFunctionPointerKind(fn);
@@ -8101,6 +8103,8 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
81018103
CanType baseTy = i->getLookupType();
81028104
ProtocolConformanceRef conformance = i->getConformance();
81038105
SILDeclRef member = i->getMember();
8106+
PrettyStackTraceSILDeclRef entry("lowering use of witness method", member);
8107+
81048108
auto fnType = IGM.getSILTypes().getConstantFunctionType(
81058109
IGM.getMaximalTypeExpansionContext(), member);
81068110

@@ -8285,6 +8289,7 @@ void IRGenSILFunction::visitSuperMethodInst(swift::SuperMethodInst *i) {
82858289
llvm::Value *baseValue = base.claimNext();
82868290

82878291
auto method = i->getMember().getOverriddenVTableEntry();
8292+
PrettyStackTraceSILDeclRef entry("lowering super call to", method);
82888293
auto methodType = i->getType().castTo<SILFunctionType>();
82898294

82908295
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
@@ -8381,6 +8386,8 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
83818386
llvm::Value *baseValue = base.claimNext();
83828387

83838388
SILDeclRef method = i->getMember().getOverriddenVTableEntry();
8389+
PrettyStackTraceSILDeclRef entry("lowering class method call to", method);
8390+
83848391
auto methodType = i->getType().castTo<SILFunctionType>();
83858392

83868393
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());

lib/SIL/Utils/PrettyStackTrace.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ void PrettyStackTraceSILNode::print(llvm::raw_ostream &out) const {
104104
if (Node)
105105
out << *Node;
106106
}
107+
108+
void PrettyStackTraceSILDeclRef::print(llvm::raw_ostream &out) const {
109+
out << "While " << action << " SIL decl '";
110+
declRef.print(out);
111+
out << "'\n";
112+
}

0 commit comments

Comments
 (0)