diff --git a/include/swift/AST/PrettyStackTrace.h b/include/swift/AST/PrettyStackTrace.h index 8b1cc80cbf431..0baaa28354cca 100644 --- a/include/swift/AST/PrettyStackTrace.h +++ b/include/swift/AST/PrettyStackTrace.h @@ -69,6 +69,19 @@ class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { virtual void print(llvm::raw_ostream &OS) const override; }; +/// PrettyStackTraceDecl - Observe that we are processing a specific +/// declaration with a given substitution map. +class PrettyStackTraceDeclAndSubst : public llvm::PrettyStackTraceEntry { + const Decl *decl; + SubstitutionMap subst; + const char *action; +public: + PrettyStackTraceDeclAndSubst(const char *action, SubstitutionMap subst, + const Decl *decl) + : decl(decl), subst(subst), action(action) {} + virtual void print(llvm::raw_ostream &OS) const override; +}; + /// PrettyStackTraceAnyFunctionRef - Observe that we are processing a specific /// function or closure literal. class PrettyStackTraceAnyFunctionRef : public llvm::PrettyStackTraceEntry { diff --git a/lib/AST/PrettyStackTrace.cpp b/lib/AST/PrettyStackTrace.cpp index 71663b08cbc98..c4ccc40fe5692 100644 --- a/lib/AST/PrettyStackTrace.cpp +++ b/lib/AST/PrettyStackTrace.cpp @@ -42,6 +42,19 @@ void PrettyStackTraceDecl::print(llvm::raw_ostream &out) const { printDeclDescription(out, TheDecl, TheDecl->getASTContext()); } +void PrettyStackTraceDeclAndSubst::print(llvm::raw_ostream &out) const { + out << "While " << action << ' '; + if (!decl) { + out << "NULL declaration!\n"; + return; + } + printDeclDescription(out, decl, decl->getASTContext()); + + out << "with substitution map: "; + subst.dump(out); +} + + void swift::printDeclDescription(llvm::raw_ostream &out, const Decl *D, const ASTContext &Context, bool addNewline) { SourceLoc loc = D->getStartLoc(); diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 5b380b9bb8ab9..1c71dfa914304 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -29,6 +29,7 @@ #include "swift/AST/Module.h" #include "swift/AST/NameLookup.h" #include "swift/AST/NameLookupRequests.h" +#include "swift/AST/PrettyStackTrace.h" #include "swift/AST/Types.h" #include "swift/Basic/Defer.h" #include "swift/Basic/Platform.h" @@ -5582,6 +5583,8 @@ static ValueDecl *generateThunkForExtraMetatypes(SubstitutionMap subst, ConcreteDeclRef ClangImporter::getCXXFunctionTemplateSpecialization(SubstitutionMap subst, ValueDecl *decl) { + PrettyStackTraceDeclAndSubst trace("specializing", subst, decl); + assert(isa(decl->getClangDecl()) && "This API should only be used with function templates."); diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 66f79cf208f27..3b095bb27f57f 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -28,6 +28,7 @@ #include "swift/AST/Module.h" #include "swift/AST/NameLookup.h" #include "swift/AST/ParameterList.h" +#include "swift/AST/PrettyStackTrace.h" #include "swift/AST/Type.h" #include "swift/AST/Types.h" #include "swift/AST/TypeVisitor.h" @@ -211,6 +212,10 @@ namespace { using TypeVisitor::Visit; ImportResult Visit(clang::QualType type) { + PrettyStackTraceClangType trace(Impl.getClangASTContext(), + "importing a clang type", + type.getTypePtr()); + auto IR = Visit(type.getTypePtr()); return IR; }