Skip to content

Commit b44bff2

Browse files
committed
Sema: Fold Constraint::createFixedChoice() into Constraint::createBindOverload()
1 parent 2eaec5a commit b44bff2

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

include/swift/Sema/Constraint.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ class Constraint final : public llvm::ilist_node<Constraint>,
558558
ValueDecl *requirement, DeclContext *useDC,
559559
FunctionRefKind functionRefKind, ConstraintLocator *locator);
560560

561-
/// Create an overload-binding constraint.
561+
/// Create an overload-binding constraint, possibly with a fix.
562562
static Constraint *createBindOverload(ConstraintSystem &cs, Type type,
563563
OverloadChoice choice,
564-
DeclContext *useDC,
564+
DeclContext *useDC, ConstraintFix *fix,
565565
ConstraintLocator *locator);
566566

567567
/// Create a restricted relational constraint.
@@ -575,13 +575,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
575575
ConstraintFix *fix, Type first, Type second,
576576
ConstraintLocator *locator);
577577

578-
/// Create a bind overload choice with a fix.
579-
/// Note: This constraint is going to be disabled by default.
580-
static Constraint *createFixedChoice(ConstraintSystem &cs, Type type,
581-
OverloadChoice choice,
582-
DeclContext *useDC, ConstraintFix *fix,
583-
ConstraintLocator *locator);
584-
585578
/// Create a new disjunction constraint.
586579
static Constraint *createDisjunction(ConstraintSystem &cs,
587580
ArrayRef<Constraint *> constraints,

lib/Sema/Constraint.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,8 @@ Constraint *Constraint::createMemberOrOuterDisjunction(
805805
memberConstraint->setFavored();
806806
for (auto choice : outerAlternatives) {
807807
constraints.push_back(
808-
Constraint::createBindOverload(cs, first, choice, useDC, locator));
808+
Constraint::createBindOverload(cs, first, choice, useDC, /*fix=*/nullptr,
809+
locator));
809810
}
810811
return Constraint::createDisjunction(cs, constraints, locator, ForgetChoice);
811812
}
@@ -856,8 +857,22 @@ Constraint *Constraint::createValueWitness(
856857
Constraint *Constraint::createBindOverload(ConstraintSystem &cs, Type type,
857858
OverloadChoice choice,
858859
DeclContext *useDC,
860+
ConstraintFix *fix,
859861
ConstraintLocator *locator) {
860-
return createFixedChoice(cs, type, choice, useDC, /*fix=*/nullptr, locator);
862+
// Collect type variables.
863+
SmallPtrSet<TypeVariableType *, 4> typeVars;
864+
if (type->hasTypeVariable())
865+
type->getTypeVariables(typeVars);
866+
if (auto baseType = choice.getBaseType()) {
867+
baseType->getTypeVariables(typeVars);
868+
}
869+
870+
// Create the constraint.
871+
auto size =
872+
totalSizeToAlloc<TypeVariableType *, ConstraintFix *, OverloadChoice>(
873+
typeVars.size(), fix ? 1 : 0, /*hasOverloadChoice=*/1);
874+
void *mem = cs.getAllocator().Allocate(size, alignof(Constraint));
875+
return new (mem) Constraint(type, choice, useDC, fix, locator, typeVars);
861876
}
862877

863878
Constraint *Constraint::createRestricted(ConstraintSystem &cs,
@@ -899,27 +914,6 @@ Constraint *Constraint::createFixed(ConstraintSystem &cs, ConstraintKind kind,
899914
return new (mem) Constraint(kind, fix, first, second, locator, typeVars);
900915
}
901916

902-
Constraint *Constraint::createFixedChoice(ConstraintSystem &cs, Type type,
903-
OverloadChoice choice,
904-
DeclContext *useDC,
905-
ConstraintFix *fix,
906-
ConstraintLocator *locator) {
907-
// Collect type variables.
908-
SmallPtrSet<TypeVariableType *, 4> typeVars;
909-
if (type->hasTypeVariable())
910-
type->getTypeVariables(typeVars);
911-
if (auto baseType = choice.getBaseType()) {
912-
baseType->getTypeVariables(typeVars);
913-
}
914-
915-
// Create the constraint.
916-
auto size =
917-
totalSizeToAlloc<TypeVariableType *, ConstraintFix *, OverloadChoice>(
918-
typeVars.size(), fix ? 1 : 0, /*hasOverloadChoice=*/1);
919-
void *mem = cs.getAllocator().Allocate(size, alignof(Constraint));
920-
return new (mem) Constraint(type, choice, useDC, fix, locator, typeVars);
921-
}
922-
923917
Constraint *Constraint::createDisjunction(ConstraintSystem &cs,
924918
ArrayRef<Constraint *> constraints,
925919
ConstraintLocator *locator,

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,10 +3831,8 @@ void ConstraintSystem::generateConstraints(
38313831
if (requiresFix && !fix)
38323832
return;
38333833

3834-
auto *choice = fix ? Constraint::createFixedChoice(*this, type, overload,
3835-
useDC, fix, locator)
3836-
: Constraint::createBindOverload(*this, type, overload,
3837-
useDC, locator);
3834+
auto *choice = Constraint::createBindOverload(*this, type, overload,
3835+
useDC, fix, locator);
38383836

38393837
if (isFavored)
38403838
choice->setFavored();

0 commit comments

Comments
 (0)