Skip to content

Commit ac9a3bf

Browse files
committed
Sema: Add counters for synthesized accessors
1 parent 3d6c5d8 commit ac9a3bf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/swift/Basic/Statistics.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ FRONTEND_STATISTIC(Sema, NumDeclsTypechecked)
179179
/// Number of declarations finalized.
180180
FRONTEND_STATISTIC(Sema, NumDeclsFinalized)
181181

182+
/// Number of synthesized accessors.
183+
FRONTEND_STATISTIC(Sema, NumAccessorsSynthesized)
184+
185+
/// Number of synthesized accessor bodies.
186+
FRONTEND_STATISTIC(Sema, NumAccessorBodiesSynthesized)
187+
182188
/// Number of full function bodies typechecked.
183189
FRONTEND_STATISTIC(Sema, NumFunctionsTypechecked)
184190

lib/Sema/CodeSynthesis.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
234234
// Always add the getter to the context immediately after the storage.
235235
addMemberToContextIfNeeded(getter, storage->getDeclContext(), storage);
236236

237+
if (ctx.Stats)
238+
ctx.Stats->getFrontendCounters().NumAccessorsSynthesized++;
239+
237240
return getter;
238241
}
239242

@@ -285,6 +288,9 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,
285288
assert(getter && "always synthesize setter prototype after get/read");
286289
addMemberToContextIfNeeded(setter, storage->getDeclContext(), getter);
287290

291+
if (ctx.Stats)
292+
ctx.Stats->getFrontendCounters().NumAccessorsSynthesized++;
293+
288294
return setter;
289295
}
290296

@@ -483,6 +489,9 @@ createCoroutineAccessorPrototype(AbstractStorageDecl *storage,
483489

484490
addMemberToContextIfNeeded(accessor, dc, afterDecl);
485491

492+
if (ctx.Stats)
493+
ctx.Stats->getFrontendCounters().NumAccessorsSynthesized++;
494+
486495
return accessor;
487496
}
488497

@@ -2275,6 +2284,9 @@ synthesizeAccessorBody(AbstractFunctionDecl *fn, void *) {
22752284
auto *accessor = cast<AccessorDecl>(fn);
22762285
auto &ctx = accessor->getASTContext();
22772286

2287+
if (ctx.Stats)
2288+
ctx.Stats->getFrontendCounters().NumAccessorBodiesSynthesized++;
2289+
22782290
if (accessor->isInvalid() || ctx.hadError())
22792291
return { nullptr, true };
22802292

0 commit comments

Comments
 (0)