@@ -156,7 +156,7 @@ static void mergeWithInferredAvailability(SemanticAvailableAttr Attr,
156156 // The merge of two introduction versions is the maximum of the two versions.
157157 if (mergeIntoInferredVersion (Attr.getIntroduced (), Inferred.Introduced ,
158158 std::max)) {
159- Inferred.IsSPI = ParsedAttr-> isSPI ();
159+ Inferred.IsSPI = Attr. isSPI ();
160160 }
161161
162162 // The merge of deprecated and obsoleted versions takes the minimum.
@@ -345,10 +345,10 @@ getRemappedDeprecatedObsoletedVersionForFallbackPlatform(
345345}
346346
347347bool AvailabilityInference::updateIntroducedPlatformForFallback (
348- const AvailableAttr * attr, const ASTContext &Ctx, llvm::StringRef &Platform ,
349- llvm::VersionTuple &PlatformVer) {
350- std::optional<llvm::VersionTuple> IntroducedVersion = attr-> Introduced ;
351- if (attr-> getPlatform () == PlatformKind::iOS &&
348+ const SemanticAvailableAttr & attr, const ASTContext &Ctx,
349+ llvm::StringRef &Platform, llvm:: VersionTuple &PlatformVer) {
350+ std::optional<llvm::VersionTuple> IntroducedVersion = attr. getIntroduced () ;
351+ if (attr. getPlatform () == PlatformKind::iOS &&
352352 IntroducedVersion.has_value () &&
353353 isPlatformActive (PlatformKind::visionOS, Ctx.LangOpts )) {
354354 // We re-map the iOS introduced version to the corresponding visionOS version
@@ -365,10 +365,10 @@ bool AvailabilityInference::updateIntroducedPlatformForFallback(
365365}
366366
367367bool AvailabilityInference::updateDeprecatedPlatformForFallback (
368- const AvailableAttr * attr, const ASTContext &Ctx, llvm::StringRef &Platform ,
369- llvm::VersionTuple &PlatformVer) {
370- std::optional<llvm::VersionTuple> DeprecatedVersion = attr-> Deprecated ;
371- if (attr-> getPlatform () == PlatformKind::iOS &&
368+ const SemanticAvailableAttr & attr, const ASTContext &Ctx,
369+ llvm::StringRef &Platform, llvm:: VersionTuple &PlatformVer) {
370+ std::optional<llvm::VersionTuple> DeprecatedVersion = attr. getDeprecated () ;
371+ if (attr. getPlatform () == PlatformKind::iOS &&
372372 DeprecatedVersion.has_value () &&
373373 isPlatformActive (PlatformKind::visionOS, Ctx.LangOpts )) {
374374 // We re-map the iOS deprecated version to the corresponding visionOS version
@@ -385,11 +385,10 @@ bool AvailabilityInference::updateDeprecatedPlatformForFallback(
385385}
386386
387387bool AvailabilityInference::updateObsoletedPlatformForFallback (
388- const AvailableAttr *attr, const ASTContext &Ctx, llvm::StringRef &Platform,
389- llvm::VersionTuple &PlatformVer) {
390- std::optional<llvm::VersionTuple> ObsoletedVersion = attr->Obsoleted ;
391- if (attr->getPlatform () == PlatformKind::iOS &&
392- ObsoletedVersion.has_value () &&
388+ const SemanticAvailableAttr &attr, const ASTContext &Ctx,
389+ llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer) {
390+ std::optional<llvm::VersionTuple> ObsoletedVersion = attr.getObsoleted ();
391+ if (attr.getPlatform () == PlatformKind::iOS && ObsoletedVersion.has_value () &&
393392 isPlatformActive (PlatformKind::visionOS, Ctx.LangOpts )) {
394393 // We re-map the iOS obsoleted version to the corresponding visionOS version
395394 auto PotentiallyRemappedObsoletedVersion =
@@ -405,8 +404,9 @@ bool AvailabilityInference::updateObsoletedPlatformForFallback(
405404}
406405
407406void AvailabilityInference::updatePlatformStringForFallback (
408- const AvailableAttr *attr, const ASTContext &Ctx, llvm::StringRef &Platform) {
409- if (attr->getPlatform () == PlatformKind::iOS &&
407+ const SemanticAvailableAttr &attr, const ASTContext &Ctx,
408+ llvm::StringRef &Platform) {
409+ if (attr.getPlatform () == PlatformKind::iOS &&
410410 isPlatformActive (PlatformKind::visionOS, Ctx.LangOpts )) {
411411 Platform = swift::prettyPlatformString (PlatformKind::visionOS);
412412 }
@@ -468,8 +468,9 @@ Decl::getSemanticAvailableAttrs(bool includeInactive) const {
468468std::optional<SemanticAvailableAttr>
469469Decl::getSemanticAvailableAttr (const AvailableAttr *attr) const {
470470 auto domainForAvailableAttr = [](const AvailableAttr *attr) {
471- if (attr->hasPlatform ())
472- return AvailabilityDomain::forPlatform (attr->getPlatform ());
471+ auto platform = attr->getPlatform ();
472+ if (platform != PlatformKind::none)
473+ return AvailabilityDomain::forPlatform (platform);
473474
474475 switch (attr->getPlatformAgnosticAvailability ()) {
475476 case PlatformAgnosticAvailabilityKind::Deprecated:
@@ -530,8 +531,7 @@ std::optional<SemanticAvailableAttr> Decl::getDeprecatedAttr() const {
530531 StringRef deprecatedPlatform;
531532 llvm::VersionTuple remappedDeprecatedVersion;
532533 if (AvailabilityInference::updateDeprecatedPlatformForFallback (
533- attr.getParsedAttr (), ctx, deprecatedPlatform,
534- remappedDeprecatedVersion))
534+ attr, ctx, deprecatedPlatform, remappedDeprecatedVersion))
535535 deprecatedVersion = remappedDeprecatedVersion;
536536
537537 if (!deprecatedVersion.has_value ())
@@ -821,21 +821,24 @@ AvailabilityRange AvailabilityInference::availableRange(const Decl *D) {
821821
822822bool AvailabilityInference::isAvailableAsSPI (const Decl *D) {
823823 if (auto attr = D->getAvailableAttrForPlatformIntroduction ())
824- return attr->getParsedAttr ()-> isSPI ();
824+ return attr->isSPI ();
825825
826826 return false ;
827827}
828828
829829AvailabilityRange
830- SemanticAvailableAttr::getIntroducedRange (ASTContext &Ctx) const {
830+ SemanticAvailableAttr::getIntroducedRange (const ASTContext &Ctx) const {
831+ assert (domain.isActive (Ctx));
832+
831833 auto *attr = getParsedAttr ();
832- assert (attr->isActivePlatform (Ctx));
834+ if (!attr->Introduced .has_value ())
835+ return AvailabilityRange::alwaysAvailable ();
833836
834837 llvm::VersionTuple IntroducedVersion = attr->Introduced .value ();
835- StringRef Platform = attr-> prettyPlatformString () ;
838+ StringRef Platform;
836839 llvm::VersionTuple RemappedIntroducedVersion;
837840 if (AvailabilityInference::updateIntroducedPlatformForFallback (
838- attr , Ctx, Platform, RemappedIntroducedVersion))
841+ * this , Ctx, Platform, RemappedIntroducedVersion))
839842 IntroducedVersion = RemappedIntroducedVersion;
840843
841844 return AvailabilityRange{VersionRange::allGTE (IntroducedVersion)};
0 commit comments