Skip to content

Commit 0b258e2

Browse files
authored
Merge pull request #5421 from DougGregor/finish-lazy-constraints
2 parents 4779907 + cf19b8a commit 0b258e2

File tree

3 files changed

+8
-48
lines changed

3 files changed

+8
-48
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4156,6 +4156,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
41564156
TypeMatchOptions subflags = TMF_GenerateConstraints;
41574157
switch (kind) {
41584158
case ConstraintKind::Equal:
4159+
case ConstraintKind::Bind:
41594160
case ConstraintKind::BindParam:
41604161
case ConstraintKind::Subtype:
41614162
case ConstraintKind::Conversion:
@@ -4188,16 +4189,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
41884189
case ConstraintKind::Defaultable:
41894190
return simplifyDefaultableConstraint(first, second, subflags, locator);
41904191

4191-
case ConstraintKind::Bind: { // FIXME: This should go through matchTypes() above
4192-
// FALLBACK CASE: do the slow thing.
4193-
auto c = Constraint::create(*this, kind, first, second, DeclName(),
4194-
FunctionRefKind::Compound,
4195-
getConstraintLocator(locator));
4196-
if (isFavored) c->setFavored();
4197-
addConstraint(c);
4198-
return SolutionKind::Solved;
4199-
}
4200-
42014192
case ConstraintKind::ValueMember:
42024193
case ConstraintKind::UnresolvedValueMember:
42034194
case ConstraintKind::TypeMember:

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -333,37 +333,6 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
333333
return getConstraintLocator(anchor, path, builder.getSummaryFlags());
334334
}
335335

336-
bool ConstraintSystem::addConstraint(Constraint *constraint) {
337-
switch (simplifyConstraint(*constraint)) {
338-
case SolutionKind::Error:
339-
if (!failedConstraint) {
340-
failedConstraint = constraint;
341-
}
342-
343-
if (solverState) {
344-
solverState->retiredConstraints.push_front(constraint);
345-
solverState->generatedConstraints.push_back(constraint);
346-
}
347-
348-
return false;
349-
350-
case SolutionKind::Solved:
351-
// This constraint has already been solved; there is nothing more
352-
// to do.
353-
// Record solved constraint.
354-
if (solverState) {
355-
solverState->retiredConstraints.push_front(constraint);
356-
solverState->generatedConstraints.push_back(constraint);
357-
}
358-
359-
return true;
360-
361-
case SolutionKind::Unsolved:
362-
addUnsolvedConstraint(constraint);
363-
return false;
364-
}
365-
}
366-
367336
TypeVariableType *
368337
ConstraintSystem::getMemberType(TypeVariableType *baseTypeVar,
369338
AssociatedTypeDecl *assocType,
@@ -1389,6 +1358,12 @@ void ConstraintSystem::addOverloadSet(Type boundType,
13891358
OverloadChoice *favoredChoice) {
13901359
assert(!choices.empty() && "Empty overload set");
13911360

1361+
// If there is a single choice, add the bind overload directly.
1362+
if (choices.size() == 1) {
1363+
addBindOverloadConstraint(boundType, choices.front(), locator);
1364+
return;
1365+
}
1366+
13921367
SmallVector<Constraint *, 4> overloads;
13931368

13941369
// As we do for other favored constraints, if a favored overload has been

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,12 +1373,6 @@ class ConstraintSystem {
13731373
/// emits an error message.
13741374
void diagnoseFailureForExpr(Expr *expr);
13751375

1376-
/// \brief Add a newly-allocated constraint after attempting to simplify
1377-
/// it.
1378-
///
1379-
/// \returns true if this constraint was solved.
1380-
bool addConstraint(Constraint *constraint);
1381-
13821376
/// \brief Add a constraint to the constraint system.
13831377
void addConstraint(ConstraintKind kind, Type first, Type second,
13841378
ConstraintLocatorBuilder locator,
@@ -1490,7 +1484,7 @@ class ConstraintSystem {
14901484
if (isFavored)
14911485
constraint->setFavored();
14921486

1493-
addConstraint(constraint);
1487+
addUnsolvedConstraint(constraint);
14941488
}
14951489

14961490
/// Whether we should add a new constraint to capture a failure.

0 commit comments

Comments
 (0)