Skip to content

Commit fd021cc

Browse files
committed
refactor(sema): use DenseSet count instead of two loops to enable split constraints
1 parent 6077567 commit fd021cc

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

include/Sema/Constraint.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class Constraint {
460460
/// @brief Enable this constraint.
461461
void enable() { _isDisabled = 0; }
462462

463+
/// @brief Sets the enabled state of this constraint.
464+
/// @param enabled True to enable the constraint, false to disable it.
465+
void setEnabled(bool enabled) { _isDisabled = !enabled; }
466+
463467
/// @brief Print this constraint to the output stream.
464468
void print() const;
465469
};

include/Sema/ConstraintSystem.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ class ConstraintSystem {
219219
/// extracted.
220220
void mapImplicitConversions(Solution *solution);
221221

222-
/// @brief Solves all constraints and returns the solution result through
223-
/// the provided parameter.
222+
/// @brief Solves all enabled constraints within this local constraint
223+
/// system and returns the solution result through the provided parameter.
224+
/// This method is called within solveConstraints, after simplification and
225+
/// splitting of the constraint system, and before mapping types back to the
226+
/// AST.
224227
/// @param result The solution result to populate with found solutions.
225228
/// @return True if a solution was found, false otherwise.
226229
bool solveLocalConstraints(SolutionResult &result);

lib/Sema/ConstraintSystem/ConstraintSystem.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,7 @@ bool ConstraintSystem::solveConstraints()
298298
for (std::size_t i = 0; i < colors.size(); ++i) {
299299
// Disable all constraints not in this color
300300
for (auto *constraint : _constraints) {
301-
constraint->disable();
302-
}
303-
for (auto *constraint : colorConstraints[i]) {
304-
constraint->enable();
301+
constraint->setEnabled(colorConstraints[i].count(constraint));
305302
}
306303
SolutionResult result;
307304
if (!solveLocalConstraints(result)) {

0 commit comments

Comments
 (0)