@@ -151,10 +151,14 @@ class DeclAttribute : public AttributeBase {
151
151
Value : 32
152
152
);
153
153
154
- SWIFT_INLINE_BITFIELD (AvailableAttr, DeclAttribute, 4 +1 +1 +1 ,
154
+ SWIFT_INLINE_BITFIELD (AvailableAttr, DeclAttribute, 4 +1 +1 +1 + 1 + 1 ,
155
155
// / An `AvailableAttr::Kind` value.
156
156
Kind : 4 ,
157
157
158
+ // / State storage for `SemanticAvailableAttrRequest`.
159
+ HasComputedSemanticAttr : 1 ,
160
+ HasDomain : 1 ,
161
+
158
162
// / State storage for `RenamedDeclRequest`.
159
163
HasComputedRenamedDecl : 1 ,
160
164
HasRenamedDecl : 1 ,
@@ -750,26 +754,32 @@ class AvailableAttr : public DeclAttribute {
750
754
const StringRef Message;
751
755
const StringRef Rename;
752
756
753
- const std::optional< llvm::VersionTuple> Introduced;
757
+ const llvm::VersionTuple Introduced;
754
758
const SourceRange IntroducedRange;
755
- const std::optional< llvm::VersionTuple> Deprecated;
759
+ const llvm::VersionTuple Deprecated;
756
760
const SourceRange DeprecatedRange;
757
- const std::optional< llvm::VersionTuple> Obsoleted;
761
+ const llvm::VersionTuple Obsoleted;
758
762
const SourceRange ObsoletedRange;
759
763
760
764
public:
761
765
// / Returns the parsed version for `introduced:`.
762
766
std::optional<llvm::VersionTuple> getRawIntroduced () const {
767
+ if (Introduced.empty ())
768
+ return std::nullopt;
763
769
return Introduced;
764
770
}
765
771
766
772
// / Returns the parsed version for `deprecated:`.
767
773
std::optional<llvm::VersionTuple> getRawDeprecated () const {
774
+ if (Deprecated.empty ())
775
+ return std::nullopt;
768
776
return Deprecated;
769
777
}
770
778
771
779
// / Returns the parsed version for `obsoleted:`.
772
780
std::optional<llvm::VersionTuple> getRawObsoleted () const {
781
+ if (Obsoleted.empty ())
782
+ return std::nullopt;
773
783
return Obsoleted;
774
784
}
775
785
@@ -806,14 +816,15 @@ class AvailableAttr : public DeclAttribute {
806
816
// / Returns the `AvailabilityDomain` associated with the attribute, or
807
817
// / `std::nullopt` if it has either not yet been resolved or could not be
808
818
// / resolved successfully.
809
- std::optional<AvailabilityDomain> getCachedDomain () const { return Domain; }
819
+ std::optional<AvailabilityDomain> getCachedDomain () const {
820
+ if (hasCachedDomain ())
821
+ return Domain;
822
+ return std::nullopt;
823
+ }
810
824
811
825
// / Returns true if the `AvailabilityDomain` associated with the attribute
812
826
// / has been resolved successfully.
813
- bool hasCachedDomain () const {
814
- // For now, domains are always set on construction of the attribute.
815
- return true ;
816
- }
827
+ bool hasCachedDomain () const { return Bits.AvailableAttr .HasDomain ; }
817
828
818
829
// / Returns the kind of availability the attribute specifies.
819
830
Kind getKind () const { return static_cast <Kind>(Bits.AvailableAttr .Kind ); }
@@ -873,6 +884,17 @@ class AvailableAttr : public DeclAttribute {
873
884
Bits.AvailableAttr .HasComputedRenamedDecl = true ;
874
885
Bits.AvailableAttr .HasRenamedDecl = hasRenamedDecl;
875
886
}
887
+
888
+ private:
889
+ friend class SemanticAvailableAttrRequest ;
890
+
891
+ bool hasComputedSemanticAttr () const {
892
+ return Bits.AvailableAttr .HasComputedSemanticAttr ;
893
+ }
894
+
895
+ void setComputedSemanticAttr () {
896
+ Bits.AvailableAttr .HasComputedSemanticAttr = true ;
897
+ }
876
898
};
877
899
878
900
// / Indicates that the given declaration is visible to Objective-C.
@@ -3252,7 +3274,7 @@ class SemanticAvailableAttr final {
3252
3274
3253
3275
// / The version tuple written in source for the `introduced:` component.
3254
3276
std::optional<llvm::VersionTuple> getIntroduced () const {
3255
- return attr->Introduced ;
3277
+ return attr->getRawIntroduced () ;
3256
3278
}
3257
3279
3258
3280
// / The source range of the `introduced:` component.
@@ -3264,12 +3286,12 @@ class SemanticAvailableAttr final {
3264
3286
3265
3287
// / The version tuple written in source for the `deprecated:` component.
3266
3288
std::optional<llvm::VersionTuple> getDeprecated () const {
3267
- return attr->Deprecated ;
3289
+ return attr->getRawDeprecated () ;
3268
3290
}
3269
3291
3270
3292
// / The version tuple written in source for the `obsoleted:` component.
3271
3293
std::optional<llvm::VersionTuple> getObsoleted () const {
3272
- return attr->Obsoleted ;
3294
+ return attr->getRawObsoleted () ;
3273
3295
}
3274
3296
3275
3297
// / Returns the `message:` field of the attribute, or an empty string.
@@ -3302,7 +3324,8 @@ class SemanticAvailableAttr final {
3302
3324
// / Whether this attribute has an introduced, deprecated, or obsoleted
3303
3325
// / version.
3304
3326
bool isVersionSpecific () const {
3305
- return attr->Introduced || attr->Deprecated || attr->Obsoleted ;
3327
+ return getIntroduced ().has_value () || getDeprecated ().has_value () ||
3328
+ getObsoleted ().has_value ();
3306
3329
}
3307
3330
3308
3331
// / Whether this is a language mode specific attribute.
0 commit comments