@@ -1608,18 +1608,25 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1608
1608
1609
1609
// If either (or both) types are type variables, unify the type variables.
1610
1610
if (typeVar1 || typeVar2) {
1611
+ // Handle the easy case of both being type variables, and being
1612
+ // identical, first.
1613
+ if (typeVar1 && typeVar2) {
1614
+ auto rep1 = getRepresentative (typeVar1);
1615
+ auto rep2 = getRepresentative (typeVar2);
1616
+ if (rep1 == rep2) {
1617
+ // We already merged these two types, so this constraint is
1618
+ // trivially solved.
1619
+ return SolutionKind::Solved;
1620
+ }
1621
+ }
1622
+
1611
1623
switch (kind) {
1612
1624
case ConstraintKind::Bind:
1613
1625
case ConstraintKind::BindToPointerType:
1614
1626
case ConstraintKind::Equal: {
1615
1627
if (typeVar1 && typeVar2) {
1616
1628
auto rep1 = getRepresentative (typeVar1);
1617
1629
auto rep2 = getRepresentative (typeVar2);
1618
- if (rep1 == rep2) {
1619
- // We already merged these two types, so this constraint is
1620
- // trivially solved.
1621
- return SolutionKind::Solved;
1622
- }
1623
1630
1624
1631
// If exactly one of the type variables can bind to an lvalue, we
1625
1632
// can't merge these two type variables.
@@ -1675,28 +1682,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1675
1682
assignFixedType (typeVar1, type2);
1676
1683
}
1677
1684
return SolutionKind::Solved;
1678
- } else if (typeVar1 && typeVar2) {
1679
- auto rep1 = getRepresentative (typeVar1);
1680
- auto rep2 = getRepresentative (typeVar2);
1681
- if (rep1 == rep2) {
1682
- return SolutionKind::Solved;
1683
- }
1684
1685
}
1685
1686
1686
1687
return formUnsolvedResult ();
1687
1688
}
1688
1689
1689
1690
case ConstraintKind::ArgumentTupleConversion:
1690
1691
case ConstraintKind::Conversion:
1691
- if (typeVar1 && typeVar2) {
1692
- auto rep1 = getRepresentative (typeVar1);
1693
- auto rep2 = getRepresentative (typeVar2);
1694
- if (rep1 == rep2) {
1695
- // We already merged these two types, so this constraint is
1696
- // trivially solved.
1697
- return SolutionKind::Solved;
1698
- }
1699
- }
1700
1692
LLVM_FALLTHROUGH;
1701
1693
1702
1694
case ConstraintKind::Subtype:
@@ -1739,12 +1731,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1739
1731
case ConstraintKind::OperatorArgumentConversion:
1740
1732
// We couldn't solve this constraint. If only one of the types is a type
1741
1733
// variable, perhaps we can do something with it below.
1742
- if (typeVar1 && typeVar2) {
1743
- if (typeVar1 == typeVar2) return SolutionKind::Solved;
1744
-
1734
+ if (typeVar1 && typeVar2)
1745
1735
return formUnsolvedResult ();
1746
- }
1747
-
1748
1736
break ;
1749
1737
1750
1738
case ConstraintKind::ApplicableFunction:
0 commit comments