Skip to content

Commit c4b74a3

Browse files
committed
[ConstraintSystem] Remove getSourceKind() from PotentialBinding
There was a single place where it was used to determine whether a binding comes from an argument conversion constraint. Since constraint locator is part of the binding now it's possible to use it instead and remove unused accessor.
1 parent 87beea3 commit c4b74a3

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,13 @@ bool TypeVarBindingProducer::computeNext() {
962962

963963
bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
964964
auto type = Binding.BindingType;
965-
auto *locator = TypeVar->getImpl().getLocator();
965+
auto *srcLocator = Binding.getLocator();
966+
auto *dstLocator = TypeVar->getImpl().getLocator();
966967

967968
if (Binding.hasDefaultedLiteralProtocol()) {
968-
type = cs.openUnboundGenericType(type, locator);
969+
type = cs.openUnboundGenericType(type, dstLocator);
969970
type = type->reconstituteSugar(/*recursive=*/false);
970-
} else if (Binding.getSourceKind() == ConstraintKind::ArgumentConversion &&
971+
} else if (srcLocator->isLastElement<LocatorPathElt::ApplyArgToParam>() &&
971972
!type->hasTypeVariable() && cs.isCollectionType(type)) {
972973
// If the type binding comes from the argument conversion, let's
973974
// instead of binding collection types directly, try to bind
@@ -978,25 +979,27 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
978979
auto UGT = UnboundGenericType::get(BGT->getDecl(), BGT->getParent(),
979980
BGT->getASTContext());
980981

981-
type = cs.openUnboundGenericType(UGT, locator);
982+
type = cs.openUnboundGenericType(UGT, dstLocator);
982983
type = type->reconstituteSugar(/*recursive=*/false);
983984
}
984985

985-
cs.addConstraint(ConstraintKind::Bind, TypeVar, type, Binding.getLocator());
986+
cs.addConstraint(ConstraintKind::Bind, TypeVar, type, srcLocator);
986987

987988
// If this was from a defaultable binding note that.
988989
if (Binding.isDefaultableBinding()) {
989-
cs.DefaultedConstraints.push_back(Binding.getLocator());
990-
991-
if (locator->isForGenericParameter() && type->isHole()) {
992-
// Drop `generic parameter` locator element so that all missing
993-
// generic parameters related to the same path can be coalesced later.
994-
auto path = locator->getPath();
995-
auto genericParam = locator->getGenericParameter();
996-
auto *fix = DefaultGenericArgument::create(cs, genericParam,
997-
cs.getConstraintLocator(locator->getAnchor(), path.drop_back()));
998-
if (cs.recordFix(fix))
999-
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+
}
10001003
}
10011004
}
10021005

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,14 +3328,6 @@ class ConstraintSystem {
33283328
: nullptr;
33293329
}
33303330

3331-
ConstraintKind getSourceKind() const {
3332-
if (auto *constraint = BindingSource.dyn_cast<Constraint *>())
3333-
return constraint->getKind();
3334-
// If binding source is not constraint - it's a hole which is
3335-
// always a `Bind` constraint.
3336-
return ConstraintKind::Bind;
3337-
}
3338-
33393331
ConstraintLocator *getLocator() const {
33403332
if (auto *constraint = BindingSource.dyn_cast<Constraint *>())
33413333
return constraint->getLocator();
@@ -3346,8 +3338,8 @@ class ConstraintSystem {
33463338
return {type, Kind, BindingSource};
33473339
}
33483340

3349-
PotentialBinding withSameSource(Type type, AllowedBindingKind kind) {
3350-
return {type, Kind, BindingSource};
3341+
PotentialBinding withSameSource(Type type, AllowedBindingKind kind) const {
3342+
return {type, kind, BindingSource};
33513343
}
33523344

33533345
static PotentialBinding forHole(ASTContext &ctx,

0 commit comments

Comments
 (0)