@@ -362,8 +362,13 @@ class alignas(1 << TypeAlignInBits) TypeBase {
362
362
363
363
// / Whether an element of the tuple is inout.
364
364
unsigned HasInOutElement : 1 ;
365
+
366
+ unsigned : 32 - (NumTypeBaseBits + 1 ); // unused / padding
367
+
368
+ // / The number of elements of the tuple.
369
+ unsigned Count : 32 ;
365
370
};
366
- NUMBITS (TupleType, NumTypeBaseBits + 1 );
371
+ NUMBITS (TupleType, 64 );
367
372
368
373
#undef NUMBITS
369
374
union {
@@ -1577,8 +1582,9 @@ typedef ArrayRefView<TupleTypeElt,CanType,getCanTupleEltType>
1577
1582
// / TupleType - A tuple is a parenthesized list of types where each name has an
1578
1583
// / optional name.
1579
1584
// /
1580
- class TupleType : public TypeBase , public llvm ::FoldingSetNode {
1581
- const ArrayRef<TupleTypeElt> Elements;
1585
+ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
1586
+ private llvm::TrailingObjects<TupleType, TupleTypeElt> {
1587
+ friend TrailingObjects;
1582
1588
1583
1589
public:
1584
1590
// / get - Return the uniqued tuple type with the specified elements.
@@ -1590,16 +1596,20 @@ class TupleType : public TypeBase, public llvm::FoldingSetNode {
1590
1596
// / getEmpty - Return the empty tuple type '()'.
1591
1597
static CanTypeWrapper<TupleType> getEmpty (const ASTContext &C);
1592
1598
1593
- // / getFields - Return the fields of this tuple.
1594
- ArrayRef<TupleTypeElt> getElements () const { return Elements; }
1599
+ unsigned getNumElements () const { return TupleTypeBits.Count ; }
1595
1600
1596
- unsigned getNumElements () const { return Elements.size (); }
1601
+ // / getElements - Return the elements of this tuple.
1602
+ ArrayRef<TupleTypeElt> getElements () const {
1603
+ return {getTrailingObjects<TupleTypeElt>(), getNumElements ()};
1604
+ }
1597
1605
1598
- const TupleTypeElt &getElement (unsigned i) const { return Elements[i]; }
1606
+ const TupleTypeElt &getElement (unsigned i) const {
1607
+ return getTrailingObjects<TupleTypeElt>()[i];
1608
+ }
1599
1609
1600
1610
// / getElementType - Return the type of the specified element.
1601
1611
Type getElementType (unsigned ElementNo) const {
1602
- return Elements [ElementNo].getType ();
1612
+ return getTrailingObjects<TupleTypeElt>() [ElementNo].getType ();
1603
1613
}
1604
1614
1605
1615
TupleEltTypeArrayRef getElementTypes () const {
@@ -1631,7 +1641,7 @@ class TupleType : public TypeBase, public llvm::FoldingSetNode {
1631
1641
}
1632
1642
1633
1643
void Profile (llvm::FoldingSetNodeID &ID) {
1634
- Profile (ID, Elements );
1644
+ Profile (ID, getElements () );
1635
1645
}
1636
1646
static void Profile (llvm::FoldingSetNodeID &ID,
1637
1647
ArrayRef<TupleTypeElt> Elements);
@@ -1640,8 +1650,11 @@ class TupleType : public TypeBase, public llvm::FoldingSetNode {
1640
1650
TupleType (ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
1641
1651
RecursiveTypeProperties properties,
1642
1652
bool hasInOut)
1643
- : TypeBase(TypeKind::Tuple, CanCtx, properties), Elements(elements) {
1653
+ : TypeBase(TypeKind::Tuple, CanCtx, properties) {
1644
1654
TupleTypeBits.HasInOutElement = hasInOut;
1655
+ TupleTypeBits.Count = elements.size ();
1656
+ std::uninitialized_copy (elements.begin (), elements.end (),
1657
+ getTrailingObjects<TupleTypeElt>());
1645
1658
}
1646
1659
};
1647
1660
BEGIN_CAN_TYPE_WRAPPER (TupleType, Type)
0 commit comments