Skip to content

Commit 8f2f14b

Browse files
[CSSimplify] Modify logic on match representations to allow ONLY thick to thin and thick to thick representations on subtype context
1 parent 3eb82c1 commit 8f2f14b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,16 +1353,41 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
13531353
// corresponding function type representations and the given match kind.
13541354
static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
13551355
FunctionTypeRepresentation rep2,
1356-
ConstraintKind kind) {
1356+
ConstraintKind kind,
1357+
ConstraintLocator *locator) {
13571358
switch (kind) {
13581359
case ConstraintKind::Bind:
13591360
case ConstraintKind::BindParam:
13601361
case ConstraintKind::BindToPointerType:
13611362
case ConstraintKind::Equal:
13621363
return rep1 != rep2;
1364+
1365+
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))
1381+
return false;
1382+
1383+
// Allowing conventions "thick" (swift, block) to "thick" (swift, block)
1384+
if (isThick(rep1) && isThick(rep2))
1385+
return false;
1386+
1387+
return rep1 != rep2;
1388+
}
13631389

13641390
case ConstraintKind::OpaqueUnderlyingType:
1365-
case ConstraintKind::Subtype:
13661391
case ConstraintKind::Conversion:
13671392
case ConstraintKind::BridgingConversion:
13681393
case ConstraintKind::ArgumentConversion:
@@ -1657,7 +1682,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
16571682

16581683
if (matchFunctionRepresentations(func1->getExtInfo().getRepresentation(),
16591684
func2->getExtInfo().getRepresentation(),
1660-
kind)) {
1685+
kind, getConstraintLocator(locator))) {
16611686
return getTypeMatchFailure(locator);
16621687
}
16631688

0 commit comments

Comments
 (0)