Skip to content

Finish lazy constraints #5421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4156,6 +4156,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
TypeMatchOptions subflags = TMF_GenerateConstraints;
switch (kind) {
case ConstraintKind::Equal:
case ConstraintKind::Bind:
case ConstraintKind::BindParam:
case ConstraintKind::Subtype:
case ConstraintKind::Conversion:
Expand Down Expand Up @@ -4188,16 +4189,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
case ConstraintKind::Defaultable:
return simplifyDefaultableConstraint(first, second, subflags, locator);

case ConstraintKind::Bind: { // FIXME: This should go through matchTypes() above
// FALLBACK CASE: do the slow thing.
auto c = Constraint::create(*this, kind, first, second, DeclName(),
FunctionRefKind::Compound,
getConstraintLocator(locator));
if (isFavored) c->setFavored();
addConstraint(c);
return SolutionKind::Solved;
}

case ConstraintKind::ValueMember:
case ConstraintKind::UnresolvedValueMember:
case ConstraintKind::TypeMember:
Expand Down
37 changes: 6 additions & 31 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,37 +333,6 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
return getConstraintLocator(anchor, path, builder.getSummaryFlags());
}

bool ConstraintSystem::addConstraint(Constraint *constraint) {
switch (simplifyConstraint(*constraint)) {
case SolutionKind::Error:
if (!failedConstraint) {
failedConstraint = constraint;
}

if (solverState) {
solverState->retiredConstraints.push_front(constraint);
solverState->generatedConstraints.push_back(constraint);
}

return false;

case SolutionKind::Solved:
// This constraint has already been solved; there is nothing more
// to do.
// Record solved constraint.
if (solverState) {
solverState->retiredConstraints.push_front(constraint);
solverState->generatedConstraints.push_back(constraint);
}

return true;

case SolutionKind::Unsolved:
addUnsolvedConstraint(constraint);
return false;
}
}

TypeVariableType *
ConstraintSystem::getMemberType(TypeVariableType *baseTypeVar,
AssociatedTypeDecl *assocType,
Expand Down Expand Up @@ -1389,6 +1358,12 @@ void ConstraintSystem::addOverloadSet(Type boundType,
OverloadChoice *favoredChoice) {
assert(!choices.empty() && "Empty overload set");

// If there is a single choice, add the bind overload directly.
if (choices.size() == 1) {
addBindOverloadConstraint(boundType, choices.front(), locator);
return;
}

SmallVector<Constraint *, 4> overloads;

// As we do for other favored constraints, if a favored overload has been
Expand Down
8 changes: 1 addition & 7 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1373,12 +1373,6 @@ class ConstraintSystem {
/// emits an error message.
void diagnoseFailureForExpr(Expr *expr);

/// \brief Add a newly-allocated constraint after attempting to simplify
/// it.
///
/// \returns true if this constraint was solved.
bool addConstraint(Constraint *constraint);

/// \brief Add a constraint to the constraint system.
void addConstraint(ConstraintKind kind, Type first, Type second,
ConstraintLocatorBuilder locator,
Expand Down Expand Up @@ -1490,7 +1484,7 @@ class ConstraintSystem {
if (isFavored)
constraint->setFavored();

addConstraint(constraint);
addUnsolvedConstraint(constraint);
}

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