-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Stats tracer timer work #14695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stats tracer timer work #14695
Changes from all commits
db28140
5f12ffc
c9513a4
712da1f
a8bb856
fd5597f
67baa65
ea2e87f
1c923dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "swift/AST/Substitution.h" | ||
#include "swift/AST/Types.h" | ||
#include "swift/AST/TypeWalker.h" | ||
#include "swift/Basic/Statistic.h" | ||
#include "swift/ClangImporter/ClangModule.h" | ||
#include "llvm/ADT/MapVector.h" | ||
#include "llvm/ADT/Statistic.h" | ||
|
@@ -1367,3 +1368,46 @@ ProtocolConformanceRef::getCanonicalConformanceRef() const { | |
return *this; | ||
return ProtocolConformanceRef(getConcrete()->getCanonicalConformance()); | ||
} | ||
|
||
// See swift/Basic/Statistic.h for declaration: this enables tracing | ||
// ProtocolConformances, is defined here to avoid too much layering violation / | ||
// circular linkage dependency. | ||
|
||
struct ProtocolConformanceTraceFormatter | ||
: public UnifiedStatsReporter::TraceFormatter { | ||
void traceName(const void *Entity, raw_ostream &OS) const { | ||
if (!Entity) | ||
return; | ||
const ProtocolConformance *C = | ||
static_cast<const ProtocolConformance *>(Entity); | ||
OS << "<conformance "; | ||
if (auto const *DC = C->getDeclContext()) { | ||
if (auto const *N = DC->getAsNominalTypeOrNominalTypeExtensionContext()) { | ||
N->getFullName().print(OS, false); | ||
} | ||
} | ||
OS << " : "; | ||
if (auto *P = C->getProtocol()) | ||
P->getFullName().print(OS, false); | ||
OS << ">"; | ||
} | ||
void traceLoc(const void *Entity, SourceManager *SM, | ||
clang::SourceManager *CSM, raw_ostream &OS) const { | ||
if (!Entity) | ||
return; | ||
const ProtocolConformance *C = | ||
static_cast<const ProtocolConformance *>(Entity); | ||
if (auto const *DC = C->getDeclContext()) { | ||
if (auto const *D = DC->getAsDeclOrDeclExtensionContext()) | ||
D->getSourceRange().print(OS, *SM, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you want the range here, just the location. (Arguably if you have a NormalProtocolConformance you could get an even better location, which is where the conformance is written. But not all conformances are NormalProtocolConformances.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I know the method is named traceLoc but so far I've been actually tracing all of the ranges. Maybe I should rename it? Or maybe ranges are overkill? (Will use the normalProtocolConformance decl site when available, in any case) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might be reasonable for some of the other things, but for conformances you'll end up using the entire range of the extension or decl that declares conformance, or maybe just the class that inherits from a conforming decl. That doesn't seem useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok (I think I initially went with ranges because of exprs, but shrug it's pretty much just a hint for the reader anyway). |
||
} | ||
} | ||
}; | ||
|
||
static ProtocolConformanceTraceFormatter TF; | ||
|
||
template<> | ||
const UnifiedStatsReporter::TraceFormatter* | ||
FrontendStatsTracer::getTraceFormatter<const ProtocolConformance *>() { | ||
return &TF; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conformances already have a
printName
method that probably covers this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fixed.