2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -1144,19 +1144,6 @@ class ConstraintSystem {
1144
1144
#define CS_STATISTIC (Name, Description ) unsigned Name = 0 ;
1145
1145
#include " ConstraintSolverStats.def"
1146
1146
1147
- // / \brief Register given scope to be tracked by the current solver state,
1148
- // / this helps to make sure that all of the retired/generated constraints
1149
- // / are dealt with correctly when the life time of the scope ends.
1150
- // /
1151
- // / \param scope The scope to associate with current solver state.
1152
- void registerScope (SolverScope *scope) {
1153
- CS.incrementScopeCounter ();
1154
- auto scopeInfo =
1155
- std::make_tuple (scope, retiredConstraints.begin (),
1156
- generatedConstraints.size ());
1157
- scopes.push_back (scopeInfo);
1158
- }
1159
-
1160
1147
// / \brief Check whether there are any retired constraints present.
1161
1148
bool hasRetiredConstraints () const {
1162
1149
return !retiredConstraints.empty ();
@@ -1204,6 +1191,22 @@ class ConstraintSystem {
1204
1191
}
1205
1192
}
1206
1193
1194
+ // / \brief Register given scope to be tracked by the current solver state,
1195
+ // / this helps to make sure that all of the retired/generated constraints
1196
+ // / are dealt with correctly when the life time of the scope ends.
1197
+ // /
1198
+ // / \param scope The scope to associate with current solver state.
1199
+ void registerScope (SolverScope *scope) {
1200
+ ++depth;
1201
+ ++NumStatesExplored;
1202
+
1203
+ CS.incrementScopeCounter ();
1204
+ auto scopeInfo =
1205
+ std::make_tuple (scope, retiredConstraints.begin (),
1206
+ generatedConstraints.size ());
1207
+ scopes.push_back (scopeInfo);
1208
+ }
1209
+
1207
1210
// / \brief Restore all of the retired/generated constraints to the state
1208
1211
// / before given scope. This is required because retired constraints have
1209
1212
// / to be re-introduced to the system in order of arrival (LIFO) and list
@@ -1212,6 +1215,8 @@ class ConstraintSystem {
1212
1215
// /
1213
1216
// / \param scope The solver scope to rollback.
1214
1217
void rollback (SolverScope *scope) {
1218
+ --depth;
1219
+
1215
1220
SolverScope *savedScope;
1216
1221
// The position of last retired constraint before given scope.
1217
1222
ConstraintList::iterator lastRetiredPos;
@@ -1440,6 +1445,9 @@ class ConstraintSystem {
1440
1445
// / The previous score.
1441
1446
Score PreviousScore;
1442
1447
1448
+ // / Time in fractional seconds at which we entered this scope.
1449
+ double startTime;
1450
+
1443
1451
// / Constraint graph scope associated with this solver scope.
1444
1452
ConstraintGraphScope CGScope;
1445
1453
@@ -1451,6 +1459,13 @@ class ConstraintSystem {
1451
1459
public:
1452
1460
explicit SolverScope (ConstraintSystem &cs);
1453
1461
~SolverScope ();
1462
+
1463
+ Optional<double > getElapsedTimeInFractionalSeconds () {
1464
+ if (!cs.Timer )
1465
+ return None;
1466
+
1467
+ return cs.Timer ->getElapsedProcessTimeInFractionalSeconds () - startTime;
1468
+ }
1454
1469
};
1455
1470
1456
1471
ConstraintSystem (TypeChecker &tc, DeclContext *dc,
0 commit comments