Skip to content

Commit db4e3b0

Browse files
committed
Sema: Move definition of checkTypeOfBinding() before its first use
1 parent 2eebdc3 commit db4e3b0

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ void ConstraintGraphNode::initBindingSet() {
4444
/// to a Double and non-optional value could be injected into an optional.
4545
static bool hasConversions(Type);
4646

47-
static bool checkTypeOfBinding(TypeVariableType *typeVar, Type type);
48-
4947
BindingSet::BindingSet(ConstraintSystem &CS, TypeVariableType *TypeVar,
5048
const PotentialBindings &info)
5149
: CS(CS), TypeVar(TypeVar), Info(info) {
@@ -1311,6 +1309,37 @@ void PotentialBindings::addPotentialBinding(TypeVariableType *TypeVar,
13111309
Bindings.push_back(std::move(binding));
13121310
}
13131311

1312+
/// Check whether the given type can be used as a binding for the given
1313+
/// type variable.
1314+
///
1315+
/// \returns true if the binding is okay.
1316+
static bool checkTypeOfBinding(TypeVariableType *typeVar, Type type) {
1317+
// If the type references the type variable, don't permit the binding.
1318+
if (type->hasTypeVariable()) {
1319+
SmallPtrSet<TypeVariableType *, 4> referencedTypeVars;
1320+
type->getTypeVariables(referencedTypeVars);
1321+
if (referencedTypeVars.count(typeVar))
1322+
return false;
1323+
}
1324+
1325+
{
1326+
auto objType = type->getWithoutSpecifierType();
1327+
1328+
// If the type is a type variable itself, don't permit the binding.
1329+
if (objType->is<TypeVariableType>())
1330+
return false;
1331+
1332+
// Don't bind to a dependent member type, even if it's currently
1333+
// wrapped in any number of optionals, because binding producer
1334+
// might unwrap and try to attempt it directly later.
1335+
if (objType->lookThroughAllOptionalTypes()->is<DependentMemberType>())
1336+
return false;
1337+
}
1338+
1339+
// Okay, allow the binding.
1340+
return true;
1341+
}
1342+
13141343
bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
13151344
// Prevent against checking against the same opened nominal type
13161345
// over and over again. Doing so means redundant work in the best
@@ -1568,37 +1597,6 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar) {
15681597
return bindings;
15691598
}
15701599

1571-
/// Check whether the given type can be used as a binding for the given
1572-
/// type variable.
1573-
///
1574-
/// \returns true if the binding is okay.
1575-
static bool checkTypeOfBinding(TypeVariableType *typeVar, Type type) {
1576-
// If the type references the type variable, don't permit the binding.
1577-
if (type->hasTypeVariable()) {
1578-
SmallPtrSet<TypeVariableType *, 4> referencedTypeVars;
1579-
type->getTypeVariables(referencedTypeVars);
1580-
if (referencedTypeVars.count(typeVar))
1581-
return false;
1582-
}
1583-
1584-
{
1585-
auto objType = type->getWithoutSpecifierType();
1586-
1587-
// If the type is a type variable itself, don't permit the binding.
1588-
if (objType->is<TypeVariableType>())
1589-
return false;
1590-
1591-
// Don't bind to a dependent member type, even if it's currently
1592-
// wrapped in any number of optionals, because binding producer
1593-
// might unwrap and try to attempt it directly later.
1594-
if (objType->lookThroughAllOptionalTypes()->is<DependentMemberType>())
1595-
return false;
1596-
}
1597-
1598-
// Okay, allow the binding.
1599-
return true;
1600-
}
1601-
16021600
std::optional<PotentialBinding>
16031601
PotentialBindings::inferFromRelational(ConstraintSystem &CS,
16041602
TypeVariableType *TypeVar,

0 commit comments

Comments
 (0)