Skip to content

Commit a1d585d

Browse files
authored
Merge pull request #86158 from slavapestov/cs-arena-bytes
Sema: Convert solver arena usage into an always-on statistic
2 parents 13ef2a0 + 9157d98 commit a1d585d

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

include/swift/Basic/Statistics.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ FRONTEND_STATISTIC(Sema, NumCrossImportsChecked)
187187
/// Number of pairs of modules we've actually found cross-imports for.
188188
FRONTEND_STATISTIC(Sema, NumCrossImportsFound)
189189

190+
/// Number of bytes allocated in the solver arena, summed across all
191+
/// constraint systems for all expressions.
192+
FRONTEND_STATISTIC(Sema, NumSolverBytesAllocated)
193+
194+
/// Number of bytes allocated in the solver arena, maximum across all
195+
/// constraint systems for all expressions.
196+
FRONTEND_STATISTIC(Sema, MaxSolverBytesAllocated)
197+
190198
/// Number of steps recorded in the trail while solving expression type
191199
/// constraints. A rough proxy for "how much work the expression
192200
/// type checker did".

include/swift/Sema/ConstraintSolverStats.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# error #define CS_STATISTIC(Name, Description) before including
1919
#endif
2020

21-
CS_STATISTIC(ASTBytesAllocated, "bytes allocated in solver arena")
2221
CS_STATISTIC(NumTypeVariablesBound, "# of type variables bound")
2322
CS_STATISTIC(NumTypeVariableBindings, "# of type variable bindings attempted")
2423
CS_STATISTIC(NumDisjunctions, "# of disjunctions explored")

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ class ConstraintSystem {
21962196

21972197
llvm::DenseMap<Expr *, std::pair<unsigned, Expr *>> ExprWeights;
21982198

2199-
/// Allocator used for all of the related constraint systems.
2199+
/// Allocator used for data that is local to this constraint system.
22002200
llvm::BumpPtrAllocator Allocator;
22012201

22022202
/// Arena used for memory management of constraint-checker-related

lib/Sema/CSSolver.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,27 @@ ConstraintSystem::SolverState::~SolverState() {
670670
CS.activateConstraint(constraint);
671671
}
672672

673+
auto &ctx = CS.getASTContext();
674+
673675
// If global constraint debugging is off and we are finished logging the
674676
// current solution attempt, switch debugging back off.
675-
const auto &tyOpts = CS.getASTContext().TypeCheckerOpts;
676-
if (!tyOpts.DebugConstraintSolver &&
677-
tyOpts.DebugConstraintSolverAttempt &&
678-
tyOpts.DebugConstraintSolverAttempt == SolutionAttempt) {
677+
if (!ctx.TypeCheckerOpts.DebugConstraintSolver &&
678+
ctx.TypeCheckerOpts.DebugConstraintSolverAttempt &&
679+
ctx.TypeCheckerOpts.DebugConstraintSolverAttempt == SolutionAttempt) {
679680
CS.Options -= ConstraintSystemFlags::DebugConstraints;
680681
}
681682

682683
// This statistic is special because it's not a counter; we just update
683684
// it in one shot at the end.
684-
ASTBytesAllocated = CS.getASTContext().getSolverMemory();
685+
if (ctx.Stats) {
686+
auto &counters = ctx.Stats->getFrontendCounters();
687+
int64_t bytes = CS.getAllocator().getBytesAllocated();
688+
counters.NumSolverBytesAllocated += bytes;
689+
counters.MaxSolverBytesAllocated =
690+
std::max(counters.MaxSolverBytesAllocated, bytes);
691+
}
685692

686-
// Write our local statistics back to the overall statistics.
693+
// Write our local debug statistics back to the overall debug statistics.
687694
#define CS_STATISTIC(Name, Description) JOIN2(Overall,Name) += Name;
688695
#include "swift/Sema/ConstraintSolverStats.def"
689696

0 commit comments

Comments
 (0)