Skip to content

Commit 8834861

Browse files
committed
[ConstraintSystem] Order VarDecls before other kinds of decls in disjunctions.
1 parent 3bc570f commit 8834861

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,18 @@ void DisjunctionChoiceProducer::partitionDisjunction(
23652365
return true;
23662366
}
23672367

2368+
// Order VarDecls before other kinds of declarations because they are
2369+
// effectively favored over functions when the two are in the same
2370+
// overload set. This disjunction order allows SK_UnappliedFunction
2371+
// to prune later overload choices that are functions when a solution
2372+
// has already been found with a property.
2373+
if (auto *decl = getOverloadChoiceDecl(constraint)) {
2374+
if (isa<VarDecl>(decl)) {
2375+
everythingElse.push_back(index);
2376+
return true;
2377+
}
2378+
}
2379+
23682380
return false;
23692381
});
23702382

validation-test/Sema/type_checker_perf/fast/property_vs_unapplied_func.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ func rdar47742750(arr1: [Int], arr2: [Int]?) {
2828
assert(arr1.count == arr1.count + (arr2 == nil ? 0 : 1 + arr2!.count + arr2!.count + arr2!.count))
2929
}
3030
}
31+
32+
func f(
33+
a: String?,
34+
b: String?,
35+
c: Int,
36+
d: String?,
37+
e: String?
38+
) -> Int {
39+
return (a?.unicodeScalars.count ?? 0) +
40+
(b?.unicodeScalars.count ?? 0) +
41+
c +
42+
(d?.unicodeScalars.count ?? 0) +
43+
(e?.unicodeScalars.count ?? 0)
44+
}

0 commit comments

Comments
 (0)