Skip to content

Commit 6fb6d1c

Browse files
committed
[CSOptimizer] Enable ranking of Int*, Float{80} and Double initializers
1 parent 8818d39 commit 6fb6d1c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/Sema/CSOptimizer.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ using namespace constraints;
3434

3535
namespace {
3636

37+
// TODO: both `isIntegerType` and `isFloatType` should be available on Type
38+
// as `isStdlib{Integer, Float}Type`.
39+
40+
static bool isIntegerType(Type type) {
41+
return type->isInt() || type->isInt8() || type->isInt16() ||
42+
type->isInt32() || type->isInt64() || type->isUInt() ||
43+
type->isUInt8() || type->isUInt16() || type->isUInt32() ||
44+
type->isUInt64();
45+
}
46+
47+
static bool isFloatType(Type type) {
48+
return type->isFloat() || type->isDouble() || type->isFloat80();
49+
}
50+
3751
static bool isSupportedOperator(Constraint *disjunction) {
3852
if (!isOperatorDisjunction(disjunction))
3953
return false;
@@ -57,6 +71,16 @@ static bool isSupportedOperator(Constraint *disjunction) {
5771
return false;
5872
}
5973

74+
static bool isSupportedSpecialConstructor(ConstructorDecl *ctor) {
75+
if (auto *selfDecl = ctor->getImplicitSelfDecl()) {
76+
auto selfTy = selfDecl->getInterfaceType();
77+
/// Support `Int*`, `Float*` and `Double` initializers since their generic
78+
/// overloads are not too complicated.
79+
return selfTy && (isIntegerType(selfTy) || isFloatType(selfTy));
80+
}
81+
return false;
82+
}
83+
6084
static bool isStandardComparisonOperator(ValueDecl *decl) {
6185
return decl->isOperator() &&
6286
decl->getBaseIdentifier().isStandardComparisonOperator();
@@ -72,6 +96,12 @@ static bool isSupportedDisjunction(Constraint *disjunction) {
7296
if (isSupportedOperator(disjunction))
7397
return true;
7498

99+
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(
100+
getOverloadChoiceDecl(choices.front()))) {
101+
if (isSupportedSpecialConstructor(ctor))
102+
return true;
103+
}
104+
75105
// Non-operator disjunctions are supported only if they don't
76106
// have any generic choices.
77107
return llvm::all_of(choices, [&](Constraint *choice) {

0 commit comments

Comments
 (0)