Skip to content

Commit 563ba95

Browse files
committed
Sema: Move definition of hasConversions() before its first use
1 parent db4e3b0 commit 563ba95

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ void ConstraintGraphNode::initBindingSet() {
3838
Set.emplace(CG.getConstraintSystem(), TypeVar, Potential);
3939
}
4040

41-
/// Check whether there exists a type that could be implicitly converted
42-
/// to a given type i.e. is the given type is Double or Optional<..> this
43-
/// function is going to return true because CGFloat could be converted
44-
/// to a Double and non-optional value could be injected into an optional.
45-
static bool hasConversions(Type);
46-
4741
BindingSet::BindingSet(ConstraintSystem &CS, TypeVariableType *TypeVar,
4842
const PotentialBindings &info)
4943
: CS(CS), TypeVar(TypeVar), Info(info) {
@@ -1340,6 +1334,40 @@ static bool checkTypeOfBinding(TypeVariableType *typeVar, Type type) {
13401334
return true;
13411335
}
13421336

1337+
/// Check whether there exists a type that could be implicitly converted
1338+
/// to a given type i.e. is the given type is Double or Optional<..> this
1339+
/// function is going to return true because CGFloat could be converted
1340+
/// to a Double and non-optional value could be injected into an optional.
1341+
static bool hasConversions(Type type) {
1342+
if (type->isAnyHashable() || type->isDouble() || type->isCGFloat())
1343+
return true;
1344+
1345+
if (type->getAnyPointerElementType())
1346+
return true;
1347+
1348+
if (auto *structTy = type->getAs<BoundGenericStructType>()) {
1349+
if (auto eltTy = structTy->getArrayElementType()) {
1350+
return hasConversions(eltTy);
1351+
} else if (auto pair = ConstraintSystem::isDictionaryType(structTy)) {
1352+
return hasConversions(pair->second);
1353+
} else if (auto eltTy = ConstraintSystem::isSetType(structTy)) {
1354+
return hasConversions(*eltTy);
1355+
}
1356+
1357+
return false;
1358+
}
1359+
1360+
if (auto *enumTy = type->getAs<BoundGenericEnumType>()) {
1361+
if (enumTy->getOptionalObjectType())
1362+
return true;
1363+
1364+
return false;
1365+
}
1366+
1367+
return !(type->is<StructType>() || type->is<EnumType>() ||
1368+
type->is<BuiltinType>() || type->is<ArchetypeType>());
1369+
}
1370+
13431371
bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
13441372
// Prevent against checking against the same opened nominal type
13451373
// over and over again. Doing so means redundant work in the best
@@ -1416,36 +1444,6 @@ bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
14161444
return true;
14171445
}
14181446

1419-
static bool hasConversions(Type type) {
1420-
if (type->isAnyHashable() || type->isDouble() || type->isCGFloat())
1421-
return true;
1422-
1423-
if (type->getAnyPointerElementType())
1424-
return true;
1425-
1426-
if (auto *structTy = type->getAs<BoundGenericStructType>()) {
1427-
if (auto eltTy = structTy->getArrayElementType()) {
1428-
return hasConversions(eltTy);
1429-
} else if (auto pair = ConstraintSystem::isDictionaryType(structTy)) {
1430-
return hasConversions(pair->second);
1431-
} else if (auto eltTy = ConstraintSystem::isSetType(structTy)) {
1432-
return hasConversions(*eltTy);
1433-
}
1434-
1435-
return false;
1436-
}
1437-
1438-
if (auto *enumTy = type->getAs<BoundGenericEnumType>()) {
1439-
if (enumTy->getOptionalObjectType())
1440-
return true;
1441-
1442-
return false;
1443-
}
1444-
1445-
return !(type->is<StructType>() || type->is<EnumType>() ||
1446-
type->is<BuiltinType>() || type->is<ArchetypeType>());
1447-
}
1448-
14491447
bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
14501448
if (isHole())
14511449
return false;

0 commit comments

Comments
 (0)