@@ -62,6 +62,7 @@ class ArgumentList;
62
62
class AssociatedTypeDecl ;
63
63
class ASTContext ;
64
64
enum BufferPointerTypeKind : unsigned ;
65
+ struct BuiltinNameStringLiteral ;
65
66
class BuiltinTupleDecl ;
66
67
class ClassDecl ;
67
68
class ClangModuleLoader ;
@@ -1508,6 +1509,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
1508
1509
// / return `None`.
1509
1510
std::optional<TangentSpace>
1510
1511
getAutoDiffTangentSpace (LookupConformanceFn lookupConformance);
1512
+
1513
+ // / Return the kind of generic parameter that this type can be matched to.
1514
+ GenericTypeParamKind getMatchingParamKind ();
1511
1515
};
1512
1516
1513
1517
// / AnyGenericType - This abstract class helps types ensure that fields
@@ -1648,8 +1652,9 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(UnresolvedType, Type)
1648
1652
// / BuiltinType - An abstract class for all the builtin types.
1649
1653
class BuiltinType : public TypeBase {
1650
1654
protected:
1651
- BuiltinType (TypeKind kind, const ASTContext &canTypeCtx)
1652
- : TypeBase (kind, &canTypeCtx, RecursiveTypeProperties ()) {}
1655
+ BuiltinType (TypeKind kind, const ASTContext &canTypeCtx,
1656
+ RecursiveTypeProperties properties = {})
1657
+ : TypeBase (kind, &canTypeCtx, properties) {}
1653
1658
public:
1654
1659
static bool classof (const TypeBase *T) {
1655
1660
return T->getKind () >= TypeKind::First_BuiltinType &&
@@ -1672,6 +1677,113 @@ class BuiltinType : public TypeBase {
1672
1677
};
1673
1678
DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinType, Type)
1674
1679
1680
+ // / BuiltinUnboundGenericType - the base declaration of a generic builtin type
1681
+ // / that has not yet had generic parameters applied.
1682
+ // /
1683
+ // / Referring to an unbound generic type by itself is invalid, but this
1684
+ // / representation is used as an intermediate during type resolution when
1685
+ // / resolving a type reference such as `Builtin.Int<31>`. Applying
1686
+ // / the generic parameters produces the actual builtin type based on the
1687
+ // / kind of the base.
1688
+ class BuiltinUnboundGenericType : public BuiltinType {
1689
+ friend class ASTContext ;
1690
+ TypeKind BoundGenericTypeKind;
1691
+
1692
+ BuiltinUnboundGenericType (const ASTContext &C,
1693
+ TypeKind genericTypeKind)
1694
+ : BuiltinType (TypeKind::BuiltinUnboundGeneric, C),
1695
+ BoundGenericTypeKind (genericTypeKind)
1696
+ {}
1697
+
1698
+ public:
1699
+ static bool classof (const TypeBase *T) {
1700
+ return T->getKind () == TypeKind::BuiltinUnboundGeneric;
1701
+ }
1702
+
1703
+ // / Produce the unqualified name of the type.
1704
+ BuiltinNameStringLiteral getBuiltinTypeName () const ;
1705
+ StringRef getBuiltinTypeNameString () const ;
1706
+
1707
+ static BuiltinUnboundGenericType *get (TypeKind genericTypeKind,
1708
+ const ASTContext &C);
1709
+
1710
+ // / Get the generic signature with which to substitute this type.
1711
+ GenericSignature getGenericSignature () const ;
1712
+
1713
+ // / Get the type that results from binding the generic parameters of this
1714
+ // / builtin to the given substitutions.
1715
+ // /
1716
+ // / Produces an ErrorType if the substitution is invalid.
1717
+ Type getBound (SubstitutionMap subs) const ;
1718
+ };
1719
+ DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinUnboundGenericType, BuiltinType)
1720
+
1721
+ // / BuiltinFixedArrayType - The builtin type representing N values stored
1722
+ // / inline contiguously.
1723
+ // /
1724
+ // / All elements of a value of this type must be fully initialized any time the
1725
+ // / value may be copied, moved, or destroyed.
1726
+ class BuiltinFixedArrayType : public BuiltinType, public llvm::FoldingSetNode {
1727
+ friend class ASTContext ;
1728
+
1729
+ CanType Size ;
1730
+ CanType ElementType;
1731
+
1732
+ static RecursiveTypeProperties
1733
+ getRecursiveTypeProperties (CanType Size , CanType Element) {
1734
+ RecursiveTypeProperties properties;
1735
+ properties |= Size ->getRecursiveProperties ();
1736
+ properties |= Element->getRecursiveProperties ();
1737
+ return properties;
1738
+ }
1739
+
1740
+ BuiltinFixedArrayType (CanType Size ,
1741
+ CanType ElementType)
1742
+ : BuiltinType (TypeKind::BuiltinFixedArray, ElementType->getASTContext (),
1743
+ getRecursiveTypeProperties (Size , ElementType)),
1744
+ Size (Size ),
1745
+ ElementType (ElementType)
1746
+ {}
1747
+
1748
+ public:
1749
+ // / Arrays with more elements than this are always treated as in-memory values.
1750
+ // /
1751
+ // / (4096 is the hardcoded limit above which we refuse to import C arrays
1752
+ // / as tuples. From first principles, a much lower threshold would probably
1753
+ // / make sense, but we don't want to break the type lowering of C types
1754
+ // / as they appear in existing Swift code.)
1755
+ static constexpr const uint64_t MaximumLoadableSize = 4096 ;
1756
+
1757
+ static bool classof (const TypeBase *T) {
1758
+ return T->getKind () == TypeKind::BuiltinFixedArray;
1759
+ }
1760
+
1761
+ static BuiltinFixedArrayType *get (CanType Size ,
1762
+ CanType ElementType);
1763
+
1764
+ // / Get the integer generic parameter representing the number of elements.
1765
+ CanType getSize () const { return Size ; }
1766
+
1767
+ // / Get the fixed integer number of elements if known and zero or greater.
1768
+ std::optional<uint64_t > getFixedInhabitedSize () const ;
1769
+
1770
+ // / True if the type is statically negative-sized (and therefore uninhabited).
1771
+ bool isFixedNegativeSize () const ;
1772
+
1773
+ // / Get the element type.
1774
+ CanType getElementType () const { return ElementType; }
1775
+
1776
+ void Profile (llvm::FoldingSetNodeID &ID) const {
1777
+ Profile (ID, getSize (), getElementType ());
1778
+ }
1779
+ static void Profile (llvm::FoldingSetNodeID &ID,
1780
+ CanType Size , CanType ElementType) {
1781
+ ID.AddPointer (Size .getPointer ());
1782
+ ID.AddPointer (ElementType.getPointer ());
1783
+ }
1784
+ };
1785
+ DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinFixedArrayType, BuiltinType)
1786
+
1675
1787
// / BuiltinRawPointerType - The builtin raw (and dangling) pointer type. This
1676
1788
// / pointer is completely unmanaged and is equivalent to i8* in LLVM IR.
1677
1789
class BuiltinRawPointerType : public BuiltinType {
0 commit comments