Skip to content

Commit 422c87a

Browse files
authored
Merge pull request #41876 from zoecarver/add-pretty-prints
2 parents f4d2b0d + 13e64f3 commit 422c87a

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

include/swift/AST/PrettyStackTrace.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
6969
virtual void print(llvm::raw_ostream &OS) const override;
7070
};
7171

72+
/// PrettyStackTraceDecl - Observe that we are processing a specific
73+
/// declaration with a given substitution map.
74+
class PrettyStackTraceDeclAndSubst : public llvm::PrettyStackTraceEntry {
75+
const Decl *decl;
76+
SubstitutionMap subst;
77+
const char *action;
78+
public:
79+
PrettyStackTraceDeclAndSubst(const char *action, SubstitutionMap subst,
80+
const Decl *decl)
81+
: decl(decl), subst(subst), action(action) {}
82+
virtual void print(llvm::raw_ostream &OS) const override;
83+
};
84+
7285
/// PrettyStackTraceAnyFunctionRef - Observe that we are processing a specific
7386
/// function or closure literal.
7487
class PrettyStackTraceAnyFunctionRef : public llvm::PrettyStackTraceEntry {

lib/AST/PrettyStackTrace.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ void PrettyStackTraceDecl::print(llvm::raw_ostream &out) const {
4242
printDeclDescription(out, TheDecl, TheDecl->getASTContext());
4343
}
4444

45+
void PrettyStackTraceDeclAndSubst::print(llvm::raw_ostream &out) const {
46+
out << "While " << action << ' ';
47+
if (!decl) {
48+
out << "NULL declaration!\n";
49+
return;
50+
}
51+
printDeclDescription(out, decl, decl->getASTContext());
52+
53+
out << "with substitution map: ";
54+
subst.dump(out);
55+
}
56+
57+
4558
void swift::printDeclDescription(llvm::raw_ostream &out, const Decl *D,
4659
const ASTContext &Context, bool addNewline) {
4760
SourceLoc loc = D->getStartLoc();

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/Module.h"
3030
#include "swift/AST/NameLookup.h"
3131
#include "swift/AST/NameLookupRequests.h"
32+
#include "swift/AST/PrettyStackTrace.h"
3233
#include "swift/AST/Types.h"
3334
#include "swift/Basic/Defer.h"
3435
#include "swift/Basic/Platform.h"
@@ -5582,6 +5583,8 @@ static ValueDecl *generateThunkForExtraMetatypes(SubstitutionMap subst,
55825583
ConcreteDeclRef
55835584
ClangImporter::getCXXFunctionTemplateSpecialization(SubstitutionMap subst,
55845585
ValueDecl *decl) {
5586+
PrettyStackTraceDeclAndSubst trace("specializing", subst, decl);
5587+
55855588
assert(isa<clang::FunctionTemplateDecl>(decl->getClangDecl()) &&
55865589
"This API should only be used with function templates.");
55875590

lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "swift/AST/Module.h"
2929
#include "swift/AST/NameLookup.h"
3030
#include "swift/AST/ParameterList.h"
31+
#include "swift/AST/PrettyStackTrace.h"
3132
#include "swift/AST/Type.h"
3233
#include "swift/AST/Types.h"
3334
#include "swift/AST/TypeVisitor.h"
@@ -211,6 +212,10 @@ namespace {
211212

212213
using TypeVisitor::Visit;
213214
ImportResult Visit(clang::QualType type) {
215+
PrettyStackTraceClangType trace(Impl.getClangASTContext(),
216+
"importing a clang type",
217+
type.getTypePtr());
218+
214219
auto IR = Visit(type.getTypePtr());
215220
return IR;
216221
}

0 commit comments

Comments
 (0)