Skip to content

Commit a405fff

Browse files
committed
[CSOptimizer] favor Any.Type for metatype args alongside Any fast-path
Resolves #85020
1 parent d350bc7 commit a405fff

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
@@ -1429,11 +1429,22 @@ static void determineBestChoicesInContext(
14291429
}
14301430
}
14311431

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

14381449
// Check if a candidate could be matched to a parameter by
14391450
// an existential opening.

0 commit comments

Comments
 (0)