Skip to content

Commit 0ad0a84

Browse files
committed
[ConstraintSystem] NFC: Move repairFailure to be a member of ConstraintSystem
That makes it much easier to use various facilities provided by `ConstraintSystem`.
1 parent 59a1198 commit 0ad0a84

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,10 +1978,9 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
19781978
/// Attempt to repair typing failures and record fixes if needed.
19791979
/// \return true if at least some of the failures has been repaired
19801980
/// successfully, which allows type matcher to continue.
1981-
static bool
1982-
repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
1983-
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
1984-
ConstraintLocatorBuilder locator) {
1981+
bool ConstraintSystem::repairFailures(
1982+
Type lhs, Type rhs, SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
1983+
ConstraintLocatorBuilder locator) {
19851984
SmallVector<LocatorPathElt, 4> path;
19861985
auto *anchor = locator.getLocatorParts(path);
19871986

@@ -2005,14 +2004,14 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20052004
case ConstraintLocator::ApplyArgToParam: {
20062005
if (lhs->getOptionalObjectType() && !rhs->getOptionalObjectType()) {
20072006
conversionsOrFixes.push_back(
2008-
ForceOptional::create(cs, lhs, lhs->getOptionalObjectType(),
2009-
cs.getConstraintLocator(locator)));
2007+
ForceOptional::create(*this, lhs, lhs->getOptionalObjectType(),
2008+
getConstraintLocator(locator)));
20102009
}
20112010
break;
20122011
}
20132012

20142013
case ConstraintLocator::FunctionArgument: {
2015-
auto *argLoc = cs.getConstraintLocator(
2014+
auto *argLoc = getConstraintLocator(
20162015
locator.withPathElement(LocatorPathElt::getSynthesizedArgument(0)));
20172016

20182017
// Let's drop the last element which points to a single argument
@@ -2023,7 +2022,7 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20232022
path.back().getKind() == ConstraintLocator::ContextualType))
20242023
return false;
20252024

2026-
auto arg = llvm::find_if(cs.getTypeVariables(),
2025+
auto arg = llvm::find_if(getTypeVariables(),
20272026
[&argLoc](const TypeVariableType *typeVar) {
20282027
return typeVar->getImpl().getLocator() == argLoc;
20292028
});
@@ -2040,27 +2039,27 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20402039
//
20412040
// But if `T.Element` didn't get resolved to `Void` we'd like
20422041
// to diagnose this as a missing argument which can't be ignored.
2043-
if (arg != cs.getTypeVariables().end()) {
2042+
if (arg != getTypeVariables().end()) {
20442043
auto fnType = FunctionType::get({FunctionType::Param(lhs)},
2045-
cs.getASTContext().TheEmptyTupleType);
2044+
getASTContext().TheEmptyTupleType);
20462045
conversionsOrFixes.push_back(AddMissingArguments::create(
2047-
cs, fnType, {FunctionType::Param(*arg)},
2048-
cs.getConstraintLocator(anchor, path,
2049-
/*summaryFlags=*/0)));
2046+
*this, fnType, {FunctionType::Param(*arg)},
2047+
getConstraintLocator(anchor, path,
2048+
/*summaryFlags=*/0)));
20502049
}
20512050
break;
20522051
}
20532052

20542053
case ConstraintLocator::TypeParameterRequirement:
20552054
case ConstraintLocator::ConditionalRequirement: {
2056-
if (auto *fix = fixRequirementFailure(cs, lhs, rhs, anchor, path))
2055+
if (auto *fix = fixRequirementFailure(*this, lhs, rhs, anchor, path))
20572056
conversionsOrFixes.push_back(fix);
20582057
break;
20592058
}
20602059

20612060
case ConstraintLocator::ClosureResult: {
2062-
auto *fix = ContextualMismatch::create(cs, lhs, rhs,
2063-
cs.getConstraintLocator(locator));
2061+
auto *fix = ContextualMismatch::create(*this, lhs, rhs,
2062+
getConstraintLocator(locator));
20642063
conversionsOrFixes.push_back(fix);
20652064
break;
20662065
}
@@ -2070,14 +2069,14 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20702069
// between them are mutability and/or root, value type mismatch.
20712070
if (isKnownKeyPathType(lhs) && isKnownKeyPathType(rhs)) {
20722071
auto *fix = KeyPathContextualMismatch::create(
2073-
cs, lhs, rhs, cs.getConstraintLocator(locator));
2072+
*this, lhs, rhs, getConstraintLocator(locator));
20742073
conversionsOrFixes.push_back(fix);
20752074
}
20762075

20772076
if (lhs->is<FunctionType>() && !rhs->is<AnyFunctionType>() &&
20782077
isa<ClosureExpr>(anchor)) {
2079-
auto *fix = ContextualMismatch::create(cs, lhs, rhs,
2080-
cs.getConstraintLocator(locator));
2078+
auto *fix = ContextualMismatch::create(*this, lhs, rhs,
2079+
getConstraintLocator(locator));
20812080
conversionsOrFixes.push_back(fix);
20822081
}
20832082
break;
@@ -2899,7 +2898,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28992898

29002899
// Attempt to repair any failures identifiable at this point.
29012900
if (attemptFixes) {
2902-
if (repairFailures(*this, type1, type2, conversionsOrFixes, locator)) {
2901+
if (repairFailures(type1, type2, conversionsOrFixes, locator)) {
29032902
if (conversionsOrFixes.empty())
29042903
return getTypeMatchSuccess();
29052904
}

lib/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,13 @@ class ConstraintSystem {
26242624
TypeMatchResult(SolutionKind result) : Kind(result) {}
26252625
};
26262626

2627+
/// Attempt to repair typing failures and record fixes if needed.
2628+
/// \return true if at least some of the failures has been repaired
2629+
/// successfully, which allows type matcher to continue.
2630+
bool repairFailures(Type lhs, Type rhs,
2631+
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
2632+
ConstraintLocatorBuilder locator);
2633+
26272634
/// Subroutine of \c matchTypes(), which matches up two tuple types.
26282635
///
26292636
/// \returns the result of performing the tuple-to-tuple conversion.

0 commit comments

Comments
 (0)