Skip to content

Commit b96e34c

Browse files
authored
Merge pull request swiftlang#33042 from DougGregor/edge-contract-only-bind-param
[Constraint system] Limit edge contraction to BindParam.
2 parents 5a1f061 + fb95c7d commit b96e34c

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

lib/Sema/ConstraintGraph.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,7 @@ ConstraintGraph::computeConnectedComponents(
10681068
/// edge in the graph.
10691069
static bool shouldContractEdge(ConstraintKind kind) {
10701070
switch (kind) {
1071-
case ConstraintKind::Bind:
10721071
case ConstraintKind::BindParam:
1073-
case ConstraintKind::BindToPointerType:
1074-
case ConstraintKind::Equal:
10751072
return true;
10761073

10771074
default:
@@ -1103,8 +1100,6 @@ bool ConstraintGraph::contractEdges() {
11031100
if (!(tyvar1 && tyvar2))
11041101
continue;
11051102

1106-
auto isParamBindingConstraint = kind == ConstraintKind::BindParam;
1107-
11081103
// If the argument is allowed to bind to `inout`, in general,
11091104
// it's invalid to contract the edge between argument and parameter,
11101105
// but if we can prove that there are no possible bindings
@@ -1114,7 +1109,7 @@ bool ConstraintGraph::contractEdges() {
11141109
// Such action is valid because argument type variable can
11151110
// only get its bindings from related overload, which gives
11161111
// us enough information to decided on l-valueness.
1117-
if (isParamBindingConstraint && tyvar1->getImpl().canBindToInOut()) {
1112+
if (tyvar1->getImpl().canBindToInOut()) {
11181113
bool isNotContractable = true;
11191114
if (auto bindings = CS.inferBindingsFor(tyvar1)) {
11201115
// Holes can't be contracted.
@@ -1146,26 +1141,21 @@ bool ConstraintGraph::contractEdges() {
11461141
auto rep1 = CS.getRepresentative(tyvar1);
11471142
auto rep2 = CS.getRepresentative(tyvar2);
11481143

1149-
if (((rep1->getImpl().canBindToLValue() ==
1150-
rep2->getImpl().canBindToLValue()) ||
1151-
// Allow l-value contractions when binding parameter types.
1152-
isParamBindingConstraint)) {
1153-
if (CS.isDebugMode()) {
1154-
auto &log = llvm::errs();
1155-
if (CS.solverState)
1156-
log.indent(CS.solverState->depth * 2);
1157-
1158-
log << "Contracting constraint ";
1159-
constraint->print(log, &CS.getASTContext().SourceMgr);
1160-
log << "\n";
1161-
}
1144+
if (CS.isDebugMode()) {
1145+
auto &log = llvm::errs();
1146+
if (CS.solverState)
1147+
log.indent(CS.solverState->depth * 2);
11621148

1163-
// Merge the edges and retire the constraint.
1164-
CS.retireConstraint(constraint);
1165-
if (rep1 != rep2)
1166-
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
1167-
didContractEdges = true;
1149+
log << "Contracting constraint ";
1150+
constraint->print(log, &CS.getASTContext().SourceMgr);
1151+
log << "\n";
11681152
}
1153+
1154+
// Merge the edges and retire the constraint.
1155+
CS.retireConstraint(constraint);
1156+
if (rep1 != rep2)
1157+
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
1158+
didContractEdges = true;
11691159
}
11701160
return didContractEdges;
11711161
}

0 commit comments

Comments
 (0)