31
31
#include " swift/AST/TypeAlignments.h"
32
32
#include " swift/AST/TypeWalker.h"
33
33
#include " swift/AST/Witness.h"
34
+ #include " swift/Basic/ArrayRefView.h"
34
35
#include " swift/Basic/Compiler.h"
35
36
#include " swift/Basic/InlineBitfield.h"
36
37
#include " swift/Basic/OptionalEnum.h"
@@ -307,7 +308,7 @@ class alignas(1 << DeclAlignInBits) Decl {
307
308
NumElements : 32
308
309
);
309
310
310
- SWIFT_INLINE_BITFIELD (ValueDecl, Decl, 1 +1 +1 + 1 + 1 ,
311
+ SWIFT_INLINE_BITFIELD (ValueDecl, Decl, 1 +1 +1 ,
311
312
AlreadyInLookupTable : 1 ,
312
313
313
314
// / Whether we have already checked whether this declaration is a
@@ -316,19 +317,10 @@ class alignas(1 << DeclAlignInBits) Decl {
316
317
317
318
// / Whether the decl can be accessed by swift users; for instance,
318
319
// / a.storage for lazy var a is a decl that cannot be accessed.
319
- IsUserAccessible : 1 ,
320
-
321
- // / Whether the "IsObjC" bit has been computed yet.
322
- IsObjCComputed : 1 ,
323
-
324
- // / Whether this declaration is exposed to Objective-C.
325
- IsObjC : 1
320
+ IsUserAccessible : 1
326
321
);
327
322
328
- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +1 ,
329
- // / Whether we are overridden later
330
- Overridden : 1 ,
331
-
323
+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 ,
332
324
// / Whether the getter is mutating.
333
325
IsGetterMutating : 1 ,
334
326
@@ -588,11 +580,6 @@ class alignas(1 << DeclAlignInBits) Decl {
588
580
Associativity : 2
589
581
);
590
582
591
- SWIFT_INLINE_BITFIELD (AssociatedTypeDecl, ValueDecl, 1 +1 ,
592
- ComputedOverridden : 1 ,
593
- HasOverridden : 1
594
- );
595
-
596
583
SWIFT_INLINE_BITFIELD (ImportDecl, Decl, 3 +8 ,
597
584
ImportKind : 3 ,
598
585
@@ -2181,6 +2168,21 @@ class ValueDecl : public Decl {
2181
2168
llvm::PointerIntPair<Type, 3 , OptionalEnum<AccessLevel>> TypeAndAccess;
2182
2169
unsigned LocalDiscriminator = 0 ;
2183
2170
2171
+ struct {
2172
+ // / Whether the "IsObjC" bit has been computed yet.
2173
+ unsigned isObjCComputed : 1 ;
2174
+
2175
+ // / Whether this declaration is exposed to Objective-C.
2176
+ unsigned isObjC : 1 ;
2177
+
2178
+ // / Whether the "overridden" declarations have been computed already.
2179
+ unsigned hasOverriddenComputed : 1 ;
2180
+
2181
+ // / Whether there are any "overridden" declarations. The actual overridden
2182
+ // / declarations are kept in a side table in the ASTContext.
2183
+ unsigned hasOverridden : 1 ;
2184
+ } LazySemanticInfo;
2185
+
2184
2186
protected:
2185
2187
ValueDecl (DeclKind K,
2186
2188
llvm::PointerUnion<DeclContext *, ASTContext *> context,
@@ -2189,8 +2191,10 @@ class ValueDecl : public Decl {
2189
2191
Bits.ValueDecl .AlreadyInLookupTable = false ;
2190
2192
Bits.ValueDecl .CheckedRedeclaration = false ;
2191
2193
Bits.ValueDecl .IsUserAccessible = true ;
2192
- Bits.ValueDecl .IsObjCComputed = false ;
2193
- Bits.ValueDecl .IsObjC = false ;
2194
+ LazySemanticInfo.isObjCComputed = false ;
2195
+ LazySemanticInfo.isObjC = false ;
2196
+ LazySemanticInfo.hasOverriddenComputed = false ;
2197
+ LazySemanticInfo.hasOverridden = false ;
2194
2198
}
2195
2199
2196
2200
// MemberLookupTable borrows a bit from this type
@@ -2414,6 +2418,23 @@ class ValueDecl : public Decl {
2414
2418
// / Retrieve the declaration that this declaration overrides, if any.
2415
2419
ValueDecl *getOverriddenDecl () const ;
2416
2420
2421
+ // / Retrieve the declarations that this declaration overrides, if any.
2422
+ ArrayRef<ValueDecl *> getOverriddenDecls () const ;
2423
+
2424
+ // / Set the declaration that this declaration overrides.
2425
+ void setOverriddenDecl (ValueDecl *overridden) {
2426
+ (void )setOverriddenDecls (overridden);
2427
+ }
2428
+
2429
+ // / Set the declarations that this declaration overrides.
2430
+ // /
2431
+ // / \returns the ASTContext-allocated version of the array of overridden
2432
+ // / declarations.
2433
+ ArrayRef<ValueDecl *> setOverriddenDecls (ArrayRef<ValueDecl *> overridden);
2434
+
2435
+ // / Whether the overridden declarations have already been computed.
2436
+ bool overriddenDeclsComputed () const ;
2437
+
2417
2438
// / Compute the untyped overload signature for this declaration.
2418
2439
OverloadSignature getOverloadSignature () const ;
2419
2440
@@ -2807,23 +2828,19 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
2807
2828
AssociatedTypeDecl *getAssociatedTypeAnchor () const ;
2808
2829
2809
2830
// / Retrieve the (first) overridden associated type declaration, if any.
2810
- AssociatedTypeDecl *getOverriddenDecl () const ;
2831
+ AssociatedTypeDecl *getOverriddenDecl () const {
2832
+ return cast_or_null<AssociatedTypeDecl>(
2833
+ AbstractTypeParamDecl::getOverriddenDecl ());
2834
+ }
2811
2835
2812
2836
// / Retrieve the set of associated types overridden by this associated
2813
2837
// / type.
2814
- ArrayRef<AssociatedTypeDecl *> getOverriddenDecls () const ;
2815
-
2816
- // / Whether the overridden declarations have already been computed.
2817
- bool overriddenDeclsComputed () const {
2818
- return Bits.AssociatedTypeDecl .ComputedOverridden ;
2838
+ CastArrayRefView<ValueDecl *, AssociatedTypeDecl>
2839
+ getOverriddenDecls () const {
2840
+ return CastArrayRefView<ValueDecl *, AssociatedTypeDecl>(
2841
+ AbstractTypeParamDecl::getOverriddenDecls ());
2819
2842
}
2820
2843
2821
- // / Record the set of overridden declarations.
2822
- // /
2823
- // / \returns the array recorded in the AST.
2824
- ArrayRef<AssociatedTypeDecl *> setOverriddenDecls (
2825
- ArrayRef<AssociatedTypeDecl *> overridden);
2826
-
2827
2844
SourceLoc getStartLoc () const { return KeywordLoc; }
2828
2845
SourceRange getSourceRange () const ;
2829
2846
@@ -4020,8 +4037,6 @@ class AbstractStorageDecl : public ValueDecl {
4020
4037
public:
4021
4038
static const size_t MaxNumAccessors = 255 ;
4022
4039
private:
4023
- AbstractStorageDecl *OverriddenDecl;
4024
-
4025
4040
// / A record of the accessors for the declaration.
4026
4041
class alignas (1 << 3 ) AccessorRecord final :
4027
4042
private llvm::TrailingObjects<AccessorRecord, AccessorDecl*> {
@@ -4092,12 +4107,11 @@ class AbstractStorageDecl : public ValueDecl {
4092
4107
protected:
4093
4108
AbstractStorageDecl (DeclKind Kind, DeclContext *DC, DeclName Name,
4094
4109
SourceLoc NameLoc, bool supportsMutation)
4095
- : ValueDecl(Kind, DC, Name, NameLoc), OverriddenDecl( nullptr ) {
4110
+ : ValueDecl(Kind, DC, Name, NameLoc) {
4096
4111
Bits.AbstractStorageDecl .HasStorage = true ;
4097
4112
Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
4098
4113
Bits.AbstractStorageDecl .IsGetterMutating = false ;
4099
4114
Bits.AbstractStorageDecl .IsSetterMutating = true ;
4100
- Bits.AbstractStorageDecl .Overridden = false ;
4101
4115
}
4102
4116
4103
4117
void setSupportsMutationIfStillStored (bool supportsMutation) {
@@ -4292,28 +4306,9 @@ class AbstractStorageDecl : public ValueDecl {
4292
4306
getObjCSetterSelector (Identifier preferredName = Identifier()) const ;
4293
4307
4294
4308
AbstractStorageDecl *getOverriddenDecl () const {
4295
- return OverriddenDecl;
4296
- }
4297
- void setOverriddenDecl (AbstractStorageDecl *over) {
4298
- // FIXME: Hack due to broken class circularity checking.
4299
- if (over == this ) return ;
4300
- OverriddenDecl = over;
4301
- over->setIsOverridden ();
4302
- }
4303
-
4304
- // / The declaration has been overridden in the module
4305
- // /
4306
- // / Resolved during type checking
4307
- void setIsOverridden () {
4308
- Bits.AbstractStorageDecl .Overridden = true ;
4309
+ return cast_or_null<AbstractStorageDecl>(ValueDecl::getOverriddenDecl ());
4309
4310
}
4310
4311
4311
- // / Whether the declaration is later overridden in the module
4312
- // /
4313
- // / Overrides are resolved during type checking; only query this field after
4314
- // / the whole module has been checked
4315
- bool isOverridden () const { return Bits.AbstractStorageDecl .Overridden ; }
4316
-
4317
4312
// / Returns the location of 'override' keyword, if any.
4318
4313
SourceLoc getOverrideLoc () const ;
4319
4314
@@ -5171,7 +5166,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5171
5166
ParamDecl *getImplicitSelfDecl ();
5172
5167
5173
5168
// / Retrieve the declaration that this method overrides, if any.
5174
- AbstractFunctionDecl *getOverriddenDecl () const ;
5169
+ AbstractFunctionDecl *getOverriddenDecl () const {
5170
+ return cast_or_null<AbstractFunctionDecl>(ValueDecl::getOverriddenDecl ());
5171
+ }
5175
5172
5176
5173
// / Returns true if a function declaration overrides a given
5177
5174
// / method from its direct or indirect superclass.
@@ -5259,9 +5256,8 @@ class FuncDecl : public AbstractFunctionDecl {
5259
5256
5260
5257
// / \brief If this FuncDecl is an accessor for a property, this indicates
5261
5258
// / which property and what kind of accessor.
5262
- llvm::PointerUnion<FuncDecl *, BehaviorRecord *>
5263
- OverriddenOrBehaviorParamDecl;
5264
- OperatorDecl *Operator;
5259
+ BehaviorRecord *BehaviorParamDecl = nullptr ;
5260
+ OperatorDecl *Operator = nullptr ;
5265
5261
5266
5262
protected:
5267
5263
ParameterList **getParameterListBuffer (); // defined inline below
@@ -5280,9 +5276,7 @@ class FuncDecl : public AbstractFunctionDecl {
5280
5276
Name, NameLoc,
5281
5277
Throws, ThrowsLoc,
5282
5278
NumParameterLists, GenericParams),
5283
- StaticLoc (StaticLoc), FuncLoc(FuncLoc),
5284
- OverriddenOrBehaviorParamDecl(),
5285
- Operator(nullptr ) {
5279
+ StaticLoc (StaticLoc), FuncLoc(FuncLoc) {
5286
5280
assert (!Name.getBaseName ().isSpecial ());
5287
5281
5288
5282
Bits.FuncDecl .IsStatic =
@@ -5440,34 +5434,17 @@ class FuncDecl : public AbstractFunctionDecl {
5440
5434
5441
5435
// / Get the supertype method this method overrides, if any.
5442
5436
FuncDecl *getOverriddenDecl () const {
5443
- return OverriddenOrBehaviorParamDecl. dyn_cast <FuncDecl *>( );
5437
+ return cast_or_null <FuncDecl>( AbstractFunctionDecl::getOverriddenDecl () );
5444
5438
}
5445
- void setOverriddenDecl (FuncDecl *over) {
5446
- // FIXME: Hack due to broken class circularity checking.
5447
- if (over == this ) return ;
5448
5439
5449
- // A function cannot be an override if it is also a derived global decl
5450
- // (since derived decls are at global scope).
5451
- assert ((!OverriddenOrBehaviorParamDecl
5452
- || OverriddenOrBehaviorParamDecl.get <FuncDecl*>() == over)
5453
- && " function can only be one of override, derived, or behavior param" );
5454
- OverriddenOrBehaviorParamDecl = over;
5455
- over->setIsOverridden ();
5456
- }
5457
-
5458
5440
// / Get the property behavior this function serves as a parameter for, if
5459
5441
// / any.
5460
5442
BehaviorRecord *getParamBehavior () const {
5461
- return OverriddenOrBehaviorParamDecl
5462
- .dyn_cast <BehaviorRecord *>();
5443
+ return BehaviorParamDecl;
5463
5444
}
5464
5445
5465
5446
void setParamBehavior (BehaviorRecord *behavior) {
5466
- // Behavior param blocks cannot be overrides or derived.
5467
- assert ((!OverriddenOrBehaviorParamDecl
5468
- || OverriddenOrBehaviorParamDecl.is <BehaviorRecord *>())
5469
- && " function can only be one of override, derived, or behavior param" );
5470
- OverriddenOrBehaviorParamDecl = behavior;
5447
+ BehaviorParamDecl = behavior;
5471
5448
}
5472
5449
5473
5450
OperatorDecl *getOperatorDecl () const {
@@ -5861,10 +5838,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
5861
5838
// / inserted at the end of the initializer by SILGen.
5862
5839
Expr *CallToSuperInit = nullptr ;
5863
5840
5864
- // / The constructor this overrides, which only makes sense when
5865
- // / both the overriding and the overridden constructors are abstract.
5866
- ConstructorDecl *OverriddenDecl = nullptr ;
5867
-
5868
5841
public:
5869
5842
ConstructorDecl (DeclName Name, SourceLoc ConstructorLoc,
5870
5843
OptionalTypeKind Failability, SourceLoc FailabilityLoc,
@@ -6017,13 +5990,9 @@ class ConstructorDecl : public AbstractFunctionDecl {
6017
5990
Bits.ConstructorDecl .HasStubImplementation = stub;
6018
5991
}
6019
5992
6020
- ConstructorDecl *getOverriddenDecl () const { return OverriddenDecl; }
6021
- void setOverriddenDecl (ConstructorDecl *over) {
6022
- // FIXME: Hack due to broken class circularity checking.
6023
- if (over == this ) return ;
6024
-
6025
- OverriddenDecl = over;
6026
- over->setIsOverridden ();
5993
+ ConstructorDecl *getOverriddenDecl () const {
5994
+ return cast_or_null<ConstructorDecl>(
5995
+ AbstractFunctionDecl::getOverriddenDecl ());
6027
5996
}
6028
5997
6029
5998
// / Determine whether this initializer falls into the special case for
@@ -6650,7 +6619,7 @@ std::pair<DefaultArgumentKind, Type>
6650
6619
getDefaultArgumentInfo (ValueDecl *source, unsigned Index);
6651
6620
6652
6621
// / Display ValueDecl subclasses.
6653
- void simple_display (llvm::raw_ostream &out, const ValueDecl *& decl);
6622
+ void simple_display (llvm::raw_ostream &out, const ValueDecl *decl);
6654
6623
6655
6624
} // end namespace swift
6656
6625
0 commit comments