@@ -1780,25 +1780,63 @@ class BuiltinUnboundGenericType : public BuiltinType {
17801780};
17811781DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinUnboundGenericType, BuiltinType)
17821782
1783+ // / BuiltinGenericType - Base class for builtins that are parameterized by
1784+ // / a generic signature.
1785+ class BuiltinGenericType : public BuiltinType {
1786+ protected:
1787+
1788+ BuiltinGenericType (TypeKind kind, ASTContext &context,
1789+ RecursiveTypeProperties properties)
1790+ : BuiltinType (kind, context, properties)
1791+ {}
1792+
1793+ // / The substitution map is cached here once requested.
1794+ mutable std::optional<SubstitutionMap> CachedSubstitutionMap = std::nullopt ;
1795+
1796+ public:
1797+ static bool classof (const TypeBase *T) {
1798+ return T->getKind () >= TypeKind::First_BuiltinGenericType
1799+ && T->getKind () <= TypeKind::Last_BuiltinGenericType;
1800+ }
1801+
1802+ // Get the generic signature describing the parameterization of types of
1803+ // this class.
1804+ GenericSignature getGenericSignature () const ;
1805+
1806+ // Get the substitution map for this particular type.
1807+ SubstitutionMap getSubstitutions () const ;
1808+
1809+ // Produce another type of the same class but with different arguments.
1810+ CanTypeWrapper<BuiltinGenericType>
1811+ getWithSubstitutions (SubstitutionMap newSubs) const ;
1812+ };
1813+ DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinGenericType, BuiltinType)
1814+
17831815// / BuiltinFixedArrayType - The builtin type representing N values stored
17841816// / inline contiguously.
17851817// /
17861818// / All elements of a value of this type must be fully initialized any time the
17871819// / value may be copied, moved, or destroyed.
1788- class BuiltinFixedArrayType : public BuiltinType, public llvm::FoldingSetNode {
1820+ class BuiltinFixedArrayType : public BuiltinGenericType,
1821+ public llvm::FoldingSetNode {
17891822 friend class ASTContext ;
17901823
17911824 CanType Size;
17921825 CanType ElementType;
17931826
17941827 BuiltinFixedArrayType (CanType Size, CanType ElementType,
17951828 RecursiveTypeProperties properties)
1796- : BuiltinType (TypeKind::BuiltinFixedArray, ElementType->getASTContext (),
1797- properties),
1829+ : BuiltinGenericType (TypeKind::BuiltinFixedArray,
1830+ ElementType->getASTContext (),
1831+ properties),
17981832 Size (Size),
17991833 ElementType (ElementType)
18001834 {}
18011835
1836+ friend BuiltinGenericType;
1837+ // / Get the generic arguments as a substitution map.
1838+ SubstitutionMap buildSubstitutions () const ;
1839+
18021840public:
18031841 // / Arrays with more elements than this are always treated as in-memory values.
18041842 // /
@@ -1826,7 +1864,7 @@ class BuiltinFixedArrayType : public BuiltinType, public llvm::FoldingSetNode {
18261864
18271865 // / Get the element type.
18281866 CanType getElementType () const { return ElementType; }
1829-
1867+
18301868 void Profile (llvm::FoldingSetNodeID &ID) const {
18311869 Profile (ID, getSize (), getElementType ());
18321870 }
@@ -1836,7 +1874,7 @@ class BuiltinFixedArrayType : public BuiltinType, public llvm::FoldingSetNode {
18361874 ID.AddPointer (ElementType.getPointer ());
18371875 }
18381876};
1839- DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinFixedArrayType, BuiltinType )
1877+ DEFINE_EMPTY_CAN_TYPE_WRAPPER (BuiltinFixedArrayType, BuiltinGenericType )
18401878
18411879// / BuiltinRawPointerType - The builtin raw (and dangling) pointer type. This
18421880// / pointer is completely unmanaged and is equivalent to i8* in LLVM IR.
0 commit comments