Skip to content

Commit 0a617a8

Browse files
committed
[ConstraintSystem] Fail transitive conformance constraints without checking
implicit conversions if the type does not conform and the current score is equal to the best score. Implicit conversions will always increase the score, so if the current score is equal to the best score and an implicit conversion is needed to satisfy a conformance requirement, the solver would end up pruning that path later on anyway. It's better to fail early.
1 parent ab594dd commit 0a617a8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6479,6 +6479,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
64796479
// If the type doesn't conform, let's check whether
64806480
// an Optional or Unsafe{Mutable}Pointer from it would.
64816481

6482+
// If the current score is equal to the best score, fail without checking
6483+
// implicit conversions, because an implicit conversion would lead to a
6484+
// worse score anyway.
6485+
if (solverState && solverState->BestScore && CurrentScore == *solverState->BestScore)
6486+
return SolutionKind::Error;
6487+
64826488
SmallVector<Type, 4> typesToCheck;
64836489

64846490
// T -> Optional<T>

0 commit comments

Comments
 (0)