Skip to content

Commit 656952a

Browse files
committed
[ConstraintSystem] Add a way to get the elapsed time we've spent in a SolverScope.
1 parent 31f2617 commit 656952a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
483483
numDefaultedConstraints = cs.DefaultedConstraints.size();
484484
numCheckedConformances = cs.CheckedConformances.size();
485485
PreviousScore = cs.CurrentScore;
486+
if (cs.Timer) {
487+
startTime = cs.Timer->getElapsedProcessTimeInFractionalSeconds();
488+
}
486489

487490
cs.solverState->registerScope(this);
488491
assert(!cs.failedConstraint && "Unexpected failed constraint!");

lib/Sema/ConstraintSystem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,9 @@ class ConstraintSystem {
14451445
/// The previous score.
14461446
Score PreviousScore;
14471447

1448+
/// Time in fractional seconds at which we entered this scope.
1449+
double startTime;
1450+
14481451
/// Constraint graph scope associated with this solver scope.
14491452
ConstraintGraphScope CGScope;
14501453

@@ -1456,6 +1459,13 @@ class ConstraintSystem {
14561459
public:
14571460
explicit SolverScope(ConstraintSystem &cs);
14581461
~SolverScope();
1462+
1463+
Optional<double> getElapsedTimeInFractionalSeconds() {
1464+
if (!cs.Timer)
1465+
return None;
1466+
1467+
return cs.Timer->getElapsedProcessTimeInFractionalSeconds() - startTime;
1468+
}
14591469
};
14601470

14611471
ConstraintSystem(TypeChecker &tc, DeclContext *dc,

0 commit comments

Comments
 (0)