Skip to content

Commit baccbde

Browse files
[CSSimplify] Simplify logic for valiting to thick conversion on subtype
1 parent bacbc57 commit baccbde

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
13541354
static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
13551355
FunctionTypeRepresentation rep2,
13561356
ConstraintKind kind,
1357-
ConstraintLocator *locator) {
1357+
ConstraintLocatorBuilder locator) {
13581358
switch (kind) {
13591359
case ConstraintKind::Bind:
13601360
case ConstraintKind::BindParam:
@@ -1363,25 +1363,14 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
13631363
return rep1 != rep2;
13641364

13651365
case ConstraintKind::Subtype: {
1366-
if (!locator->isLastElement<LocatorPathElt::FunctionArgument>())
1367-
return false;
1368-
1369-
auto isThin = [](FunctionTypeRepresentation rep) {
1370-
return rep == FunctionTypeRepresentation::CFunctionPointer ||
1371-
rep == FunctionTypeRepresentation::Thin;
1372-
};
1373-
1374-
auto isThick = [](FunctionTypeRepresentation rep) {
1375-
return rep == FunctionTypeRepresentation::Swift ||
1376-
rep == swift::FunctionTypeRepresentation::Block;
1377-
};
1378-
1379-
// Allowing conventions "thin" (c, thin) to "thick" (swift, block)
1380-
if (isThin(rep1) && isThick(rep2))
1366+
auto last = locator.last();
1367+
if (!(last && last->is<LocatorPathElt::FunctionArgument>()))
13811368
return false;
13821369

1383-
// Allowing conventions "thick" (swift, block) to "thick" (swift, block)
1384-
if (isThick(rep1) && isThick(rep2))
1370+
// Allowing all to "thick" (swift, block) conventions
1371+
// "thin" (c, thin) to "thick" or "thick" to "thick"
1372+
if (rep2 == FunctionTypeRepresentation::Swift ||
1373+
rep2 == FunctionTypeRepresentation::Block)
13851374
return false;
13861375

13871376
return rep1 != rep2;
@@ -1682,7 +1671,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
16821671

16831672
if (matchFunctionRepresentations(func1->getExtInfo().getRepresentation(),
16841673
func2->getExtInfo().getRepresentation(),
1685-
kind, getConstraintLocator(locator))) {
1674+
kind, locator)) {
16861675
return getTypeMatchFailure(locator);
16871676
}
16881677

0 commit comments

Comments
 (0)