Skip to content

Commit 248c3af

Browse files
Merge pull request #78320 from AnthonyLatsis/nymphaea-rubra
Sema: Small `matchPackExpansionTypes` cleanup
2 parents 9dad512 + 0b20482 commit 248c3af

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,40 +2405,31 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
24052405
}
24062406
}
24072407

2408-
// If both sides are expanded or neither side is, just match them
2408+
auto *const pack1 = pattern1->getAs<PackType>();
2409+
auto *const pack2 = pattern2->getAs<PackType>();
2410+
2411+
// If both sides are expanded or neither side is, proceed to matching them
24092412
// directly.
2410-
if (pattern1->is<PackType>() == pattern2->is<PackType>()) {
2411-
return matchTypes(pattern1, pattern2, kind, flags, locator);
2412-
2413-
// If the right hand side is expanded, we have something like
2414-
// Foo<$T0>... vs Pack{Foo<Int>, Foo<String>}...; We're going to
2415-
// bind $T0 to Pack{Int, String}.
2416-
} else if (!pattern1->is<PackType>() && pattern2->is<PackType>()) {
2417-
if (auto *pack2 = pattern2->getAs<PackType>()) {
2418-
if (auto *pack1 = replaceTypeVariablesWithFreshPacks(
2419-
*this, pattern1, pack2, locator)) {
2420-
addConstraint(kind, pack1, pack2, locator);
2421-
return getTypeMatchSuccess();
2422-
}
2413+
// Otherwise, we have something like `Foo<$T0>` vs.
2414+
// `Pack{Foo<Int>, Foo<String>}` or vice versa.
2415+
// We're going to bind `$T0` to `Pack{Int, String}` and unfold `Foo<$T0>` into
2416+
// `Pack{Foo<$T3>, Foo<$T4>} first.
2417+
if ((bool)pack1 != (bool)pack2) {
2418+
if (pack1) {
2419+
pattern2 =
2420+
replaceTypeVariablesWithFreshPacks(*this, pattern2, pack1, locator);
2421+
} else {
2422+
pattern1 =
2423+
replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
24232424
}
24242425

2425-
return getTypeMatchFailure(locator);
2426-
2427-
// If the left hand side is expanded, we have something like
2428-
// Pack{Foo<Int>, Foo<String>}... vs Foo<$T0>...; We're going to
2429-
// bind $T0 to Pack{Int, String}.
2430-
} else {
2431-
assert(pattern1->is<PackType>() && !pattern2->is<PackType>());
2432-
if (auto *pack1 = pattern1->getAs<PackType>()) {
2433-
if (auto *pack2 = replaceTypeVariablesWithFreshPacks(
2434-
*this, pattern2, pack1, locator)) {
2435-
addConstraint(kind, pack1, pack2, locator);
2436-
return getTypeMatchSuccess();
2437-
}
2426+
if (!(pattern1 && pattern2)) {
2427+
return getTypeMatchFailure(locator);
24382428
}
2439-
2440-
return getTypeMatchFailure(locator);
24412429
}
2430+
2431+
// Continue matching.
2432+
return matchTypes(pattern1, pattern2, kind, flags, locator);
24422433
}
24432434

24442435
/// Check where a representation is a subtype of another.

0 commit comments

Comments
 (0)