Skip to content

Commit 51f6e66

Browse files
authored
Merge pull request #72755 from hborla/disjunction-variable-ordering
[ConstraintSystem] Order `VarDecl`s before other kinds of decls in disjunctions.
2 parents 293a434 + a3ac8ec commit 51f6e66

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ struct DatabaseLog {
1616
}
1717
}
1818

19-
extension Sequence {
20-
public func count(
21-
where predicate: (Element) throws -> Bool
22-
) rethrows -> Int { 0 }
23-
}
24-
2519

2620
func rdar47742750(arr1: [Int], arr2: [Int]?) {
2721
let _ = {
2822
assert(arr1.count == arr1.count + (arr2 == nil ? 0 : 1 + arr2!.count + arr2!.count + arr2!.count))
2923
}
3024
}
25+
26+
func f(
27+
a: String?,
28+
b: String?,
29+
c: Int,
30+
d: String?,
31+
e: String?
32+
) -> Int {
33+
return (a?.unicodeScalars.count ?? 0) +
34+
(b?.unicodeScalars.count ?? 0) +
35+
c +
36+
(d?.unicodeScalars.count ?? 0) +
37+
(e?.unicodeScalars.count ?? 0)
38+
}

0 commit comments

Comments
 (0)