Skip to content

[4.1][CSSolver] Increment score when performing certain function conversions #14464

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 8, 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
6 changes: 5 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
return SolutionKind::Error;
if (kind < ConstraintKind::Subtype)
return SolutionKind::Error;

increaseScore(SK_FunctionConversion);
}

// A non-throwing function can be a subtype of a throwing function.
Expand Down Expand Up @@ -1880,8 +1882,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// If the 2nd type is an autoclosure, then we don't actually want to
// treat these as parallel. The first type needs wrapping in a closure
// despite already being a function type.
if (!func1->isAutoClosure() && func2->isAutoClosure())
if (!func1->isAutoClosure() && func2->isAutoClosure()) {
increaseScore(SK_FunctionConversion);
break;
}
return matchFunctionTypes(func1, func2, kind, flags, locator);
}

Expand Down
21 changes: 21 additions & 0 deletions test/Constraints/rdar37160679.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s

func foo(_ f: @autoclosure () -> Int) {}
func foo(_ f: () -> Int) {}

func bar(_ f: () throws -> Int) {}
func bar(_ f: () -> Int) {}

func baz(a1: @autoclosure () -> Int,
a2: () -> Int,
b1: () throws -> Int,
b2: () -> Int) {
// CHECK: function_ref @_T012rdar371606793fooySiyXKF
foo(a1)
// CHECK: function_ref @_T012rdar371606793fooySiycF
foo(a2)
// CHECK: function_ref @_T012rdar371606793barySiyKcF
bar(b1)
// CHECK: function_ref @_T012rdar371606793barySiycF
bar(b2)
}