Skip to content

Commit a7b5476

Browse files
committed
[DisjunctionStep] Only check requirements early to skip disjunction
choices for arithmetic operators for now.
1 parent f75eca9 commit a7b5476

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/Sema/CSStep.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -661,27 +661,29 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
661661
if (checkRequirementsEarly()) {
662662
Constraint *constraint = choice;
663663
auto *decl = constraint->getOverloadChoice().getDecl();
664-
auto *useDC = constraint->getOverloadUseDC();
665-
auto choiceType = CS.getEffectiveOverloadType(constraint->getOverloadChoice(),
666-
/*allowMembers=*/true, useDC);
667-
auto choiceFnType = choiceType->getAs<FunctionType>();
668-
auto genericFnType = decl->getInterfaceType()->getAs<GenericFunctionType>();
669-
auto signature = genericFnType->getGenericSignature();
670-
671-
for (auto argParamPair : llvm::zip(argFnType->getParams(),
672-
choiceFnType->getParams())) {
673-
auto argType = std::get<0>(argParamPair).getPlainType();
674-
auto paramType = std::get<1>(argParamPair).getPlainType();
675-
676-
// Only check argument types with no type variables that will be matched
677-
// against a plain type parameter.
678-
argType = argType->getCanonicalType()->getWithoutSpecifierType();
679-
if (argType->hasTypeVariable() || !paramType->isTypeParameter())
680-
continue;
681-
682-
for (auto *protocol : signature->getRequiredProtocols(paramType)) {
683-
if (!TypeChecker::conformsToProtocol(argType, protocol, useDC))
684-
return skip("unsatisfied");
664+
if (decl->getBaseIdentifier().isArithmeticOperator()) {
665+
auto *useDC = constraint->getOverloadUseDC();
666+
auto choiceType = CS.getEffectiveOverloadType(constraint->getOverloadChoice(),
667+
/*allowMembers=*/true, useDC);
668+
auto choiceFnType = choiceType->getAs<FunctionType>();
669+
auto genericFnType = decl->getInterfaceType()->getAs<GenericFunctionType>();
670+
auto signature = genericFnType->getGenericSignature();
671+
672+
for (auto argParamPair : llvm::zip(argFnType->getParams(),
673+
choiceFnType->getParams())) {
674+
auto argType = std::get<0>(argParamPair).getPlainType();
675+
auto paramType = std::get<1>(argParamPair).getPlainType();
676+
677+
// Only check argument types with no type variables that will be matched
678+
// against a plain type parameter.
679+
argType = argType->getCanonicalType()->getWithoutSpecifierType();
680+
if (argType->hasTypeVariable() || !paramType->isTypeParameter())
681+
continue;
682+
683+
for (auto *protocol : signature->getRequiredProtocols(paramType)) {
684+
if (!TypeChecker::conformsToProtocol(argType, protocol, useDC))
685+
return skip("unsatisfied");
686+
}
685687
}
686688
}
687689
}

0 commit comments

Comments
 (0)