Skip to content

[ConstraintSystem] Hold slightly less state in DisjunctionChoice. #18359

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 1 commit into from
Jul 31, 2018
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
10 changes: 6 additions & 4 deletions lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,11 +2012,12 @@ bool ConstraintSystem::solveForDisjunctionChoices(
Optional<Score> bestNonGenericScore;

++solverState->NumDisjunctions;
bool explicitConversion = isExplicitConversionConstraint(disjunction);
auto constraints = disjunction->getNestedConstraints();
// Try each of the constraints within the disjunction.
for (auto index : indices(constraints)) {
auto currentChoice =
DisjunctionChoice(this, disjunction, constraints[index]);
DisjunctionChoice(this, constraints[index], explicitConversion);
if (shouldSkipDisjunctionChoice(*this, currentChoice, bestNonGenericScore))
continue;

Expand Down Expand Up @@ -2164,7 +2165,9 @@ DisjunctionChoice::solve(SmallVectorImpl<Solution> &solutions,
FreeTypeVariableBinding allowFreeTypeVariables) {
CS->simplifyDisjunctionChoice(Choice);

propagateConversionInfo();
if (ExplicitConversion)
propagateConversionInfo();

if (CS->solveRec(solutions, allowFreeTypeVariables))
return None;

Expand Down Expand Up @@ -2209,8 +2212,7 @@ bool DisjunctionChoice::isSymmetricOperator() const {
}

void DisjunctionChoice::propagateConversionInfo() const {
if (!CS->isExplicitConversionConstraint(Disjunction))
return;
assert(ExplicitConversion);

auto LHS = Choice->getFirstType();
auto typeVar = LHS->getAs<TypeVariableType>();
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -3308,13 +3308,13 @@ void simplifyLocator(Expr *&anchor,

class DisjunctionChoice {
ConstraintSystem *CS;
Constraint *Disjunction;
Constraint *Choice;
bool ExplicitConversion;

public:
DisjunctionChoice(ConstraintSystem *const cs, Constraint *disjunction,
Constraint *choice)
: CS(cs), Disjunction(disjunction), Choice(choice) {}
DisjunctionChoice(ConstraintSystem *const cs, Constraint *choice,
bool explicitConversion)
: CS(cs), Choice(choice), ExplicitConversion(explicitConversion) {}

Constraint *operator->() const { return Choice; }

Expand Down