Skip to content

Commit a6933e2

Browse files
committed
---
yaml --- r: 317291 b: refs/heads/master-rebranch c: ff50ab5 h: refs/heads/master i: 317289: 044e0fc 317287: 5332226
1 parent b95b9a7 commit a6933e2

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: 3941c983ca6e3ce684ed0fb6ac02569fe4d7d685
1460+
refs/heads/master-rebranch: ff50ab5324c11223b520ea8446150f94906f8ecb

branches/master-rebranch/lib/Sema/CSBindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
423423
case ConstraintKind::ArgumentConversion:
424424
case ConstraintKind::OperatorArgumentConversion:
425425
case ConstraintKind::OptionalObject: {
426+
// If there is a `bind param` constraint associated with
427+
// current type variable, result should be aware of that
428+
// fact. Binding set might be incomplete until
429+
// this constraint is resolved, because we currently don't
430+
// look-through constraints expect to `subtype` to try and
431+
// find related bindings.
432+
if (constraint->getKind() == ConstraintKind::BindParam)
433+
result.PotentiallyIncomplete = true;
434+
426435
auto binding = getPotentialBindingForRelationalConstraint(
427436
result, constraint, hasDependentMemberRelationalConstraints,
428437
hasNonDependentMemberRelationalConstraints,

branches/master-rebranch/lib/Sema/ConstraintSystem.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,12 @@ class ConstraintSystem {
28062806
/// Whether the bindings of this type involve other type variables.
28072807
bool InvolvesTypeVariables = false;
28082808

2809+
/// Whether the bindings represent (potentially) incomplete set,
2810+
/// there is no way to say with absolute certainty if that's the
2811+
/// case, but that could happen when certain constraints like
2812+
/// `bind param` are present in the system.
2813+
bool PotentiallyIncomplete = false;
2814+
28092815
/// Whether this type variable has literal bindings.
28102816
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
28112817

@@ -2850,9 +2856,14 @@ class ConstraintSystem {
28502856
if (formBindingScore(y) < formBindingScore(x))
28512857
return false;
28522858

2853-
// If the only difference is default types,
2859+
// If there is a difference in number of default types,
28542860
// prioritize bindings with fewer of them.
2855-
return x.NumDefaultableBindings < y.NumDefaultableBindings;
2861+
if (x.NumDefaultableBindings != y.NumDefaultableBindings)
2862+
return x.NumDefaultableBindings < y.NumDefaultableBindings;
2863+
2864+
// As a last resort, let's check if the bindings are
2865+
// potentially incomplete, and if so, let's de-prioritize them.
2866+
return x.PotentiallyIncomplete < y.PotentiallyIncomplete;
28562867
}
28572868

28582869
void foundLiteralBinding(ProtocolDecl *proto) {
@@ -2885,6 +2896,8 @@ class ConstraintSystem {
28852896
void dump(llvm::raw_ostream &out,
28862897
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
28872898
out.indent(indent);
2899+
if (PotentiallyIncomplete)
2900+
out << "potentially_incomplete ";
28882901
if (FullyBound)
28892902
out << "fully_bound ";
28902903
if (SubtypeOfExistentialType)

branches/master-rebranch/test/Constraints/closures.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,11 @@ func test<Instances : Collection>(
797797
) { fatalError() }
798798

799799
test([1]) { _, _ in fatalError(); () }
800+
801+
// rdar://problem/45659733
802+
func rdar_45659733() {
803+
func foo<T : BinaryInteger>(_: AnyHashable, _: T) {}
804+
func bar(_ a: Int, _ b: Int) {
805+
_ = (a ..< b).map { i in foo(i, i) } // Ok
806+
}
807+
}

0 commit comments

Comments
 (0)