@@ -66,12 +66,30 @@ class alignas(8) TypeRepr {
66
66
Warned : 1
67
67
);
68
68
69
- SWIFT_INLINE_BITFIELD_FULL (TupleTypeRepr, TypeRepr, 1 +16 ,
69
+ SWIFT_INLINE_BITFIELD_FULL (TupleTypeRepr, TypeRepr, 1 +32 ,
70
70
// / Whether this tuple has '...' and its position.
71
71
HasEllipsis : 1 ,
72
72
: NumPadBits,
73
73
// / The number of elements contained.
74
- NumElements : 16
74
+ NumElements : 32
75
+ );
76
+
77
+ SWIFT_INLINE_BITFIELD_EMPTY (IdentTypeRepr, TypeRepr);
78
+ SWIFT_INLINE_BITFIELD_EMPTY (ComponentIdentTypeRepr, IdentTypeRepr);
79
+
80
+ SWIFT_INLINE_BITFIELD_FULL (GenericIdentTypeRepr, ComponentIdentTypeRepr, 32 ,
81
+ : NumPadBits,
82
+ NumGenericArgs : 32
83
+ );
84
+
85
+ SWIFT_INLINE_BITFIELD_FULL (CompoundIdentTypeRepr, IdentTypeRepr, 32 ,
86
+ : NumPadBits,
87
+ NumComponents : 32
88
+ );
89
+
90
+ SWIFT_INLINE_BITFIELD_FULL (CompositionTypeRepr, TypeRepr, 32 ,
91
+ : NumPadBits,
92
+ NumTypes : 32
75
93
);
76
94
77
95
} Bits;
@@ -319,24 +337,37 @@ class SimpleIdentTypeRepr : public ComponentIdentTypeRepr {
319
337
// / \code
320
338
// / Bar<Gen>
321
339
// / \endcode
322
- class GenericIdentTypeRepr : public ComponentIdentTypeRepr {
323
- ArrayRef<TypeRepr*> GenericArgs;
340
+ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr,
341
+ private llvm::TrailingObjects<GenericIdentTypeRepr, TypeRepr *> {
342
+ friend TrailingObjects;
324
343
SourceRange AngleBrackets;
325
344
326
- public:
327
345
GenericIdentTypeRepr (SourceLoc Loc, Identifier Id,
328
346
ArrayRef<TypeRepr*> GenericArgs,
329
347
SourceRange AngleBrackets)
330
348
: ComponentIdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id),
331
- GenericArgs (GenericArgs), AngleBrackets(AngleBrackets) {
349
+ AngleBrackets (AngleBrackets) {
350
+ Bits.GenericIdentTypeRepr .NumGenericArgs = GenericArgs.size ();
332
351
assert (!GenericArgs.empty ());
333
352
#ifndef NDEBUG
334
353
for (auto arg : GenericArgs)
335
354
assert (arg != nullptr );
336
355
#endif
356
+ std::uninitialized_copy (GenericArgs.begin (), GenericArgs.end (),
357
+ getTrailingObjects<TypeRepr*>());
337
358
}
338
359
339
- ArrayRef<TypeRepr*> getGenericArgs () const { return GenericArgs; }
360
+ public:
361
+ static GenericIdentTypeRepr *create (const ASTContext &C,
362
+ SourceLoc Loc,
363
+ Identifier Id,
364
+ ArrayRef<TypeRepr*> GenericArgs,
365
+ SourceRange AngleBrackets);
366
+
367
+ ArrayRef<TypeRepr*> getGenericArgs () const {
368
+ return {getTrailingObjects<TypeRepr*>(),
369
+ Bits.GenericIdentTypeRepr .NumGenericArgs };
370
+ }
340
371
SourceRange getAngleBrackets () const { return AngleBrackets; }
341
372
342
373
static bool classof (const TypeRepr *T) {
@@ -354,15 +385,27 @@ class GenericIdentTypeRepr : public ComponentIdentTypeRepr {
354
385
// / \code
355
386
// / Foo.Bar<Gen>
356
387
// / \endcode
357
- class CompoundIdentTypeRepr : public IdentTypeRepr {
358
- public:
359
- const ArrayRef<ComponentIdentTypeRepr *> Components;
388
+ class CompoundIdentTypeRepr final : public IdentTypeRepr,
389
+ private llvm::TrailingObjects<CompoundIdentTypeRepr,
390
+ ComponentIdentTypeRepr *> {
391
+ friend TrailingObjects;
360
392
361
- explicit CompoundIdentTypeRepr (ArrayRef<ComponentIdentTypeRepr *> Components)
362
- : IdentTypeRepr(TypeReprKind::CompoundIdent),
363
- Components(Components) {
393
+ CompoundIdentTypeRepr (ArrayRef<ComponentIdentTypeRepr *> Components)
394
+ : IdentTypeRepr(TypeReprKind::CompoundIdent) {
395
+ Bits. CompoundIdentTypeRepr . NumComponents = Components. size ();
364
396
assert (Components.size () > 1 &&
365
397
" should have just used the single ComponentIdentTypeRepr directly" );
398
+ std::uninitialized_copy (Components.begin (), Components.end (),
399
+ getTrailingObjects<ComponentIdentTypeRepr*>());
400
+ }
401
+
402
+ public:
403
+ static CompoundIdentTypeRepr *create (const ASTContext &Ctx,
404
+ ArrayRef<ComponentIdentTypeRepr*> Components);
405
+
406
+ ArrayRef<ComponentIdentTypeRepr*> getComponents () const {
407
+ return {getTrailingObjects<ComponentIdentTypeRepr*>(),
408
+ Bits.CompoundIdentTypeRepr .NumComponents };
366
409
}
367
410
368
411
static bool classof (const TypeRepr *T) {
@@ -371,9 +414,15 @@ class CompoundIdentTypeRepr : public IdentTypeRepr {
371
414
static bool classof (const CompoundIdentTypeRepr *T) { return true ; }
372
415
373
416
private:
374
- SourceLoc getStartLocImpl () const { return Components.front ()->getStartLoc ();}
375
- SourceLoc getEndLocImpl () const { return Components.back ()->getEndLoc (); }
376
- SourceLoc getLocImpl () const { return Components.back ()->getLoc (); }
417
+ SourceLoc getStartLocImpl () const {
418
+ return getComponents ().front ()->getStartLoc ();
419
+ }
420
+ SourceLoc getEndLocImpl () const {
421
+ return getComponents ().back ()->getEndLoc ();
422
+ }
423
+ SourceLoc getLocImpl () const {
424
+ return getComponents ().back ()->getLoc ();
425
+ }
377
426
378
427
void printImpl (ASTPrinter &Printer, const PrintOptions &Opts) const ;
379
428
friend class TypeRepr ;
@@ -392,13 +441,13 @@ class IdentTypeRepr::ComponentRange {
392
441
iterator begin () const {
393
442
if (isa<ComponentIdentTypeRepr>(IdT))
394
443
return reinterpret_cast <iterator>(&IdT);
395
- return cast<CompoundIdentTypeRepr>(IdT)->Components .begin ();
444
+ return cast<CompoundIdentTypeRepr>(IdT)->getComponents () .begin ();
396
445
}
397
446
398
447
iterator end () const {
399
448
if (isa<ComponentIdentTypeRepr>(IdT))
400
449
return reinterpret_cast <iterator>(&IdT) + 1 ;
401
- return cast<CompoundIdentTypeRepr>(IdT)->Components .end ();
450
+ return cast<CompoundIdentTypeRepr>(IdT)->getComponents () .end ();
402
451
}
403
452
404
453
bool empty () const { return begin () == end (); }
@@ -735,24 +784,30 @@ class TupleTypeRepr final : public TypeRepr,
735
784
// / \code
736
785
// / Foo & Bar
737
786
// / \endcode
738
- class CompositionTypeRepr : public TypeRepr {
739
- ArrayRef<TypeRepr *> Types;
787
+ class CompositionTypeRepr final : public TypeRepr,
788
+ private llvm::TrailingObjects<CompositionTypeRepr, TypeRepr*> {
789
+ friend TrailingObjects;
740
790
SourceLoc FirstTypeLoc;
741
791
SourceRange CompositionRange;
742
792
743
- public:
744
793
CompositionTypeRepr (ArrayRef<TypeRepr *> Types,
745
794
SourceLoc FirstTypeLoc,
746
795
SourceRange CompositionRange)
747
- : TypeRepr(TypeReprKind::Composition), Types(Types),
748
- FirstTypeLoc (FirstTypeLoc), CompositionRange(CompositionRange) {
796
+ : TypeRepr(TypeReprKind::Composition), FirstTypeLoc(FirstTypeLoc),
797
+ CompositionRange (CompositionRange) {
798
+ Bits.CompositionTypeRepr .NumTypes = Types.size ();
799
+ std::uninitialized_copy (Types.begin (), Types.end (),
800
+ getTrailingObjects<TypeRepr*>());
749
801
}
750
802
751
- ArrayRef<TypeRepr *> getTypes () const { return Types; }
803
+ public:
804
+ ArrayRef<TypeRepr *> getTypes () const {
805
+ return {getTrailingObjects<TypeRepr*>(), Bits.CompositionTypeRepr .NumTypes };
806
+ }
752
807
SourceLoc getSourceLoc () const { return FirstTypeLoc; }
753
808
SourceRange getCompositionRange () const { return CompositionRange; }
754
809
755
- static CompositionTypeRepr *create (ASTContext &C,
810
+ static CompositionTypeRepr *create (const ASTContext &C,
756
811
ArrayRef<TypeRepr*> Protocols,
757
812
SourceLoc FirstTypeLoc,
758
813
SourceRange CompositionRange);
0 commit comments