@@ -1158,8 +1158,7 @@ const RequirementSource *RequirementSource::forExplicit(
1158
1158
const RequirementSource *RequirementSource::forInferred (
1159
1159
GenericSignatureBuilder &builder,
1160
1160
Type rootType,
1161
- const TypeRepr *typeRepr) {
1162
- WrittenRequirementLoc writtenLoc = typeRepr;
1161
+ WrittenRequirementLoc writtenLoc) {
1163
1162
REQUIREMENT_SOURCE_FACTORY_BODY (
1164
1163
(nodeID, Inferred, nullptr , rootType.getPointer (),
1165
1164
writtenLoc.getOpaqueValue (), nullptr ),
@@ -1646,40 +1645,34 @@ const RequirementSource *FloatingRequirementSource::getSource(
1646
1645
ResolvedType type) const {
1647
1646
switch (kind) {
1648
1647
case Resolved:
1649
- return storage. get < const RequirementSource *>() ;
1648
+ return source ;
1650
1649
1651
1650
case Explicit: {
1652
1651
auto depType = type.getDependentType (builder);
1653
-
1654
- if (auto requirementRepr = storage.dyn_cast <const RequirementRepr *>())
1655
- return RequirementSource::forExplicit (builder, depType, requirementRepr);
1656
- if (auto typeRepr = storage.dyn_cast <const TypeRepr *>())
1657
- return RequirementSource::forExplicit (builder, depType, typeRepr);
1658
- return RequirementSource::forAbstract (builder, depType);
1652
+ return RequirementSource::forExplicit (builder, depType, loc);
1659
1653
}
1660
1654
1661
1655
case Inferred: {
1662
1656
auto depType = type.getDependentType (builder);
1663
- return RequirementSource::forInferred (builder, depType,
1664
- storage.get <const TypeRepr *>());
1657
+ return RequirementSource::forInferred (builder, depType, loc);
1665
1658
}
1666
1659
1667
- case AbstractProtocol: {
1660
+ case ProtocolRequirement:
1661
+ case InferredProtocolRequirement: {
1668
1662
auto depType = type.getDependentType ();
1669
1663
1670
1664
// Derive the dependent type on which this requirement was written. It is
1671
1665
// the path from the requirement source on which this requirement is based
1672
1666
// to the potential archetype on which the requirement is being placed.
1673
- auto baseSource = storage.get <const RequirementSource *>();
1674
- auto baseSourceType = baseSource->getAffectedType ();
1667
+ auto baseSourceType = source->getAffectedType ();
1675
1668
1676
1669
auto dependentType =
1677
- formProtocolRelativeType (protocolReq. protocol , baseSourceType, depType);
1670
+ formProtocolRelativeType (protocol, baseSourceType, depType);
1678
1671
1679
- return storage. get < const RequirementSource *>()
1680
- ->viaProtocolRequirement (builder, dependentType,
1681
- protocolReq. protocol , protocolReq. inferred ,
1682
- protocolReq. written );
1672
+ return source
1673
+ ->viaProtocolRequirement (builder, dependentType, protocol,
1674
+ kind == InferredProtocolRequirement ,
1675
+ loc );
1683
1676
}
1684
1677
1685
1678
case NestedTypeNameMatch: {
@@ -1688,29 +1681,20 @@ const RequirementSource *FloatingRequirementSource::getSource(
1688
1681
}
1689
1682
}
1690
1683
1691
- llvm_unreachable (" Unhandled FloatingPointRequirementSourceKind in switch. " );
1684
+ llvm_unreachable (" unhandled kind " );
1692
1685
}
1693
1686
1694
1687
SourceLoc FloatingRequirementSource::getLoc () const {
1695
- // For an explicit abstract protocol source, we can get a more accurate source
1696
- // location from the written protocol requirement.
1697
- if (kind == Kind::AbstractProtocol && isExplicit ()) {
1698
- auto written = protocolReq.written ;
1699
- if (auto typeRepr = written.dyn_cast <const TypeRepr *>())
1688
+ if (kind == Inferred || isExplicit ()) {
1689
+ if (auto typeRepr = loc.dyn_cast <const TypeRepr *>())
1700
1690
return typeRepr->getLoc ();
1701
- if (auto requirementRepr = written .dyn_cast <const RequirementRepr *>())
1691
+ if (auto requirementRepr = loc .dyn_cast <const RequirementRepr *>())
1702
1692
return requirementRepr->getSeparatorLoc ();
1703
1693
}
1704
1694
1705
- if (auto source = storage. dyn_cast < const RequirementSource *>() )
1695
+ if (source)
1706
1696
return source->getLoc ();
1707
1697
1708
- if (auto typeRepr = storage.dyn_cast <const TypeRepr *>())
1709
- return typeRepr->getLoc ();
1710
-
1711
- if (auto requirementRepr = storage.dyn_cast <const RequirementRepr *>())
1712
- return requirementRepr->getSeparatorLoc ();
1713
-
1714
1698
return SourceLoc ();
1715
1699
}
1716
1700
@@ -1721,8 +1705,9 @@ bool FloatingRequirementSource::isDerived() const {
1721
1705
case NestedTypeNameMatch:
1722
1706
return false ;
1723
1707
1724
- case AbstractProtocol:
1725
- switch (storage.get <const RequirementSource *>()->kind ) {
1708
+ case ProtocolRequirement:
1709
+ case InferredProtocolRequirement:
1710
+ switch (source->kind ) {
1726
1711
case RequirementSource::RequirementSignatureSelf:
1727
1712
return false ;
1728
1713
@@ -1740,7 +1725,7 @@ bool FloatingRequirementSource::isDerived() const {
1740
1725
}
1741
1726
1742
1727
case Resolved:
1743
- return storage. get < const RequirementSource *>() ->isDerivedRequirement ();
1728
+ return source ->isDerivedRequirement ();
1744
1729
}
1745
1730
llvm_unreachable (" unhandled kind" );
1746
1731
}
@@ -1754,14 +1739,14 @@ bool FloatingRequirementSource::isExplicit() const {
1754
1739
case NestedTypeNameMatch:
1755
1740
return false ;
1756
1741
1757
- case AbstractProtocol :
1742
+ case ProtocolRequirement :
1758
1743
// Requirements implied by other protocol conformance requirements are
1759
1744
// implicit, except when computing a requirement signature, where
1760
1745
// non-inferred ones are explicit, to allow flagging of redundant
1761
1746
// requirements.
1762
- switch (storage. get < const RequirementSource *>() ->kind ) {
1747
+ switch (source ->kind ) {
1763
1748
case RequirementSource::RequirementSignatureSelf:
1764
- return !protocolReq. inferred ;
1749
+ return true ;
1765
1750
1766
1751
case RequirementSource::Concrete:
1767
1752
case RequirementSource::Explicit:
@@ -1776,14 +1761,16 @@ bool FloatingRequirementSource::isExplicit() const {
1776
1761
return false ;
1777
1762
}
1778
1763
1764
+ case InferredProtocolRequirement:
1765
+ return false ;
1766
+
1779
1767
case Resolved:
1780
- switch (storage. get < const RequirementSource *>() ->kind ) {
1768
+ switch (source ->kind ) {
1781
1769
case RequirementSource::Explicit:
1782
1770
return true ;
1783
1771
1784
1772
case RequirementSource::ProtocolRequirement:
1785
- return storage.get <const RequirementSource *>()->parent ->kind
1786
- == RequirementSource::RequirementSignatureSelf;
1773
+ return source->parent ->kind == RequirementSource::RequirementSignatureSelf;
1787
1774
1788
1775
case RequirementSource::Inferred:
1789
1776
case RequirementSource::InferredProtocolRequirement:
@@ -1812,9 +1799,9 @@ FloatingRequirementSource FloatingRequirementSource::asInferred(
1812
1799
case NestedTypeNameMatch:
1813
1800
return *this ;
1814
1801
1815
- case AbstractProtocol :
1816
- return viaProtocolRequirement (storage. get < const RequirementSource *>(),
1817
- protocolReq. protocol , typeRepr,
1802
+ case ProtocolRequirement :
1803
+ case InferredProtocolRequirement:
1804
+ return viaProtocolRequirement (source, protocol, typeRepr,
1818
1805
/* inferred=*/ true );
1819
1806
}
1820
1807
llvm_unreachable (" unhandled kind" );
@@ -1823,8 +1810,8 @@ FloatingRequirementSource FloatingRequirementSource::asInferred(
1823
1810
bool FloatingRequirementSource::isRecursive (
1824
1811
GenericSignatureBuilder &builder) const {
1825
1812
llvm::SmallSet<std::pair<CanType, ProtocolDecl *>, 32 > visitedAssocReqs;
1826
- for (auto storedSource = storage. dyn_cast < const RequirementSource *>() ;
1827
- storedSource; storedSource = storedSource->parent ) {
1813
+ for (auto storedSource = source; storedSource ;
1814
+ storedSource = storedSource->parent ) {
1828
1815
// FIXME: isRecursive() is completely misnamed
1829
1816
if (storedSource->kind == RequirementSource::EquivalentType)
1830
1817
return true ;
0 commit comments