Skip to content

Commit ef86e9e

Browse files
[ConstraintSystem] Adding new score kind SK_FunctionToAutoClosureConversion to increase impact of a function to autoclosure
1 parent 1c86133 commit ef86e9e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,10 @@ enum ScoreKind {
802802
SK_KeyPathSubscript,
803803
/// A conversion from a string, array, or inout to a pointer.
804804
SK_ValueToPointerConversion,
805+
/// A closure/function conversion to an autoclosure parameter.
806+
SK_FunctionToAutoClosureConversion,
805807

806-
SK_LastScoreKind = SK_ValueToPointerConversion,
808+
SK_LastScoreKind = SK_FunctionToAutoClosureConversion,
807809
};
808810

809811
/// The number of score kinds.

lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ static StringRef getScoreKindName(ScoreKind kind) {
8181

8282
case SK_ValueToPointerConversion:
8383
return "value-to-pointer conversion";
84+
85+
case SK_FunctionToAutoClosureConversion:
86+
return "function to autoclosure parameter";
8487
}
8588
}
8689

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
13551355
//
13561356
// f { } // OK
13571357
if (isExpr<ClosureExpr>(argExpr)) {
1358-
cs.increaseScore(SK_FunctionConversion);
1358+
cs.increaseScore(SK_FunctionToAutoClosureConversion);
13591359
}
13601360

13611361
// If the argument is not marked as @autoclosure or
@@ -2233,7 +2233,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
22332233
if (func1Param.isAutoClosure() &&
22342234
(!func2Param.isAutoClosure() &&
22352235
func2Param.getPlainType()->is<FunctionType>())) {
2236-
increaseScore(SK_FunctionConversion);
2236+
increaseScore(SK_FunctionToAutoClosureConversion);
22372237
}
22382238

22392239
// Variadic bit must match.

0 commit comments

Comments
 (0)