@@ -1878,15 +1878,14 @@ static void existingOperatorBindingsForDisjunction(ConstraintSystem &CS,
1878
1878
}
1879
1879
}
1880
1880
1881
- void ConstraintSystem::partitionGenericOperators (ArrayRef<Constraint *> constraints,
1882
- SmallVectorImpl<unsigned >::iterator first,
1883
- SmallVectorImpl<unsigned >::iterator last,
1884
- ConstraintLocator *locator) {
1885
- auto *argFnType = AppliedDisjunctions[locator];
1886
- if (!isOperatorBindOverload (constraints[0 ]) || !argFnType)
1881
+ void DisjunctionChoiceProducer::partitionGenericOperators (
1882
+ SmallVectorImpl<unsigned >::iterator first,
1883
+ SmallVectorImpl<unsigned >::iterator last) {
1884
+ auto *argFnType = CS.getAppliedDisjunctionArgumentFunction (Disjunction);
1885
+ if (!isOperatorBindOverload (Choices.front ()) || !argFnType)
1887
1886
return ;
1888
1887
1889
- auto operatorName = constraints [0 ]->getOverloadChoice ().getName ();
1888
+ auto operatorName = Choices [0 ]->getOverloadChoice ().getName ();
1890
1889
if (!operatorName.getBaseIdentifier ().isArithmeticOperator ())
1891
1890
return ;
1892
1891
@@ -1899,7 +1898,8 @@ void ConstraintSystem::partitionGenericOperators(ArrayRef<Constraint *> constrai
1899
1898
if (!nominal)
1900
1899
return false ;
1901
1900
1902
- auto *protocol = TypeChecker::getProtocol (getASTContext (), SourceLoc (), kind);
1901
+ auto *protocol =
1902
+ TypeChecker::getProtocol (CS.getASTContext (), SourceLoc (), kind);
1903
1903
1904
1904
if (auto *refined = dyn_cast<ProtocolDecl>(nominal))
1905
1905
return refined->inheritsFrom (protocol);
@@ -1911,7 +1911,7 @@ void ConstraintSystem::partitionGenericOperators(ArrayRef<Constraint *> constrai
1911
1911
// Gather Numeric and Sequence overloads into separate buckets.
1912
1912
for (auto iter = first; iter != last; ++iter) {
1913
1913
unsigned index = *iter;
1914
- auto *decl = constraints [index]->getOverloadChoice ().getDecl ();
1914
+ auto *decl = Choices [index]->getOverloadChoice ().getDecl ();
1915
1915
auto *nominal = decl->getDeclContext ()->getSelfNominalTypeDecl ();
1916
1916
if (!decl->getInterfaceType ()->is <GenericFunctionType>()) {
1917
1917
concreteOverloads.push_back (index);
@@ -1926,8 +1926,10 @@ void ConstraintSystem::partitionGenericOperators(ArrayRef<Constraint *> constrai
1926
1926
1927
1927
auto sortPartition = [&](SmallVectorImpl<unsigned > &partition) {
1928
1928
llvm::sort (partition, [&](unsigned lhs, unsigned rhs) -> bool {
1929
- auto *declA = dyn_cast<ValueDecl>(constraints[lhs]->getOverloadChoice ().getDecl ());
1930
- auto *declB = dyn_cast<ValueDecl>(constraints[rhs]->getOverloadChoice ().getDecl ());
1929
+ auto *declA =
1930
+ dyn_cast<ValueDecl>(Choices[lhs]->getOverloadChoice ().getDecl ());
1931
+ auto *declB =
1932
+ dyn_cast<ValueDecl>(Choices[rhs]->getOverloadChoice ().getDecl ());
1931
1933
1932
1934
return TypeChecker::isDeclRefinementOf (declA, declB);
1933
1935
});
@@ -1946,19 +1948,22 @@ void ConstraintSystem::partitionGenericOperators(ArrayRef<Constraint *> constrai
1946
1948
// overload choices first.
1947
1949
for (auto arg : argFnType->getParams ()) {
1948
1950
auto argType = arg.getPlainType ();
1949
- argType = getFixedTypeRecursive (argType, /* wantRValue=*/ true );
1951
+ argType = CS. getFixedTypeRecursive (argType, /* wantRValue=*/ true );
1950
1952
1951
1953
if (argType->isTypeVariableOrMember ())
1952
1954
continue ;
1953
1955
1954
- if (conformsToKnownProtocol (DC, argType, KnownProtocolKind::AdditiveArithmetic)) {
1955
- first = std::copy (numericOverloads.begin (), numericOverloads.end (), first);
1956
+ if (conformsToKnownProtocol (CS.DC , argType,
1957
+ KnownProtocolKind::AdditiveArithmetic)) {
1958
+ first =
1959
+ std::copy (numericOverloads.begin (), numericOverloads.end (), first);
1956
1960
numericOverloads.clear ();
1957
1961
break ;
1958
1962
}
1959
1963
1960
- if (conformsToKnownProtocol (DC, argType, KnownProtocolKind::Sequence)) {
1961
- first = std::copy (sequenceOverloads.begin (), sequenceOverloads.end (), first);
1964
+ if (conformsToKnownProtocol (CS.DC , argType, KnownProtocolKind::Sequence)) {
1965
+ first =
1966
+ std::copy (sequenceOverloads.begin (), sequenceOverloads.end (), first);
1962
1967
sequenceOverloads.clear ();
1963
1968
break ;
1964
1969
}
@@ -1969,17 +1974,23 @@ void ConstraintSystem::partitionGenericOperators(ArrayRef<Constraint *> constrai
1969
1974
first = std::copy (sequenceOverloads.begin (), sequenceOverloads.end (), first);
1970
1975
}
1971
1976
1972
- void ConstraintSystem ::partitionDisjunction (
1973
- ArrayRef<Constraint *> Choices, SmallVectorImpl<unsigned > &Ordering,
1977
+ void DisjunctionChoiceProducer ::partitionDisjunction (
1978
+ SmallVectorImpl<unsigned > &Ordering,
1974
1979
SmallVectorImpl<unsigned > &PartitionBeginning) {
1975
1980
// Apply a special-case rule for favoring one generic function over
1976
1981
// another.
1977
- if (auto favored = tryOptimizeGenericDisjunction (DC, Choices)) {
1978
- favorConstraint (favored);
1982
+ if (auto favored = tryOptimizeGenericDisjunction (CS. DC , Choices)) {
1983
+ CS. favorConstraint (favored);
1979
1984
}
1980
1985
1981
1986
SmallSet<Constraint *, 16 > taken;
1982
1987
1988
+ using ConstraintMatcher = std::function<bool (unsigned index, Constraint *)>;
1989
+ using ConstraintMatchLoop =
1990
+ std::function<void (ArrayRef<Constraint *>, ConstraintMatcher)>;
1991
+ using PartitionAppendCallback =
1992
+ std::function<void (SmallVectorImpl<unsigned > & options)>;
1993
+
1983
1994
// Local function used to iterate over the untaken choices from the
1984
1995
// disjunction and use a higher-order function to determine if they
1985
1996
// should be part of a partition.
@@ -2006,7 +2017,7 @@ void ConstraintSystem::partitionDisjunction(
2006
2017
2007
2018
// Add existing operator bindings to the main partition first. This often
2008
2019
// helps the solver find a solution fast.
2009
- existingOperatorBindingsForDisjunction (* this , Choices, everythingElse);
2020
+ existingOperatorBindingsForDisjunction (CS , Choices, everythingElse);
2010
2021
for (auto index : everythingElse)
2011
2022
taken.insert (Choices[index]);
2012
2023
@@ -2026,7 +2037,7 @@ void ConstraintSystem::partitionDisjunction(
2026
2037
});
2027
2038
2028
2039
// Then unavailable constraints if we're skipping them.
2029
- if (!shouldAttemptFixes ()) {
2040
+ if (!CS. shouldAttemptFixes ()) {
2030
2041
forEachChoice (Choices, [&](unsigned index, Constraint *constraint) -> bool {
2031
2042
if (constraint->getKind () != ConstraintKind::BindOverload)
2032
2043
return false ;
@@ -2036,7 +2047,7 @@ void ConstraintSystem::partitionDisjunction(
2036
2047
if (!funcDecl)
2037
2048
return false ;
2038
2049
2039
- if (!isDeclUnavailable (funcDecl, constraint->getLocator ()))
2050
+ if (!CS. isDeclUnavailable (funcDecl, constraint->getLocator ()))
2040
2051
return false ;
2041
2052
2042
2053
unavailable.push_back (index);
0 commit comments