Skip to content

[4.1][CSSolver] Prioritize bindings with fewer default types #14538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,9 @@ class ConstraintSystem {
if (!x.hasNonDefaultableBindings())
return false;

if (x.FullyBound || x.SubtypeOfExistentialType)
return false;

llvm::SmallPtrSet<Constraint *, 8> intersection(x.Sources);
llvm::set_intersect(intersection, y.Sources);

Expand All @@ -2655,7 +2658,9 @@ class ConstraintSystem {
return x.TypeVar == typeVar;
}

return false;
// If the only difference is default types,
// prioritize bindings with fewer of them.
return x.NumDefaultableBindings < y.NumDefaultableBindings;
}

void foundLiteralBinding(ProtocolDecl *proto) {
Expand Down
7 changes: 7 additions & 0 deletions test/Constraints/operator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,10 @@ struct S_35740653 {
func rdar35740653(val: S_35740653) {
let _ = 0...Int(val / .value(1.0 / 42.0)) // Ok
}

protocol P_37290898 {}
struct S_37290898: P_37290898 {}

func rdar37290898(_ arr: inout [P_37290898], _ element: S_37290898?) {
arr += [element].compactMap { $0 } // Ok
}