@@ -1496,7 +1496,7 @@ class alignas(RequirementRepr) TrailingWhereClause final :
1496
1496
class alignas (8 ) _GenericContext {
1497
1497
// Not really public. See GenericContext.
1498
1498
public:
1499
- GenericParamList *GenericParams = nullptr ;
1499
+ llvm::PointerIntPair< GenericParamList *, 1 , bool > GenericParamsAndBit ;
1500
1500
1501
1501
// / The trailing where clause.
1502
1502
// /
@@ -1509,16 +1509,16 @@ class alignas(8) _GenericContext {
1509
1509
};
1510
1510
1511
1511
class GenericContext : private _GenericContext , public DeclContext {
1512
+ friend class GenericParamListRequest ;
1513
+
1512
1514
protected:
1513
- GenericContext (DeclContextKind Kind, DeclContext *Parent)
1514
- : _GenericContext(), DeclContext(Kind, Parent) { }
1515
+ GenericContext (DeclContextKind Kind, DeclContext *Parent,
1516
+ GenericParamList *Params);
1515
1517
1516
1518
public:
1517
1519
// / Retrieve the set of parameters to a generic context, or null if
1518
1520
// / this context is not generic.
1519
- GenericParamList *getGenericParams () const { return GenericParams; }
1520
-
1521
- void setGenericParams (GenericParamList *GenericParams);
1521
+ GenericParamList *getGenericParams () const ;
1522
1522
1523
1523
// / Determine whether this context has generic parameters
1524
1524
// / of its own.
@@ -1533,7 +1533,7 @@ class GenericContext : private _GenericContext, public DeclContext {
1533
1533
// / func p() // isGeneric == false
1534
1534
// / }
1535
1535
// / \endcode
1536
- bool isGeneric () const { return GenericParams != nullptr ; }
1536
+ bool isGeneric () const { return getGenericParams () != nullptr ; }
1537
1537
1538
1538
// / Retrieve the trailing where clause for this extension, if any.
1539
1539
TrailingWhereClause *getTrailingWhereClause () const {
@@ -1771,8 +1771,6 @@ class ExtensionDecl final : public GenericContext, public Decl,
1771
1771
return getValidationState () > ValidationState::CheckingWithValidSignature;
1772
1772
}
1773
1773
1774
- void createGenericParamsIfMissing (NominalTypeDecl *nominal);
1775
-
1776
1774
bool hasDefaultAccessLevel () const {
1777
1775
return Bits.ExtensionDecl .DefaultAndMaxAccessLevel != 0 ;
1778
1776
}
@@ -3328,7 +3326,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
3328
3326
GenericTypeDecl (K, DC, name, NameLoc, inherited, GenericParams),
3329
3327
IterableDeclContext (IterableDeclContextKind::NominalTypeDecl)
3330
3328
{
3331
- setGenericParams (GenericParams);
3332
3329
Bits.NominalTypeDecl .AddedImplicitInitializers = false ;
3333
3330
ExtensionGeneration = 0 ;
3334
3331
Bits.NominalTypeDecl .HasLazyConformances = false ;
@@ -4344,10 +4341,6 @@ class ProtocolDecl final : public NominalTypeDecl {
4344
4341
// / with the Objective-C runtime.
4345
4342
StringRef getObjCRuntimeName (llvm::SmallVectorImpl<char > &buffer) const ;
4346
4343
4347
- // / Create the generic parameters of this protocol if they haven't been
4348
- // / created yet.
4349
- void createGenericParamsIfMissing ();
4350
-
4351
4344
// / Retrieve the requirements that describe this protocol.
4352
4345
// /
4353
4346
// / These are the requirements including any inherited protocols
@@ -5437,7 +5430,7 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
5437
5430
SourceLoc SubscriptLoc, ParameterList *Indices,
5438
5431
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
5439
5432
GenericParamList *GenericParams)
5440
- : GenericContext(DeclContextKind::SubscriptDecl, Parent),
5433
+ : GenericContext(DeclContextKind::SubscriptDecl, Parent, GenericParams ),
5441
5434
AbstractStorageDecl (DeclKind::Subscript,
5442
5435
StaticSpelling != StaticSpellingKind::None,
5443
5436
Parent, Name, SubscriptLoc,
@@ -5446,7 +5439,6 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
5446
5439
Indices(nullptr ), ElementTy(ElementTy) {
5447
5440
Bits.SubscriptDecl .StaticSpelling = static_cast <unsigned >(StaticSpelling);
5448
5441
setIndices (Indices);
5449
- setGenericParams (GenericParams);
5450
5442
}
5451
5443
5452
5444
// / \returns the way 'static'/'class' was spelled in the source.
@@ -5611,11 +5603,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5611
5603
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
5612
5604
bool HasImplicitSelfDecl,
5613
5605
GenericParamList *GenericParams)
5614
- : GenericContext(DeclContextKind::AbstractFunctionDecl, Parent),
5606
+ : GenericContext(DeclContextKind::AbstractFunctionDecl, Parent, GenericParams ),
5615
5607
ValueDecl (Kind, Parent, Name, NameLoc),
5616
5608
Body(nullptr ), ThrowsLoc(ThrowsLoc) {
5617
5609
setBodyKind (BodyKind::None);
5618
- setGenericParams (GenericParams);
5619
5610
Bits.AbstractFunctionDecl .HasImplicitSelfDecl = HasImplicitSelfDecl;
5620
5611
Bits.AbstractFunctionDecl .Overridden = false ;
5621
5612
Bits.AbstractFunctionDecl .Throws = Throws;
@@ -7267,6 +7258,16 @@ inline void simple_display(llvm::raw_ostream &out,
7267
7258
simple_display (out, static_cast <const Decl *>(decl));
7268
7259
}
7269
7260
7261
+ // / Display GenericContext.
7262
+ // /
7263
+ // / The template keeps this sorted down in the overload set relative to the
7264
+ // / more concrete overloads with Decl pointers thereby breaking a potential ambiguity.
7265
+ template <typename T>
7266
+ inline typename std::enable_if<std::is_same<T, GenericContext>::value>::type
7267
+ simple_display (llvm::raw_ostream &out, const T *GC) {
7268
+ simple_display (out, GC->getAsDecl ());
7269
+ }
7270
+
7270
7271
// / Display GenericParamList.
7271
7272
void simple_display (llvm::raw_ostream &out, const GenericParamList *GPL);
7272
7273
0 commit comments