Skip to content

Commit a72b0f3

Browse files
committed
[Stats] Add some tracers to Sema.
1 parent 9ce3dc4 commit a72b0f3

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "swift/AST/PrettyStackTrace.h"
3131
#include "swift/AST/SubstitutionMap.h"
3232
#include "swift/AST/TypeCheckerDebugConsumer.h"
33+
#include "swift/Basic/Statistic.h"
3334
#include "swift/Parse/Confusables.h"
3435
#include "swift/Parse/Lexer.h"
3536
#include "llvm/ADT/APInt.h"
@@ -1949,6 +1950,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
19491950
TypeCheckExprOptions options,
19501951
ExprTypeCheckListener *listener,
19511952
ConstraintSystem *baseCS) {
1953+
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr", expr);
19521954
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
19531955

19541956
// First, pre-check the expression, validating any types that occur in the
@@ -2077,6 +2079,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
20772079
ConcreteDeclRef &referencedDecl,
20782080
FreeTypeVariableBinding allowFreeTypeVariables,
20792081
ExprTypeCheckListener *listener) {
2082+
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr-no-apply", expr);
20802083
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
20812084
referencedDecl = nullptr;
20822085

@@ -2158,6 +2161,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
21582161
Expr *&expr, DeclContext *dc, SmallPtrSetImpl<TypeBase *> &types,
21592162
FreeTypeVariableBinding allowFreeTypeVariables,
21602163
ExprTypeCheckListener *listener) {
2164+
FrontendStatsTracer StatsTracer(Context.Stats, "get-possible-types-no-apply", expr);
21612165
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
21622166

21632167
// Construct a constraint system from this expression.
@@ -2185,6 +2189,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
21852189
}
21862190

21872191
bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
2192+
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-completion-seq", expr);
21882193
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
21892194

21902195
// Construct a constraint system from this expression.
@@ -2261,6 +2266,7 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
22612266
}
22622267

22632268
bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
2269+
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr-shallow", expr);
22642270
PrettyStackTraceExpr stackTrace(Context, "shallow type-checking", expr);
22652271

22662272
// Construct a constraint system from this expression.
@@ -2793,6 +2799,7 @@ bool TypeChecker::typeCheckStmtCondition(StmtCondition &cond, DeclContext *dc,
27932799
/// value of a given type.
27942800
bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
27952801
Type rhsType) {
2802+
FrontendStatsTracer StatsTracer(Context.Stats, "typecheck-expr-pattern", EP);
27962803
PrettyStackTracePattern stackTrace(Context, "type-checking", EP);
27972804

27982805
// Create a 'let' binding to stand in for the RHS value.

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
37463746
}
37473747

37483748
PrettyStackTraceDecl StackTrace("validating", D);
3749+
FrontendStatsTracer StatsTracer(Context.Stats, "validate-decl", D);
37493750

37503751
if (hasEnabledForbiddenTypecheckPrefix())
37513752
checkForForbiddenPrefix(D);
@@ -5588,6 +5589,7 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
55885589
}
55895590

55905591
void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
5592+
FrontendStatsTracer StatsTracer(Context.Stats, "define-default-ctor", decl);
55915593
PrettyStackTraceDecl stackTrace("defining default constructor for",
55925594
decl);
55935595

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
386386

387387
template<typename StmtTy>
388388
bool typeCheckStmt(StmtTy *&S) {
389+
FrontendStatsTracer StatsTracer(TC.Context.Stats, "typecheck-stmt", S);
389390
PrettyStackTraceStmt trace(TC.Context, "type-checking", S);
390391
StmtTy *S2 = cast_or_null<StmtTy>(visit(S));
391392
if (S2 == nullptr)

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,7 @@ namespace {
16941694

16951695
Type TypeResolution::resolveType(TypeRepr *TyR,
16961696
TypeResolutionOptions options) {
1697+
FrontendStatsTracer StatsTracer(getASTContext().Stats, "resolve-type", TyR);
16971698
PrettyStackTraceTypeRepr stackTrace(getASTContext(), "resolving", TyR);
16981699

16991700
TypeResolver typeResolver(*this);

test/Misc/stats_dir_profiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %FileCheck -check-prefix=ENTITIES -input-file %t/stats-entities/*.dir/Time.User.entities %s
88

99
// EVENTS: {{perform-sema;.*;typecheck-decl [0-9]+}}
10-
// ENTITIES: {{perform-sema;.*;typecheck-fn bar\(\);typecheck-decl <pattern binding> [0-9]+}}
10+
// ENTITIES: {{perform-sema;.*;typecheck-fn bar\(\);typecheck-stmt Brace;typecheck-decl <pattern binding> [0-9]+}}
1111

1212
public func foo() {
1313
print("hello")

test/Misc/stats_dir_tracer.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// RUN: %target-swiftc_driver -o %t/main -module-name main -stats-output-dir %t %s -trace-stats-events
33
// RUN: %FileCheck -input-file %t/*.csv %s
44

5-
// CHECK: {{[0-9]+,[0-9]+,"exit","lookup-direct","Sema.NominalTypeLookupDirectCount",[0-9]+,[0-9]+,"Proto","\[.*stats_dir_tracer.swift:13:1 - line:15:1\]"}}
6-
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-fn","Sema.NumTypesDeserialized",[0-9]+,[0-9]+,"foo\(\)","\[.*stats_dir_tracer.swift:9:8 - line:11:1\]"}}
7-
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-decl","Sema.NumConstraintScopes",[0-9]+,[0-9]+,"<pattern binding>","\[.*stats_dir_tracer.swift:23:5 - line:23:13\]"}}
5+
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-expr","Sema.NumTypesDeserialized",[0-9]+,[0-9]+,"Call","\[.*stats_dir_tracer.swift:9:5 - line:9:18\]"}}
6+
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-expr","Sema.NumConstraintScopes",[0-9]+,[0-9]+,"IntegerLiteral","\[.*stats_dir_tracer.swift:22:13 - line:22:13\]"}}
87

98
public func foo() {
109
print("hello")

0 commit comments

Comments
 (0)