Skip to content

Commit d57c112

Browse files
committed
[ConstraintSystem] NFC: Replace isOperatorBindOverload with isOperatorDisjunction
1 parent fef108f commit d57c112

File tree

3 files changed

+15
-39
lines changed

3 files changed

+15
-39
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,6 +5307,8 @@ Type isRawRepresentable(ConstraintSystem &cs, Type type,
53075307
Type getDynamicSelfReplacementType(Type baseObjTy, const ValueDecl *member,
53085308
ConstraintLocator *memberLocator);
53095309

5310+
ValueDecl *getOverloadChoiceDecl(Constraint *choice);
5311+
53105312
class DisjunctionChoice {
53115313
ConstraintSystem &CS;
53125314
unsigned Index;
@@ -5332,7 +5334,7 @@ class DisjunctionChoice {
53325334
}
53335335

53345336
bool isUnavailable() const {
5335-
if (auto *decl = getDecl(Choice))
5337+
if (auto *decl = getOverloadChoiceDecl(Choice))
53365338
return CS.isDeclUnavailable(decl, Choice->getLocator());
53375339
return false;
53385340
}
@@ -5360,23 +5362,12 @@ class DisjunctionChoice {
53605362
void propagateConversionInfo(ConstraintSystem &cs) const;
53615363

53625364
static ValueDecl *getOperatorDecl(Constraint *choice) {
5363-
auto *decl = getDecl(choice);
5365+
auto *decl = getOverloadChoiceDecl(choice);
53645366
if (!decl)
53655367
return nullptr;
53665368

53675369
return decl->isOperator() ? decl : nullptr;
53685370
}
5369-
5370-
static ValueDecl *getDecl(Constraint *constraint) {
5371-
if (constraint->getKind() != ConstraintKind::BindOverload)
5372-
return nullptr;
5373-
5374-
auto choice = constraint->getOverloadChoice();
5375-
if (choice.getKind() != OverloadChoiceKind::Decl)
5376-
return nullptr;
5377-
5378-
return choice.getDecl();
5379-
}
53805371
};
53815372

53825373
class TypeVariableBinding {

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,18 +1734,6 @@ Constraint *ConstraintSystem::getUnboundBindOverloadDisjunction(
17341734
return result->first;
17351735
}
17361736

1737-
static bool isOperatorBindOverload(Constraint *bindOverload) {
1738-
if (bindOverload->getKind() != ConstraintKind::BindOverload)
1739-
return false;
1740-
1741-
auto choice = bindOverload->getOverloadChoice();
1742-
if (!choice.isDecl())
1743-
return false;
1744-
1745-
auto *funcDecl = dyn_cast<FuncDecl>(choice.getDecl());
1746-
return funcDecl && funcDecl->getOperatorDecl();
1747-
}
1748-
17491737
// Performance hack: if there are two generic overloads, and one is
17501738
// more specialized than the other, prefer the more-specialized one.
17511739
static Constraint *tryOptimizeGenericDisjunction(
@@ -1882,7 +1870,7 @@ void DisjunctionChoiceProducer::partitionGenericOperators(
18821870
SmallVectorImpl<unsigned>::iterator first,
18831871
SmallVectorImpl<unsigned>::iterator last) {
18841872
auto *argFnType = CS.getAppliedDisjunctionArgumentFunction(Disjunction);
1885-
if (!isOperatorBindOverload(Choices.front()) || !argFnType)
1873+
if (!isOperatorDisjunction(Disjunction) || !argFnType)
18861874
return;
18871875

18881876
auto operatorName = Choices[0]->getOverloadChoice().getName();
@@ -2056,11 +2044,8 @@ void DisjunctionChoiceProducer::partitionDisjunction(
20562044
}
20572045

20582046
// Partition SIMD operators.
2059-
if (isOperatorBindOverload(Choices[0])) {
2047+
if (isOperatorDisjunction(Disjunction)) {
20602048
forEachChoice(Choices, [&](unsigned index, Constraint *constraint) -> bool {
2061-
if (!isOperatorBindOverload(constraint))
2062-
return false;
2063-
20642049
if (isSIMDOperator(constraint->getOverloadChoice().getDecl())) {
20652050
simdOperators.push_back(index);
20662051
return true;
@@ -2114,8 +2099,7 @@ Constraint *ConstraintSystem::selectDisjunction() {
21142099
unsigned firstFavored = first->countFavoredNestedConstraints();
21152100
unsigned secondFavored = second->countFavoredNestedConstraints();
21162101

2117-
if (!isOperatorBindOverload(first->getNestedConstraints().front()) ||
2118-
!isOperatorBindOverload(second->getNestedConstraints().front()))
2102+
if (!isOperatorDisjunction(first) || !isOperatorDisjunction(second))
21192103
return firstActive < secondActive;
21202104

21212105
if (firstFavored == secondFavored) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,17 +5690,18 @@ TypeVarBindingProducer::getDefaultBinding(Constraint *constraint) const {
56905690
: binding;
56915691
}
56925692

5693+
ValueDecl *constraints::getOverloadChoiceDecl(Constraint *choice) {
5694+
if (choice->getKind() != ConstraintKind::BindOverload)
5695+
return nullptr;
5696+
return choice->getOverloadChoice().getDeclOrNull();
5697+
}
5698+
56935699
bool constraints::isOperatorDisjunction(Constraint *disjunction) {
56945700
assert(disjunction->getKind() == ConstraintKind::Disjunction);
56955701

56965702
auto choices = disjunction->getNestedConstraints();
5697-
if (choices.empty())
5698-
return false;
5699-
5700-
auto *choice = choices.front();
5701-
if (choice->getKind() != ConstraintKind::BindOverload)
5702-
return false;
5703+
assert(!choices.empty());
57035704

5704-
auto *decl = choice->getOverloadChoice().getDeclOrNull();
5705+
auto *decl = getOverloadChoiceDecl(choices.front());
57055706
return decl ? decl->isOperator() : false;
57065707
}

0 commit comments

Comments
 (0)