Skip to content

Commit ccd2171

Browse files
authored
Merge pull request #16911 from rudkx/minor-constraint-stuff
Minor constraint system stuff
2 parents fd808f3 + 656952a commit ccd2171

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -472,8 +472,6 @@ ConstraintSystem::SolverState::~SolverState() {
472472
ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
473473
: cs(cs), CGScope(cs.CG)
474474
{
475-
++cs.solverState->depth;
476-
477475
resolvedOverloadSets = cs.resolvedOverloadSets;
478476
numTypeVariables = cs.TypeVariables.size();
479477
numSavedBindings = cs.solverState->savedBindings.size();
@@ -485,16 +483,15 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
485483
numDefaultedConstraints = cs.DefaultedConstraints.size();
486484
numCheckedConformances = cs.CheckedConformances.size();
487485
PreviousScore = cs.CurrentScore;
486+
if (cs.Timer) {
487+
startTime = cs.Timer->getElapsedProcessTimeInFractionalSeconds();
488+
}
488489

489490
cs.solverState->registerScope(this);
490491
assert(!cs.failedConstraint && "Unexpected failed constraint!");
491-
492-
++cs.solverState->NumStatesExplored;
493492
}
494493

495494
ConstraintSystem::SolverScope::~SolverScope() {
496-
--cs.solverState->depth;
497-
498495
// Erase the end of various lists.
499496
cs.resolvedOverloadSets = resolvedOverloadSets;
500497
truncate(cs.TypeVariables, numTypeVariables);

lib/Sema/ConstraintSystem.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1144,19 +1144,6 @@ class ConstraintSystem {
11441144
#define CS_STATISTIC(Name, Description) unsigned Name = 0;
11451145
#include "ConstraintSolverStats.def"
11461146

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-
11601147
/// \brief Check whether there are any retired constraints present.
11611148
bool hasRetiredConstraints() const {
11621149
return !retiredConstraints.empty();
@@ -1204,6 +1191,22 @@ class ConstraintSystem {
12041191
}
12051192
}
12061193

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+
12071210
/// \brief Restore all of the retired/generated constraints to the state
12081211
/// before given scope. This is required because retired constraints have
12091212
/// to be re-introduced to the system in order of arrival (LIFO) and list
@@ -1212,6 +1215,8 @@ class ConstraintSystem {
12121215
///
12131216
/// \param scope The solver scope to rollback.
12141217
void rollback(SolverScope *scope) {
1218+
--depth;
1219+
12151220
SolverScope *savedScope;
12161221
// The position of last retired constraint before given scope.
12171222
ConstraintList::iterator lastRetiredPos;
@@ -1440,6 +1445,9 @@ class ConstraintSystem {
14401445
/// The previous score.
14411446
Score PreviousScore;
14421447

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

@@ -1451,6 +1459,13 @@ class ConstraintSystem {
14511459
public:
14521460
explicit SolverScope(ConstraintSystem &cs);
14531461
~SolverScope();
1462+
1463+
Optional<double> getElapsedTimeInFractionalSeconds() {
1464+
if (!cs.Timer)
1465+
return None;
1466+
1467+
return cs.Timer->getElapsedProcessTimeInFractionalSeconds() - startTime;
1468+
}
14541469
};
14551470

14561471
ConstraintSystem(TypeChecker &tc, DeclContext *dc,

0 commit comments

Comments
 (0)