@@ -81,7 +81,7 @@ ConstraintSystem::determineBestBindings() {
81
81
continue ;
82
82
83
83
bindings.addPotentialBinding (
84
- { type, AllowedBindingKind::Supertypes, binding. BindingSource } );
84
+ binding. withSameSource ( type, AllowedBindingKind::Supertypes) );
85
85
}
86
86
}
87
87
@@ -143,8 +143,8 @@ void ConstraintSystem::PotentialBindings::addPotentialBinding(
143
143
!binding.BindingType ->hasUnresolvedType () &&
144
144
!binding.BindingType ->hasTypeVariable () &&
145
145
!binding.BindingType ->hasUnboundGenericType () &&
146
- !binding.DefaultedProtocol && !binding. isDefaultableBinding () &&
147
- allowJoinMeet) {
146
+ !binding.hasDefaultedLiteralProtocol () &&
147
+ !binding. isDefaultableBinding () && allowJoinMeet) {
148
148
if (lastSupertypeIndex) {
149
149
auto &lastBinding = Bindings[*lastSupertypeIndex];
150
150
auto lastType = lastBinding.BindingType ->getWithoutSpecifierType ();
@@ -164,7 +164,7 @@ void ConstraintSystem::PotentialBindings::addPotentialBinding(
164
164
lastSupertypeIndex = Bindings.size ();
165
165
}
166
166
167
- if (auto *literalProtocol = binding.DefaultedProtocol )
167
+ if (auto *literalProtocol = binding.getDefaultedLiteralProtocol () )
168
168
foundLiteralBinding (literalProtocol);
169
169
170
170
// If the type variable can't bind to an lvalue, make sure the
@@ -371,7 +371,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
371
371
kind = AllowedBindingKind::Exact;
372
372
}
373
373
374
- return PotentialBinding{type, kind, constraint-> getKind () };
374
+ return PotentialBinding{type, kind, constraint};
375
375
}
376
376
377
377
// / Retrieve the set of potential type bindings for the given
@@ -466,9 +466,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
466
466
path.back ().getKind () == ConstraintLocator::ClosureResult &&
467
467
binding->Kind == AllowedBindingKind::Supertypes &&
468
468
exactTypes.insert (voidType).second ) {
469
- result.addPotentialBinding (
470
- {voidType, binding->Kind , constraint->getKind ()},
471
- /* allowJoinMeet=*/ false );
469
+ result.addPotentialBinding ({voidType, binding->Kind , constraint},
470
+ /* allowJoinMeet=*/ false );
472
471
}
473
472
}
474
473
}
@@ -551,9 +550,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
551
550
if (!exactTypes.insert (defaultType->getCanonicalType ()).second )
552
551
continue ;
553
552
554
- literalBindings.push_back ({defaultType, AllowedBindingKind::Subtypes,
555
- constraint->getKind (),
556
- constraint->getProtocol ()});
553
+ literalBindings.push_back (
554
+ {defaultType, AllowedBindingKind::Subtypes, constraint});
557
555
continue ;
558
556
}
559
557
@@ -578,9 +576,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
578
576
579
577
if (!matched) {
580
578
exactTypes.insert (defaultType->getCanonicalType ());
581
- literalBindings.push_back ({defaultType, AllowedBindingKind::Subtypes,
582
- constraint->getKind (),
583
- constraint->getProtocol ()});
579
+ literalBindings.push_back (
580
+ {defaultType, AllowedBindingKind::Subtypes, constraint});
584
581
}
585
582
586
583
break ;
@@ -677,7 +674,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
677
674
// might be covered by non-defaulted bindings.
678
675
bool updatedBindingType = false ;
679
676
for (auto &literalBinding : literalBindings) {
680
- auto *protocol = literalBinding.DefaultedProtocol ;
677
+ auto *protocol = literalBinding.getDefaultedLiteralProtocol () ;
681
678
682
679
assert (protocol);
683
680
@@ -716,7 +713,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
716
713
}
717
714
718
715
for (auto &literalBinding : literalBindings) {
719
- auto *protocol = literalBinding.DefaultedProtocol ;
716
+ auto *protocol = literalBinding.getDefaultedLiteralProtocol () ;
720
717
// For any literal type that has been covered, skip them.
721
718
if (coveredLiteralProtocols.count (protocol) == 0 )
722
719
result.addPotentialBinding (std::move (literalBinding));
@@ -729,9 +726,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
729
726
if (!exactTypes.insert (type->getCanonicalType ()).second )
730
727
continue ;
731
728
732
- result.addPotentialBinding ({type, AllowedBindingKind::Exact,
733
- constraint->getKind (), nullptr ,
734
- constraint->getLocator ()});
729
+ result.addPotentialBinding ({type, AllowedBindingKind::Exact, constraint});
735
730
}
736
731
737
732
// If there are no bindings, typeVar may be a hole.
@@ -745,9 +740,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
745
740
if (locator->isLastElement <LocatorPathElt::MemberRefBase>())
746
741
result.PotentiallyIncomplete = true ;
747
742
748
- result.addPotentialBinding ({getASTContext ().TheUnresolvedType ,
749
- AllowedBindingKind::Exact, ConstraintKind::Defaultable, nullptr ,
750
- typeVar->getImpl ().getLocator ()});
743
+ result.addPotentialBinding (
744
+ PotentialBinding::forHole (getASTContext (), locator));
751
745
}
752
746
753
747
// Determine if the bindings only constrain the type variable from above with
@@ -918,11 +912,11 @@ bool TypeVarBindingProducer::computeNext() {
918
912
919
913
// If we have a protocol with a default type, look for alternative
920
914
// types to the default.
921
- if (NumTries == 0 && binding.DefaultedProtocol ) {
922
- auto knownKind = *(binding.DefaultedProtocol ->getKnownProtocolKind ());
915
+ if (NumTries == 0 && binding.hasDefaultedLiteralProtocol ()) {
916
+ auto knownKind =
917
+ *(binding.getDefaultedLiteralProtocol ()->getKnownProtocolKind ());
923
918
for (auto altType : CS.getAlternativeLiteralTypes (knownKind)) {
924
- addNewBinding ({altType, BindingKind::Subtypes, binding.BindingSource ,
925
- binding.DefaultedProtocol });
919
+ addNewBinding (binding.withSameSource (altType, BindingKind::Subtypes));
926
920
}
927
921
}
928
922
@@ -939,10 +933,10 @@ bool TypeVarBindingProducer::computeNext() {
939
933
if (auto otherTypeVar = objTy->getAs <TypeVariableType>()) {
940
934
if (TypeVar->getImpl ().canBindToLValue () ==
941
935
otherTypeVar->getImpl ().canBindToLValue ()) {
942
- addNewBinding ({objTy, binding.Kind , binding.BindingSource } );
936
+ addNewBinding (binding.withSameSource (objTy , binding.Kind ) );
943
937
}
944
938
} else {
945
- addNewBinding ({objTy, binding.Kind , binding.BindingSource } );
939
+ addNewBinding (binding.withSameSource (objTy , binding.Kind ) );
946
940
}
947
941
}
948
942
}
@@ -953,7 +947,7 @@ bool TypeVarBindingProducer::computeNext() {
953
947
for (auto supertype : enumerateDirectSupertypes (type)) {
954
948
// If we're not allowed to try this binding, skip it.
955
949
if (auto simplifiedSuper = CS.checkTypeOfBinding (TypeVar, supertype))
956
- addNewBinding ({*simplifiedSuper, binding.Kind , binding. BindingSource } );
950
+ addNewBinding (binding.withType (*simplifiedSuper) );
957
951
}
958
952
}
959
953
@@ -968,12 +962,13 @@ bool TypeVarBindingProducer::computeNext() {
968
962
969
963
bool TypeVariableBinding::attempt (ConstraintSystem &cs) const {
970
964
auto type = Binding.BindingType ;
971
- auto *locator = TypeVar->getImpl ().getLocator ();
965
+ auto *srcLocator = Binding.getLocator ();
966
+ auto *dstLocator = TypeVar->getImpl ().getLocator ();
972
967
973
- if (Binding.DefaultedProtocol ) {
974
- type = cs.openUnboundGenericType (type, locator );
968
+ if (Binding.hasDefaultedLiteralProtocol () ) {
969
+ type = cs.openUnboundGenericType (type, dstLocator );
975
970
type = type->reconstituteSugar (/* recursive=*/ false );
976
- } else if (Binding. BindingSource == ConstraintKind::ArgumentConversion &&
971
+ } else if (srcLocator-> isLastElement <LocatorPathElt::ApplyArgToParam>() &&
977
972
!type->hasTypeVariable () && cs.isCollectionType (type)) {
978
973
// If the type binding comes from the argument conversion, let's
979
974
// instead of binding collection types directly, try to bind
@@ -984,27 +979,27 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
984
979
auto UGT = UnboundGenericType::get (BGT->getDecl (), BGT->getParent (),
985
980
BGT->getASTContext ());
986
981
987
- type = cs.openUnboundGenericType (UGT, locator );
982
+ type = cs.openUnboundGenericType (UGT, dstLocator );
988
983
type = type->reconstituteSugar (/* recursive=*/ false );
989
984
}
990
985
991
- // FIXME: We want the locator that indicates where the binding came
992
- // from.
993
- cs.addConstraint (ConstraintKind::Bind, TypeVar, type, locator);
986
+ cs.addConstraint (ConstraintKind::Bind, TypeVar, type, srcLocator);
994
987
995
988
// If this was from a defaultable binding note that.
996
989
if (Binding.isDefaultableBinding ()) {
997
- cs.DefaultedConstraints .push_back (Binding.DefaultableBinding );
998
-
999
- if (locator->isForGenericParameter () && type->isHole ()) {
1000
- // Drop `generic parameter` locator element so that all missing
1001
- // generic parameters related to the same path can be coalesced later.
1002
- auto path = locator->getPath ();
1003
- auto genericParam = locator->getGenericParameter ();
1004
- auto *fix = DefaultGenericArgument::create (cs, genericParam,
1005
- cs.getConstraintLocator (locator->getAnchor (), path.drop_back ()));
1006
- if (cs.recordFix (fix))
1007
- return true ;
990
+ cs.DefaultedConstraints .push_back (srcLocator);
991
+
992
+ if (type->isHole ()) {
993
+ if (auto *GP = TypeVar->getImpl ().getGenericParameter ()) {
994
+ auto path = dstLocator->getPath ();
995
+ // Drop `generic parameter` locator element so that all missing
996
+ // generic parameters related to the same path can be coalesced later.
997
+ auto *fix = DefaultGenericArgument::create (
998
+ cs, GP,
999
+ cs.getConstraintLocator (dstLocator->getAnchor (), path.drop_back ()));
1000
+ if (cs.recordFix (fix))
1001
+ return true ;
1002
+ }
1008
1003
}
1009
1004
}
1010
1005
0 commit comments