@@ -682,7 +682,7 @@ ConstraintSystem::SolverState::~SolverState() {
682
682
// Update the "largest" statistics if this system is larger than the
683
683
// previous one.
684
684
// FIXME: This is not at all thread-safe.
685
- if (NumStatesExplored > LargestNumStatesExplored .getValue ()) {
685
+ if (NumSolverScopes > LargestNumSolverScopes .getValue ()) {
686
686
LargestSolutionAttemptNumber = SolutionAttempt-1 ;
687
687
++LargestSolutionAttemptNumber;
688
688
#define CS_STATISTIC (Name, Description ) \
@@ -695,17 +695,17 @@ ConstraintSystem::SolverState::~SolverState() {
695
695
696
696
ConstraintSystem::SolverScope::SolverScope (ConstraintSystem &cs)
697
697
: cs(cs),
698
- numTypeVariables (cs.TypeVariables.size()),
699
- numTrailChanges (cs.solverState->Trail.size()),
698
+ startTypeVariables (cs.TypeVariables.size()),
699
+ startTrailSteps (cs.solverState->Trail.size()),
700
700
scopeNumber(cs.solverState->beginScope ()),
701
701
moved(0 ) {
702
702
ASSERT (!cs.failedConstraint && " Unexpected failed constraint!" );
703
703
}
704
704
705
705
ConstraintSystem::SolverScope::SolverScope (SolverScope &&other)
706
706
: cs(other.cs),
707
- numTypeVariables (other.numTypeVariables ),
708
- numTrailChanges (other.numTrailChanges ),
707
+ startTypeVariables (other.startTypeVariables ),
708
+ startTrailSteps (other.startTrailSteps ),
709
709
scopeNumber(other.scopeNumber),
710
710
moved(0 ) {
711
711
other.moved = 1 ;
@@ -720,7 +720,7 @@ ConstraintSystem::SolverScope::~SolverScope() {
720
720
return ;
721
721
722
722
// Roll back introduced type variables.
723
- truncate (cs.TypeVariables , numTypeVariables );
723
+ truncate (cs.TypeVariables , startTypeVariables );
724
724
725
725
// Move any remaining active constraints into the inactive list.
726
726
if (!cs.ActiveConstraints .empty ()) {
@@ -731,16 +731,43 @@ ConstraintSystem::SolverScope::~SolverScope() {
731
731
cs.ActiveConstraints );
732
732
}
733
733
734
+ uint64_t endTrailSteps = cs.solverState ->Trail .size ();
735
+
734
736
// Roll back changes to the constraint system.
735
- cs.solverState ->Trail .undo (numTrailChanges );
737
+ cs.solverState ->Trail .undo (startTrailSteps );
736
738
737
739
// Update statistics.
738
- cs.solverState ->endScope (scopeNumber);
740
+ cs.solverState ->endScope (scopeNumber,
741
+ startTrailSteps,
742
+ endTrailSteps);
739
743
740
744
// Clear out other "failed" state.
741
745
cs.failedConstraint = nullptr ;
742
746
}
743
747
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
+
744
771
// / Solve the system of constraints.
745
772
// /
746
773
// / \param allowFreeTypeVariables How to bind free type variables in
@@ -1529,7 +1556,8 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
1529
1556
if (isDebugMode ()) {
1530
1557
auto &log = llvm::errs ();
1531
1558
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 " ;
1533
1561
log << " Maximum depth reached while exploring solutions: " << solverState->maxDepth << " \n " ;
1534
1562
if (Timer) {
1535
1563
auto timeInMillis =
0 commit comments