Skip to content

Commit 2ca4dc7

Browse files
committed
[6.3][CSOptimizer] favor Any.Type for metatype args alongside Any fast-path
Resolves #85020
1 parent 24e4156 commit 2ca4dc7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,11 +1434,22 @@ static void determineBestChoicesInContext(
14341434
}
14351435
}
14361436

1437-
// If the parameter is `Any` we assume that all candidates are
1438-
// convertible to it, which makes it a perfect match. The solver
1439-
// would then decide whether erasing to an existential is preferable.
1440-
if (paramType->isAny())
1441-
return 1;
1437+
if (paramType->isAnyExistentialType()) {
1438+
// If the parameter is `Any` we assume that all candidates are
1439+
// convertible to it, which makes it a perfect match. The solver
1440+
// would then decide whether erasing to an existential is preferable.
1441+
if (paramType->isAny())
1442+
return 1;
1443+
1444+
// If the parameter is `Any.Type` we assume that all metatype
1445+
// candidates are convertible to it.
1446+
if (auto *EMT = paramType->getAs<ExistentialMetatypeType>()) {
1447+
if (EMT->getExistentialInstanceType()->isAny() &&
1448+
(candidateType->is<ExistentialMetatypeType>() ||
1449+
candidateType->is<MetatypeType>()))
1450+
return 1;
1451+
}
1452+
}
14421453

14431454
// Check if a candidate could be matched to a parameter by
14441455
// an existential opening.

0 commit comments

Comments
 (0)