@@ -682,7 +682,7 @@ ConstraintSystem::SolverState::~SolverState() {
682682 // Update the "largest" statistics if this system is larger than the
683683 // previous one.
684684 // FIXME: This is not at all thread-safe.
685- if (NumStatesExplored > LargestNumStatesExplored .getValue ()) {
685+ if (NumSolverScopes > LargestNumSolverScopes .getValue ()) {
686686 LargestSolutionAttemptNumber = SolutionAttempt-1 ;
687687 ++LargestSolutionAttemptNumber;
688688 #define CS_STATISTIC (Name, Description ) \
@@ -695,17 +695,17 @@ ConstraintSystem::SolverState::~SolverState() {
695695
696696ConstraintSystem::SolverScope::SolverScope (ConstraintSystem &cs)
697697 : cs(cs),
698- numTypeVariables (cs.TypeVariables.size()),
699- numTrailChanges (cs.solverState->Trail.size()),
698+ startTypeVariables (cs.TypeVariables.size()),
699+ startTrailSteps (cs.solverState->Trail.size()),
700700 scopeNumber(cs.solverState->beginScope ()),
701701 moved(0 ) {
702702 ASSERT (!cs.failedConstraint && " Unexpected failed constraint!" );
703703}
704704
705705ConstraintSystem::SolverScope::SolverScope (SolverScope &&other)
706706 : cs(other.cs),
707- numTypeVariables (other.numTypeVariables ),
708- numTrailChanges (other.numTrailChanges ),
707+ startTypeVariables (other.startTypeVariables ),
708+ startTrailSteps (other.startTrailSteps ),
709709 scopeNumber(other.scopeNumber),
710710 moved(0 ) {
711711 other.moved = 1 ;
@@ -720,7 +720,7 @@ ConstraintSystem::SolverScope::~SolverScope() {
720720 return ;
721721
722722 // Roll back introduced type variables.
723- truncate (cs.TypeVariables , numTypeVariables );
723+ truncate (cs.TypeVariables , startTypeVariables );
724724
725725 // Move any remaining active constraints into the inactive list.
726726 if (!cs.ActiveConstraints .empty ()) {
@@ -731,16 +731,43 @@ ConstraintSystem::SolverScope::~SolverScope() {
731731 cs.ActiveConstraints );
732732 }
733733
734+ uint64_t endTrailSteps = cs.solverState ->Trail .size ();
735+
734736 // Roll back changes to the constraint system.
735- cs.solverState ->Trail .undo (numTrailChanges );
737+ cs.solverState ->Trail .undo (startTrailSteps );
736738
737739 // Update statistics.
738- cs.solverState ->endScope (scopeNumber);
740+ cs.solverState ->endScope (scopeNumber,
741+ startTrailSteps,
742+ endTrailSteps);
739743
740744 // Clear out other "failed" state.
741745 cs.failedConstraint = nullptr ;
742746}
743747
748+ unsigned ConstraintSystem::SolverState::beginScope () {
749+ ++depth;
750+ maxDepth = std::max (maxDepth, depth);
751+
752+ CS.incrementScopeCounter ();
753+
754+ return NumSolverScopes++;
755+ }
756+
757+ // / Update statistics when a scope ends.
758+ void ConstraintSystem::SolverState::endScope (unsigned scopeNumber,
759+ uint64_t startTrailSteps,
760+ uint64_t endTrailSteps) {
761+ ASSERT (depth > 0 );
762+ --depth;
763+
764+ NumTrailSteps += (endTrailSteps - startTrailSteps);
765+
766+ unsigned countSolverScopes = NumSolverScopes - scopeNumber;
767+ if (countSolverScopes == 1 )
768+ CS.incrementLeafScopes ();
769+ }
770+
744771// / Solve the system of constraints.
745772// /
746773// / \param allowFreeTypeVariables How to bind free type variables in
@@ -1529,7 +1556,8 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
15291556 if (isDebugMode ()) {
15301557 auto &log = llvm::errs ();
15311558 log << " \n ---Solver statistics---\n " ;
1532- log << " Total number of scopes explored: " << solverState->NumStatesExplored << " \n " ;
1559+ log << " Total number of scopes explored: " << solverState->NumSolverScopes << " \n " ;
1560+ log << " Total number of trail steps: " << solverState->NumTrailSteps << " \n " ;
15331561 log << " Maximum depth reached while exploring solutions: " << solverState->maxDepth << " \n " ;
15341562 if (Timer) {
15351563 auto timeInMillis =
0 commit comments