@@ -44,8 +44,7 @@ void ConstraintGraphNode::initBindingSet() {
4444// / to a Double and non-optional value could be injected into an optional.
4545static bool hasConversions (Type);
4646
47- static std::optional<Type> checkTypeOfBinding (TypeVariableType *typeVar,
48- Type type);
47+ static bool checkTypeOfBinding (TypeVariableType *typeVar, Type type);
4948
5049BindingSet::BindingSet (ConstraintSystem &CS, TypeVariableType *TypeVar,
5150 const PotentialBindings &info)
@@ -1579,33 +1578,32 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar) {
15791578// / Check whether the given type can be used as a binding for the given
15801579// / type variable.
15811580// /
1582- // / \returns the type to bind to, if the binding is okay.
1583- static std::optional<Type> checkTypeOfBinding (TypeVariableType *typeVar,
1584- Type type) {
1581+ // / \returns true if the binding is okay.
1582+ static bool checkTypeOfBinding (TypeVariableType *typeVar, Type type) {
15851583 // If the type references the type variable, don't permit the binding.
15861584 if (type->hasTypeVariable ()) {
15871585 SmallPtrSet<TypeVariableType *, 4 > referencedTypeVars;
15881586 type->getTypeVariables (referencedTypeVars);
15891587 if (referencedTypeVars.count (typeVar))
1590- return std:: nullopt ;
1588+ return false ;
15911589 }
15921590
15931591 {
15941592 auto objType = type->getWithoutSpecifierType ();
15951593
15961594 // If the type is a type variable itself, don't permit the binding.
15971595 if (objType->is <TypeVariableType>())
1598- return std:: nullopt ;
1596+ return false ;
15991597
16001598 // Don't bind to a dependent member type, even if it's currently
16011599 // wrapped in any number of optionals, because binding producer
16021600 // might unwrap and try to attempt it directly later.
16031601 if (objType->lookThroughAllOptionalTypes ()->is <DependentMemberType>())
1604- return std:: nullopt ;
1602+ return false ;
16051603 }
16061604
1607- // Okay, allow the binding (with the simplified type) .
1608- return type ;
1605+ // Okay, allow the binding.
1606+ return true ;
16091607}
16101608
16111609std::optional<PotentialBinding>
@@ -1814,9 +1812,7 @@ PotentialBindings::inferFromRelational(ConstraintSystem &CS,
18141812 }
18151813
18161814 // Check whether we can perform this binding.
1817- if (auto boundType = checkTypeOfBinding (TypeVar, type)) {
1818- type = *boundType;
1819- } else {
1815+ if (!checkTypeOfBinding (TypeVar, type)) {
18201816 auto *bindingTypeVar = type->getRValueType ()->getAs <TypeVariableType>();
18211817
18221818 if (!bindingTypeVar)
@@ -2677,8 +2673,7 @@ bool TypeVarBindingProducer::computeNext() {
26772673
26782674 for (auto supertype : enumerateDirectSupertypes (type)) {
26792675 // If we're not allowed to try this binding, skip it.
2680- if (auto simplifiedSuper = checkTypeOfBinding (TypeVar, supertype)) {
2681- auto supertype = *simplifiedSuper;
2676+ if (checkTypeOfBinding (TypeVar, supertype)) {
26822677 // A key path type cannot be bound to type-erased key path variants.
26832678 if (TypeVar->getImpl ().isKeyPathType () &&
26842679 isTypeErasedKeyPathType (supertype))
0 commit comments