Skip to content

Commit bd4c3ad

Browse files
committed
[CS] Make CSRanking change slightly less risky for 6.2
Check for `isSolverAllocated` rather than `hasTypeVariableOrPlaceholder`, and downgrade an `ASSERT` to `CONDITIONAL_ASSERT`.
1 parent cc66fc8 commit bd4c3ad

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,10 +1413,9 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
14131413
auto type1 = types.Type1;
14141414
auto type2 = types.Type2;
14151415

1416-
// If either of the types have holes or unresolved type variables, we can't
1417-
// compare them. `isSubtypeOf` cannot be used with solver-allocated types.
1418-
if (type1->hasTypeVariableOrPlaceholder() ||
1419-
type2->hasTypeVariableOrPlaceholder()) {
1416+
// `isSubtypeOf` cannot be used with solver-allocated types.
1417+
if (type1->getRecursiveProperties().isSolverAllocated() ||
1418+
type2->getRecursiveProperties().isSolverAllocated()) {
14201419
identical = false;
14211420
continue;
14221421
}
@@ -1468,12 +1467,15 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
14681467
// The systems are not considered equivalent.
14691468
identical = false;
14701469

1471-
// Archetypes are worse than concrete types
1470+
// Archetypes are worse than concrete types (i.e. non-placeholder and
1471+
// non-archetype)
14721472
// FIXME: Total hack.
1473-
if (type1->is<ArchetypeType>() && !type2->is<ArchetypeType>()) {
1473+
if (type1->is<ArchetypeType>() && !type2->is<ArchetypeType>() &&
1474+
!type2->is<PlaceholderType>()) {
14741475
++score2;
14751476
continue;
1476-
} else if (type2->is<ArchetypeType>() && !type1->is<ArchetypeType>()) {
1477+
} else if (type2->is<ArchetypeType>() && !type1->is<ArchetypeType>() &&
1478+
!type1->is<PlaceholderType>()) {
14771479
++score1;
14781480
continue;
14791481
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,10 @@ bool TypeChecker::typesSatisfyConstraint(Type type1, Type type2,
10601060
// avoid lifetime issues for e.g cases where we lazily populate the
10611061
// `ContextSubMap` on `NominalOrBoundGenericNominalType` in the nested arena,
10621062
// since it will be destroyed on leaving.
1063-
ASSERT(!type1->getRecursiveProperties().isSolverAllocated() &&
1064-
!type2->getRecursiveProperties().isSolverAllocated() &&
1065-
"Cannot escape solver-allocated types into a nested ConstraintSystem");
1063+
CONDITIONAL_ASSERT(
1064+
!type1->getRecursiveProperties().isSolverAllocated() &&
1065+
!type2->getRecursiveProperties().isSolverAllocated() &&
1066+
"Cannot escape solver-allocated types into a nested ConstraintSystem");
10661067

10671068
ConstraintSystem cs(dc, ConstraintSystemOptions());
10681069
if (openArchetypes) {

0 commit comments

Comments
 (0)