[NFC] Simplify function type representation checks.

This commit is contained in:
Varun Gandhi
2021-01-15 11:30:38 -08:00
parent 66dfea141c
commit 3301ae90e0
2 changed files with 43 additions and 29 deletions

View File

@@ -1552,22 +1552,9 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
static bool
isSubtypeOf(FunctionTypeRepresentation potentialSubRepr,
FunctionTypeRepresentation potentialSuperRepr) {
auto isThin = [](FunctionTypeRepresentation rep) {
return rep == FunctionTypeRepresentation::CFunctionPointer ||
rep == FunctionTypeRepresentation::Thin;
};
// Allowing "thin" (c, thin) to "thin" conversions
if (isThin(potentialSubRepr) && isThin(potentialSuperRepr))
return true;
// Allowing all to "thick" (swift, block) conversions
// "thin" (c, thin) to "thick" or "thick" to "thick"
if (potentialSuperRepr == FunctionTypeRepresentation::Swift ||
potentialSuperRepr == FunctionTypeRepresentation::Block)
return true;
return potentialSubRepr == potentialSuperRepr;
return (potentialSubRepr == potentialSuperRepr)
|| isThinRepresentation(potentialSubRepr)
|| isThickRepresentation(potentialSuperRepr);
}
/// Returns true if `constraint rep1 rep2` is satisfied.