Skip to content

Commit 9642ff0

Browse files
authored
Merge pull request #12235 from xedin/fix-subtype-revert
Revert "[ConstraintSolver] Prioritize certain type variables while lo…
2 parents ff53359 + 695bacc commit 9642ff0

File tree

4 files changed

+7
-62
lines changed

4 files changed

+7
-62
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
361361
ConstraintClassification::Relational &&
362362
"only relational constraints handled here");
363363

364-
// Record constraint which contributes to the
365-
// finding of pontential bindings.
366-
result.Sources.insert(constraint);
367-
368364
auto first = simplifyType(constraint->getFirstType());
369365
auto second = simplifyType(constraint->getSecondType());
370366

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,14 +1695,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
16951695
}
16961696

16971697
// If we have a binding for the right-hand side
1698-
// (argument type used in the body) don't try
1699-
// to bind it to the left-hand side (parameter type)
1700-
// directly, because there could be an implicit
1701-
// conversion between them, and actual binding
1702-
// can only come from the left-hand side.
1698+
// (argument type) don't try to bind it to the left-hand
1699+
// side (parameter type) directly, because their
1700+
// relationship is contravariant and the actual
1701+
// binding can only come from the left-hand side.
17031702
addUnsolvedConstraint(
1704-
Constraint::create(*this, ConstraintKind::Equal, typeVar1, type2,
1705-
getConstraintLocator(locator)));
1703+
Constraint::create(*this, ConstraintKind::ArgumentConversion, type2,
1704+
typeVar1, getConstraintLocator(locator)));
17061705
return SolutionKind::Solved;
17071706
}
17081707

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "swift/AST/TypeCheckerDebugConsumer.h"
3434
#include "llvm/ADT/ilist.h"
3535
#include "llvm/ADT/PointerUnion.h"
36-
#include "llvm/ADT/SetOperations.h"
3736
#include "llvm/ADT/SetVector.h"
3837
#include "llvm/ADT/SmallPtrSet.h"
3938
#include "llvm/Support/ErrorHandling.h"
@@ -2578,9 +2577,6 @@ class ConstraintSystem {
25782577
/// Tracks the position of the last known supertype in the group.
25792578
Optional<unsigned> lastSupertypeIndex;
25802579

2581-
/// A set of all constraints which contribute to pontential bindings.
2582-
llvm::SmallPtrSet<Constraint *, 8> Sources;
2583-
25842580
PotentialBindings(TypeVariableType *typeVar) : TypeVar(typeVar) {}
25852581

25862582
/// Determine whether the set of bindings is non-empty.
@@ -2604,29 +2600,7 @@ class ConstraintSystem {
26042600
/// \c x is a better set of bindings that \c y.
26052601
friend bool operator<(const PotentialBindings &x,
26062602
const PotentialBindings &y) {
2607-
if (formBindingScore(x) < formBindingScore(y))
2608-
return true;
2609-
2610-
if (!x.hasNonDefaultableBindings())
2611-
return false;
2612-
2613-
llvm::SmallPtrSet<Constraint *, 8> intersection(x.Sources);
2614-
llvm::set_intersect(intersection, y.Sources);
2615-
2616-
// Some relational constraints dictate certain
2617-
// ordering when it comes to attempting binding
2618-
// of type variables, where left-hand side is
2619-
// always more preferrable than right-hand side.
2620-
for (const auto *constraint : intersection) {
2621-
if (constraint->getKind() != ConstraintKind::Subtype)
2622-
continue;
2623-
2624-
auto lhs = constraint->getFirstType();
2625-
if (auto *typeVar = lhs->getAs<TypeVariableType>())
2626-
return x.TypeVar == typeVar;
2627-
}
2628-
2629-
return false;
2603+
return formBindingScore(x) < formBindingScore(y);
26302604
}
26312605

26322606
void foundLiteralBinding(ProtocolDecl *proto) {

test/Constraints/generics.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -504,27 +504,3 @@ func rdar27700622<E: Comparable>(_ input: [E]) -> [E] {
504504

505505
return rdar27700622(lhs) + [pivot] + rdar27700622(rhs) // Ok
506506
}
507-
508-
// rdar://problem/22898292 - Type inference failure with constrained subclass
509-
protocol P_22898292 {}
510-
511-
do {
512-
func construct_generic<T: P_22898292>(_ construct: () -> T) -> T { return construct() }
513-
514-
class A {}
515-
class B : A, P_22898292 {}
516-
517-
func foo() -> B { return B() }
518-
func bar(_ value: A) {}
519-
func baz<T: A>(_ value: T) {}
520-
521-
func rdar_22898292_1() {
522-
let x = construct_generic { foo() } // returns A
523-
bar(x) // Ok
524-
bar(construct_generic { foo() }) // Ok
525-
}
526-
527-
func rdar22898292_2<T: B>(_ d: T) {
528-
_ = { baz($0) }(construct_generic { d }) // Ok
529-
}
530-
}

0 commit comments

Comments
 (0)