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"
@@ -319,10 +320,7 @@ class alignas(1 << DeclAlignInBits) Decl {
319
320
IsUserAccessible : 1
320
321
);
321
322
322
- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +1 ,
323
- // / Whether we are overridden later
324
- Overridden : 1 ,
325
-
323
+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 ,
326
324
// / Whether the getter is mutating.
327
325
IsGetterMutating : 1 ,
328
326
@@ -582,11 +580,6 @@ class alignas(1 << DeclAlignInBits) Decl {
582
580
Associativity : 2
583
581
);
584
582
585
- SWIFT_INLINE_BITFIELD (AssociatedTypeDecl, ValueDecl, 1 +1 ,
586
- ComputedOverridden : 1 ,
587
- HasOverridden : 1
588
- );
589
-
590
583
SWIFT_INLINE_BITFIELD (ImportDecl, Decl, 3 +8 ,
591
584
ImportKind : 3 ,
592
585
@@ -2181,6 +2174,13 @@ class ValueDecl : public Decl {
2181
2174
2182
2175
// / Whether this declaration is exposed to Objective-C.
2183
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
2184
} LazySemanticInfo;
2185
2185
2186
2186
protected:
@@ -2193,6 +2193,8 @@ class ValueDecl : public Decl {
2193
2193
Bits.ValueDecl .IsUserAccessible = true ;
2194
2194
LazySemanticInfo.isObjCComputed = false ;
2195
2195
LazySemanticInfo.isObjC = false ;
2196
+ LazySemanticInfo.hasOverriddenComputed = false ;
2197
+ LazySemanticInfo.hasOverridden = false ;
2196
2198
}
2197
2199
2198
2200
// MemberLookupTable borrows a bit from this type
@@ -2416,6 +2418,23 @@ class ValueDecl : public Decl {
2416
2418
// / Retrieve the declaration that this declaration overrides, if any.
2417
2419
ValueDecl *getOverriddenDecl () const ;
2418
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
+
2419
2438
// / Compute the untyped overload signature for this declaration.
2420
2439
OverloadSignature getOverloadSignature () const ;
2421
2440
@@ -2809,23 +2828,19 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
2809
2828
AssociatedTypeDecl *getAssociatedTypeAnchor () const ;
2810
2829
2811
2830
// / Retrieve the (first) overridden associated type declaration, if any.
2812
- AssociatedTypeDecl *getOverriddenDecl () const ;
2831
+ AssociatedTypeDecl *getOverriddenDecl () const {
2832
+ return cast_or_null<AssociatedTypeDecl>(
2833
+ AbstractTypeParamDecl::getOverriddenDecl ());
2834
+ }
2813
2835
2814
2836
// / Retrieve the set of associated types overridden by this associated
2815
2837
// / type.
2816
- ArrayRef<AssociatedTypeDecl *> getOverriddenDecls () const ;
2817
-
2818
- // / Whether the overridden declarations have already been computed.
2819
- bool overriddenDeclsComputed () const {
2820
- return Bits.AssociatedTypeDecl .ComputedOverridden ;
2838
+ CastArrayRefView<ValueDecl *, AssociatedTypeDecl>
2839
+ getOverriddenDecls () const {
2840
+ return CastArrayRefView<ValueDecl *, AssociatedTypeDecl>(
2841
+ AbstractTypeParamDecl::getOverriddenDecls ());
2821
2842
}
2822
2843
2823
- // / Record the set of overridden declarations.
2824
- // /
2825
- // / \returns the array recorded in the AST.
2826
- ArrayRef<AssociatedTypeDecl *> setOverriddenDecls (
2827
- ArrayRef<AssociatedTypeDecl *> overridden);
2828
-
2829
2844
SourceLoc getStartLoc () const { return KeywordLoc; }
2830
2845
SourceRange getSourceRange () const ;
2831
2846
@@ -4022,8 +4037,6 @@ class AbstractStorageDecl : public ValueDecl {
4022
4037
public:
4023
4038
static const size_t MaxNumAccessors = 255 ;
4024
4039
private:
4025
- AbstractStorageDecl *OverriddenDecl;
4026
-
4027
4040
// / A record of the accessors for the declaration.
4028
4041
class alignas (1 << 3 ) AccessorRecord final :
4029
4042
private llvm::TrailingObjects<AccessorRecord, AccessorDecl*> {
@@ -4094,12 +4107,11 @@ class AbstractStorageDecl : public ValueDecl {
4094
4107
protected:
4095
4108
AbstractStorageDecl (DeclKind Kind, DeclContext *DC, DeclName Name,
4096
4109
SourceLoc NameLoc, bool supportsMutation)
4097
- : ValueDecl(Kind, DC, Name, NameLoc), OverriddenDecl( nullptr ) {
4110
+ : ValueDecl(Kind, DC, Name, NameLoc) {
4098
4111
Bits.AbstractStorageDecl .HasStorage = true ;
4099
4112
Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
4100
4113
Bits.AbstractStorageDecl .IsGetterMutating = false ;
4101
4114
Bits.AbstractStorageDecl .IsSetterMutating = true ;
4102
- Bits.AbstractStorageDecl .Overridden = false ;
4103
4115
}
4104
4116
4105
4117
void setSupportsMutationIfStillStored (bool supportsMutation) {
@@ -4294,28 +4306,9 @@ class AbstractStorageDecl : public ValueDecl {
4294
4306
getObjCSetterSelector (Identifier preferredName = Identifier()) const ;
4295
4307
4296
4308
AbstractStorageDecl *getOverriddenDecl () const {
4297
- return OverriddenDecl;
4298
- }
4299
- void setOverriddenDecl (AbstractStorageDecl *over) {
4300
- // FIXME: Hack due to broken class circularity checking.
4301
- if (over == this ) return ;
4302
- OverriddenDecl = over;
4303
- over->setIsOverridden ();
4309
+ return cast_or_null<AbstractStorageDecl>(ValueDecl::getOverriddenDecl ());
4304
4310
}
4305
4311
4306
- // / The declaration has been overridden in the module
4307
- // /
4308
- // / Resolved during type checking
4309
- void setIsOverridden () {
4310
- Bits.AbstractStorageDecl .Overridden = true ;
4311
- }
4312
-
4313
- // / Whether the declaration is later overridden in the module
4314
- // /
4315
- // / Overrides are resolved during type checking; only query this field after
4316
- // / the whole module has been checked
4317
- bool isOverridden () const { return Bits.AbstractStorageDecl .Overridden ; }
4318
-
4319
4312
// / Returns the location of 'override' keyword, if any.
4320
4313
SourceLoc getOverrideLoc () const ;
4321
4314
@@ -5173,7 +5166,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5173
5166
ParamDecl *getImplicitSelfDecl ();
5174
5167
5175
5168
// / Retrieve the declaration that this method overrides, if any.
5176
- AbstractFunctionDecl *getOverriddenDecl () const ;
5169
+ AbstractFunctionDecl *getOverriddenDecl () const {
5170
+ return cast_or_null<AbstractFunctionDecl>(ValueDecl::getOverriddenDecl ());
5171
+ }
5177
5172
5178
5173
// / Returns true if a function declaration overrides a given
5179
5174
// / method from its direct or indirect superclass.
@@ -5261,9 +5256,8 @@ class FuncDecl : public AbstractFunctionDecl {
5261
5256
5262
5257
// / \brief If this FuncDecl is an accessor for a property, this indicates
5263
5258
// / which property and what kind of accessor.
5264
- llvm::PointerUnion<FuncDecl *, BehaviorRecord *>
5265
- OverriddenOrBehaviorParamDecl;
5266
- OperatorDecl *Operator;
5259
+ BehaviorRecord *BehaviorParamDecl = nullptr ;
5260
+ OperatorDecl *Operator = nullptr ;
5267
5261
5268
5262
protected:
5269
5263
ParameterList **getParameterListBuffer (); // defined inline below
@@ -5282,9 +5276,7 @@ class FuncDecl : public AbstractFunctionDecl {
5282
5276
Name, NameLoc,
5283
5277
Throws, ThrowsLoc,
5284
5278
NumParameterLists, GenericParams),
5285
- StaticLoc (StaticLoc), FuncLoc(FuncLoc),
5286
- OverriddenOrBehaviorParamDecl(),
5287
- Operator(nullptr ) {
5279
+ StaticLoc (StaticLoc), FuncLoc(FuncLoc) {
5288
5280
assert (!Name.getBaseName ().isSpecial ());
5289
5281
5290
5282
Bits.FuncDecl .IsStatic =
@@ -5442,34 +5434,17 @@ class FuncDecl : public AbstractFunctionDecl {
5442
5434
5443
5435
// / Get the supertype method this method overrides, if any.
5444
5436
FuncDecl *getOverriddenDecl () const {
5445
- return OverriddenOrBehaviorParamDecl. dyn_cast <FuncDecl *>( );
5437
+ return cast_or_null <FuncDecl>( AbstractFunctionDecl::getOverriddenDecl () );
5446
5438
}
5447
- void setOverriddenDecl (FuncDecl *over) {
5448
- // FIXME: Hack due to broken class circularity checking.
5449
- if (over == this ) return ;
5450
5439
5451
- // A function cannot be an override if it is also a derived global decl
5452
- // (since derived decls are at global scope).
5453
- assert ((!OverriddenOrBehaviorParamDecl
5454
- || OverriddenOrBehaviorParamDecl.get <FuncDecl*>() == over)
5455
- && " function can only be one of override, derived, or behavior param" );
5456
- OverriddenOrBehaviorParamDecl = over;
5457
- over->setIsOverridden ();
5458
- }
5459
-
5460
5440
// / Get the property behavior this function serves as a parameter for, if
5461
5441
// / any.
5462
5442
BehaviorRecord *getParamBehavior () const {
5463
- return OverriddenOrBehaviorParamDecl
5464
- .dyn_cast <BehaviorRecord *>();
5443
+ return BehaviorParamDecl;
5465
5444
}
5466
5445
5467
5446
void setParamBehavior (BehaviorRecord *behavior) {
5468
- // Behavior param blocks cannot be overrides or derived.
5469
- assert ((!OverriddenOrBehaviorParamDecl
5470
- || OverriddenOrBehaviorParamDecl.is <BehaviorRecord *>())
5471
- && " function can only be one of override, derived, or behavior param" );
5472
- OverriddenOrBehaviorParamDecl = behavior;
5447
+ BehaviorParamDecl = behavior;
5473
5448
}
5474
5449
5475
5450
OperatorDecl *getOperatorDecl () const {
@@ -5863,10 +5838,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
5863
5838
// / inserted at the end of the initializer by SILGen.
5864
5839
Expr *CallToSuperInit = nullptr ;
5865
5840
5866
- // / The constructor this overrides, which only makes sense when
5867
- // / both the overriding and the overridden constructors are abstract.
5868
- ConstructorDecl *OverriddenDecl = nullptr ;
5869
-
5870
5841
public:
5871
5842
ConstructorDecl (DeclName Name, SourceLoc ConstructorLoc,
5872
5843
OptionalTypeKind Failability, SourceLoc FailabilityLoc,
@@ -6019,13 +5990,9 @@ class ConstructorDecl : public AbstractFunctionDecl {
6019
5990
Bits.ConstructorDecl .HasStubImplementation = stub;
6020
5991
}
6021
5992
6022
- ConstructorDecl *getOverriddenDecl () const { return OverriddenDecl; }
6023
- void setOverriddenDecl (ConstructorDecl *over) {
6024
- // FIXME: Hack due to broken class circularity checking.
6025
- if (over == this ) return ;
6026
-
6027
- OverriddenDecl = over;
6028
- over->setIsOverridden ();
5993
+ ConstructorDecl *getOverriddenDecl () const {
5994
+ return cast_or_null<ConstructorDecl>(
5995
+ AbstractFunctionDecl::getOverriddenDecl ());
6029
5996
}
6030
5997
6031
5998
// / Determine whether this initializer falls into the special case for
0 commit comments