@@ -340,7 +340,12 @@ class alignas(1 << DeclAlignInBits) Decl {
340
340
IsUserAccessible : 1
341
341
);
342
342
343
- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 ,
343
+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 ,
344
+ // / Whether a keypath component can directly reference this storage,
345
+ // / or if it must use the overridden declaration instead.
346
+ HasComputedValidKeyPathComponent : 1 ,
347
+ ValidKeyPathComponent : 1 ,
348
+
344
349
// / Whether this property is a type property (currently unfortunately
345
350
// / called 'static').
346
351
IsStatic : 1
@@ -388,7 +393,7 @@ class alignas(1 << DeclAlignInBits) Decl {
388
393
SWIFT_INLINE_BITFIELD (SubscriptDecl, VarDecl, 2 ,
389
394
StaticSpelling : 2
390
395
);
391
- SWIFT_INLINE_BITFIELD (AbstractFunctionDecl, ValueDecl, 3 +8 +1 +1 +1 +1 +1 +1 ,
396
+ SWIFT_INLINE_BITFIELD (AbstractFunctionDecl, ValueDecl, 3 +8 +1 +1 +1 +1 +1 +1 + 1 + 1 ,
392
397
// / \see AbstractFunctionDecl::BodyKind
393
398
BodyKind : 3 ,
394
399
@@ -404,6 +409,12 @@ class alignas(1 << DeclAlignInBits) Decl {
404
409
// / Whether the function body throws.
405
410
Throws : 1 ,
406
411
412
+ // / Whether this function requires a new vtable entry.
413
+ NeedsNewVTableEntry : 1 ,
414
+
415
+ // / Whether NeedsNewVTableEntry is valid.
416
+ HasComputedNeedsNewVTableEntry : 1 ,
417
+
407
418
// / Whether this member was synthesized as part of a derived
408
419
// / protocol conformance.
409
420
Synthesized : 1 ,
@@ -412,10 +423,7 @@ class alignas(1 << DeclAlignInBits) Decl {
412
423
HasSingleExpressionBody : 1
413
424
);
414
425
415
- SWIFT_INLINE_BITFIELD (FuncDecl, AbstractFunctionDecl, 1 +1 +2 +1 +1 +2 ,
416
- // / Whether we've computed the 'static' flag yet.
417
- IsStaticComputed : 1 ,
418
-
426
+ SWIFT_INLINE_BITFIELD (FuncDecl, AbstractFunctionDecl, 1 +2 +1 +1 +2 ,
419
427
// / Whether this function is a 'static' method.
420
428
IsStatic : 1 ,
421
429
@@ -851,6 +859,17 @@ class alignas(1 << DeclAlignInBits) Decl {
851
859
return getValidationState () > ValidationState::Unchecked;
852
860
}
853
861
862
+ // / Manually indicate that validation is complete for the declaration. For
863
+ // / example: during importing, code synthesis, or derived conformances.
864
+ // /
865
+ // / For normal code validation, please use DeclValidationRAII instead.
866
+ // /
867
+ // / FIXME -- Everything should use DeclValidationRAII instead of this.
868
+ void setValidationToChecked () {
869
+ if (!isBeingValidated ())
870
+ Bits.Decl .ValidationState = unsigned (ValidationState::Checked);
871
+ }
872
+
854
873
bool escapedFromIfConfig () const {
855
874
return Bits.Decl .EscapedFromIfConfig ;
856
875
}
@@ -2591,9 +2610,6 @@ class ValueDecl : public Decl {
2591
2610
// / if the base declaration is \c open, the override might have to be too.
2592
2611
bool hasOpenAccess (const DeclContext *useDC) const ;
2593
2612
2594
- // / FIXME: This is deprecated.
2595
- bool isRecursiveValidation () const ;
2596
-
2597
2613
// / Retrieve the "interface" type of this value, which uses
2598
2614
// / GenericTypeParamType if the declaration is generic. For a generic
2599
2615
// / function, this will have a GenericFunctionType with a
@@ -2753,6 +2769,12 @@ class ValueDecl : public Decl {
2753
2769
// / Get the representative for this value's opaque result type, if it has one.
2754
2770
OpaqueReturnTypeRepr *getOpaqueResultTypeRepr () const ;
2755
2771
2772
+ // / Set the opaque return type decl for this decl.
2773
+ // /
2774
+ // / `this` must be of a decl type that supports opaque return types, and
2775
+ // / must not have previously had an opaque result type set.
2776
+ void setOpaqueResultTypeDecl (OpaqueTypeDecl *D);
2777
+
2756
2778
// / Retrieve the attribute associating this declaration with a
2757
2779
// / function builder, if there is one.
2758
2780
CustomAttr *getAttachedFunctionBuilder () const ;
@@ -4513,6 +4535,10 @@ class AbstractStorageDecl : public ValueDecl {
4513
4535
Bits.AbstractStorageDecl .IsStatic = IsStatic;
4514
4536
}
4515
4537
4538
+ void computeIsValidKeyPathComponent ();
4539
+
4540
+ OpaqueTypeDecl *OpaqueReturn = nullptr ;
4541
+
4516
4542
public:
4517
4543
4518
4544
// / Should this declaration be treated as if annotated with transparent
@@ -4753,9 +4779,18 @@ class AbstractStorageDecl : public ValueDecl {
4753
4779
// / property from the given module?
4754
4780
bool isResilient (ModuleDecl *M, ResilienceExpansion expansion) const ;
4755
4781
4782
+ void setIsValidKeyPathComponent (bool value) {
4783
+ Bits.AbstractStorageDecl .HasComputedValidKeyPathComponent = true ;
4784
+ Bits.AbstractStorageDecl .ValidKeyPathComponent = value;
4785
+ }
4786
+
4756
4787
// / True if the storage can be referenced by a keypath directly.
4757
4788
// / Otherwise, its override must be referenced.
4758
- bool isValidKeyPathComponent () const ;
4789
+ bool isValidKeyPathComponent () const {
4790
+ if (!Bits.AbstractStorageDecl .HasComputedValidKeyPathComponent )
4791
+ const_cast <AbstractStorageDecl *>(this )->computeIsValidKeyPathComponent ();
4792
+ return Bits.AbstractStorageDecl .ValidKeyPathComponent ;
4793
+ }
4759
4794
4760
4795
// / True if the storage exports a property descriptor for key paths in
4761
4796
// / other modules.
@@ -4770,6 +4805,14 @@ class AbstractStorageDecl : public ValueDecl {
4770
4805
4771
4806
bool hasAnyDynamicReplacementAccessors () const ;
4772
4807
4808
+ OpaqueTypeDecl *getOpaqueResultTypeDecl () const {
4809
+ return OpaqueReturn;
4810
+ }
4811
+ void setOpaqueResultTypeDecl (OpaqueTypeDecl *decl) {
4812
+ assert (!OpaqueReturn && " already has opaque type decl" );
4813
+ OpaqueReturn = decl;
4814
+ }
4815
+
4773
4816
// Implement isa/cast/dyncast/etc.
4774
4817
static bool classof (const Decl *D) {
4775
4818
return D->getKind () >= DeclKind::First_AbstractStorageDecl &&
@@ -5547,8 +5590,6 @@ class ImportAsMemberStatus {
5547
5590
5548
5591
// / Base class for function-like declarations.
5549
5592
class AbstractFunctionDecl : public GenericContext , public ValueDecl {
5550
- friend class NeedsNewVTableEntryRequest ;
5551
-
5552
5593
public:
5553
5594
enum class BodyKind {
5554
5595
// / The function did not have a body in the source code file.
@@ -5618,11 +5659,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5618
5659
// / Location of the 'throws' token.
5619
5660
SourceLoc ThrowsLoc;
5620
5661
5621
- struct {
5622
- unsigned NeedsNewVTableEntryComputed : 1 ;
5623
- unsigned NeedsNewVTableEntry : 1 ;
5624
- } LazySemanticInfo = { };
5625
-
5626
5662
AbstractFunctionDecl (DeclKind Kind, DeclContext *Parent, DeclName Name,
5627
5663
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
5628
5664
bool HasImplicitSelfDecl,
@@ -5634,6 +5670,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5634
5670
Bits.AbstractFunctionDecl .HasImplicitSelfDecl = HasImplicitSelfDecl;
5635
5671
Bits.AbstractFunctionDecl .Overridden = false ;
5636
5672
Bits.AbstractFunctionDecl .Throws = Throws;
5673
+ Bits.AbstractFunctionDecl .NeedsNewVTableEntry = false ;
5674
+ Bits.AbstractFunctionDecl .HasComputedNeedsNewVTableEntry = false ;
5637
5675
Bits.AbstractFunctionDecl .Synthesized = false ;
5638
5676
Bits.AbstractFunctionDecl .HasSingleExpressionBody = false ;
5639
5677
}
@@ -5803,9 +5841,16 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5803
5841
return getBodyKind () == BodyKind::MemberwiseInitializer;
5804
5842
}
5805
5843
5806
- // / For a method of a class, checks whether it will require a new entry in the
5807
- // / vtable.
5808
- bool needsNewVTableEntry () const ;
5844
+ void setNeedsNewVTableEntry (bool value) {
5845
+ Bits.AbstractFunctionDecl .HasComputedNeedsNewVTableEntry = true ;
5846
+ Bits.AbstractFunctionDecl .NeedsNewVTableEntry = value;
5847
+ }
5848
+
5849
+ bool needsNewVTableEntry () const {
5850
+ if (!Bits.AbstractFunctionDecl .HasComputedNeedsNewVTableEntry )
5851
+ const_cast <AbstractFunctionDecl *>(this )->computeNeedsNewVTableEntry ();
5852
+ return Bits.AbstractFunctionDecl .NeedsNewVTableEntry ;
5853
+ }
5809
5854
5810
5855
bool isEffectiveLinkageMoreVisibleThan (ValueDecl *other) const {
5811
5856
return (std::min (getEffectiveAccess (), AccessLevel::Public) >
@@ -5947,13 +5992,14 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SelfAccessKind SAK);
5947
5992
class FuncDecl : public AbstractFunctionDecl {
5948
5993
friend class AbstractFunctionDecl ;
5949
5994
friend class SelfAccessKindRequest ;
5950
- friend class IsStaticRequest ;
5951
5995
5952
5996
SourceLoc StaticLoc; // Location of the 'static' token or invalid.
5953
5997
SourceLoc FuncLoc; // Location of the 'func' token.
5954
5998
5955
5999
TypeLoc FnRetType;
5956
6000
6001
+ OpaqueTypeDecl *OpaqueReturn = nullptr ;
6002
+
5957
6003
protected:
5958
6004
FuncDecl (DeclKind Kind,
5959
6005
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
@@ -5969,14 +6015,14 @@ class FuncDecl : public AbstractFunctionDecl {
5969
6015
StaticLoc (StaticLoc), FuncLoc(FuncLoc) {
5970
6016
assert (!Name.getBaseName ().isSpecial ());
5971
6017
6018
+ Bits.FuncDecl .IsStatic =
6019
+ StaticLoc.isValid () || StaticSpelling != StaticSpellingKind::None;
5972
6020
Bits.FuncDecl .StaticSpelling = static_cast <unsigned >(StaticSpelling);
5973
6021
5974
6022
Bits.FuncDecl .ForcedStaticDispatch = false ;
5975
6023
Bits.FuncDecl .SelfAccess =
5976
6024
static_cast <unsigned >(SelfAccessKind::NonMutating);
5977
6025
Bits.FuncDecl .SelfAccessComputed = false ;
5978
- Bits.FuncDecl .IsStaticComputed = false ;
5979
- Bits.FuncDecl .IsStatic = false ;
5980
6026
}
5981
6027
5982
6028
private:
@@ -5996,13 +6042,6 @@ class FuncDecl : public AbstractFunctionDecl {
5996
6042
return None;
5997
6043
}
5998
6044
5999
- Optional<bool > getCachedIsStatic () const {
6000
- if (Bits.FuncDecl .IsStaticComputed )
6001
- return Bits.FuncDecl .IsStatic ;
6002
-
6003
- return None;
6004
- }
6005
-
6006
6045
public:
6007
6046
// / Factory function only for use by deserialization.
6008
6047
static FuncDecl *createDeserialized (ASTContext &Context, SourceLoc StaticLoc,
@@ -6025,16 +6064,16 @@ class FuncDecl : public AbstractFunctionDecl {
6025
6064
6026
6065
Identifier getName () const { return getFullName ().getBaseIdentifier (); }
6027
6066
6028
- bool isStatic () const ;
6029
-
6067
+ bool isStatic () const {
6068
+ return Bits.FuncDecl .IsStatic ;
6069
+ }
6030
6070
// / \returns the way 'static'/'class' was spelled in the source.
6031
6071
StaticSpellingKind getStaticSpelling () const {
6032
6072
return static_cast <StaticSpellingKind>(Bits.FuncDecl .StaticSpelling );
6033
6073
}
6034
6074
// / \returns the way 'static'/'class' should be spelled for this declaration.
6035
6075
StaticSpellingKind getCorrectStaticSpelling () const ;
6036
6076
void setStatic (bool IsStatic = true ) {
6037
- Bits.FuncDecl .IsStaticComputed = true ;
6038
6077
Bits.FuncDecl .IsStatic = IsStatic;
6039
6078
}
6040
6079
@@ -6106,7 +6145,15 @@ class FuncDecl : public AbstractFunctionDecl {
6106
6145
}
6107
6146
6108
6147
OperatorDecl *getOperatorDecl () const ;
6109
-
6148
+
6149
+ OpaqueTypeDecl *getOpaqueResultTypeDecl () const {
6150
+ return OpaqueReturn;
6151
+ }
6152
+ void setOpaqueResultTypeDecl (OpaqueTypeDecl *decl) {
6153
+ assert (!OpaqueReturn && " already has opaque type decl" );
6154
+ OpaqueReturn = decl;
6155
+ }
6156
+
6110
6157
// / Returns true if the function is forced to be statically dispatched.
6111
6158
bool hasForcedStaticDispatch () const {
6112
6159
return Bits.FuncDecl .ForcedStaticDispatch ;
0 commit comments