Skip to content

Commit 9edd9ee

Browse files
committed
AST: Finish adopting SemanticAvailableAttr in AvailabilityInference utilities.
1 parent a882ac6 commit 9edd9ee

6 files changed

+31
-33
lines changed

include/swift/AST/AvailabilityInference.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
namespace swift {
2626
class ASTContext;
27-
class AvailableAttr;
2827
class BackDeployedAttr;
2928
class Decl;
29+
class SemanticAvailableAttr;
3030

3131
class AvailabilityInference {
3232
public:
@@ -63,26 +63,26 @@ class AvailabilityInference {
6363
/// values to the re-mapped platform's, if using a fallback platform.
6464
/// Returns `true` if a remap occured.
6565
static bool updateIntroducedPlatformForFallback(
66-
const AvailableAttr *attr, const ASTContext &Ctx,
66+
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
6767
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
6868

6969
/// For the attribute's deprecation version, update the platform and version
7070
/// values to the re-mapped platform's, if using a fallback platform.
7171
/// Returns `true` if a remap occured.
7272
static bool updateDeprecatedPlatformForFallback(
73-
const AvailableAttr *attr, const ASTContext &Ctx,
73+
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
7474
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
7575

7676
/// For the attribute's obsoletion version, update the platform and version
7777
/// values to the re-mapped platform's, if using a fallback platform.
7878
/// Returns `true` if a remap occured.
7979
static bool updateObsoletedPlatformForFallback(
80-
const AvailableAttr *attr, const ASTContext &Ctx,
80+
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
8181
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
8282

83-
static void updatePlatformStringForFallback(
84-
const AvailableAttr *attr, const ASTContext &Ctx,
85-
llvm::StringRef &Platform);
83+
static void updatePlatformStringForFallback(const SemanticAvailableAttr &attr,
84+
const ASTContext &Ctx,
85+
llvm::StringRef &Platform);
8686

8787
/// For the attribute's before version, update the platform and version
8888
/// values to the re-mapped platform's, if using a fallback platform.

lib/AST/Attr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ SemanticAvailableAttr::getVersionAvailability(const ASTContext &ctx) const {
22612261
StringRef ObsoletedPlatform;
22622262
llvm::VersionTuple RemappedObsoletedVersion;
22632263
if (AvailabilityInference::updateObsoletedPlatformForFallback(
2264-
attr, ctx, ObsoletedPlatform, RemappedObsoletedVersion))
2264+
*this, ctx, ObsoletedPlatform, RemappedObsoletedVersion))
22652265
ObsoletedVersion = RemappedObsoletedVersion;
22662266

22672267
// If this entity was obsoleted before or at the query platform version,
@@ -2273,7 +2273,7 @@ SemanticAvailableAttr::getVersionAvailability(const ASTContext &ctx) const {
22732273
StringRef IntroducedPlatform;
22742274
llvm::VersionTuple RemappedIntroducedVersion;
22752275
if (AvailabilityInference::updateIntroducedPlatformForFallback(
2276-
attr, ctx, IntroducedPlatform, RemappedIntroducedVersion))
2276+
*this, ctx, IntroducedPlatform, RemappedIntroducedVersion))
22772277
IntroducedVersion = RemappedIntroducedVersion;
22782278

22792279
// If this entity was introduced after the query version and we're doing a

lib/AST/Availability.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ getRemappedDeprecatedObsoletedVersionForFallbackPlatform(
345345
}
346346

347347
bool 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

367367
bool 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

387387
bool 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

407406
void 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
}
@@ -531,8 +531,7 @@ std::optional<SemanticAvailableAttr> Decl::getDeprecatedAttr() const {
531531
StringRef deprecatedPlatform;
532532
llvm::VersionTuple remappedDeprecatedVersion;
533533
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
534-
attr.getParsedAttr(), ctx, deprecatedPlatform,
535-
remappedDeprecatedVersion))
534+
attr, ctx, deprecatedPlatform, remappedDeprecatedVersion))
536535
deprecatedVersion = remappedDeprecatedVersion;
537536

538537
if (!deprecatedVersion.has_value())
@@ -839,7 +838,7 @@ SemanticAvailableAttr::getIntroducedRange(const ASTContext &Ctx) const {
839838
StringRef Platform;
840839
llvm::VersionTuple RemappedIntroducedVersion;
841840
if (AvailabilityInference::updateIntroducedPlatformForFallback(
842-
attr, Ctx, Platform, RemappedIntroducedVersion))
841+
*this, Ctx, Platform, RemappedIntroducedVersion))
843842
IntroducedVersion = RemappedIntroducedVersion;
844843

845844
return AvailabilityRange{VersionRange::allGTE(IntroducedVersion)};

lib/IDE/CodeCompletionDiagnostics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
9494

9595
llvm::VersionTuple RemappedDeprecatedVersion;
9696
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
97-
Attr.getParsedAttr(), Ctx, Platform, RemappedDeprecatedVersion))
97+
Attr, Ctx, Platform, RemappedDeprecatedVersion))
9898
DeprecatedVersion = RemappedDeprecatedVersion;
9999

100100
auto Message = Attr.getMessage();

lib/Sema/TypeCheckAttr.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -5025,8 +5025,7 @@ void AttributeChecker::checkBackDeployedAttrs(
50255025
AvailabilityInference::updateBeforePlatformForFallback(
50265026
Attr, Ctx, beforePlatformString, beforeVersion);
50275027
AvailabilityInference::updateIntroducedPlatformForFallback(
5028-
availableAttr.getParsedAttr(), Ctx, introPlatformString,
5029-
introVersion);
5028+
availableAttr, Ctx, introPlatformString, introVersion);
50305029

50315030
if (Attr->Version <= introVersion) {
50325031
diagnose(AtLoc, diag::attr_has_no_effect_decl_not_available_before,

lib/Sema/TypeCheckAvailability.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ static void diagnoseIfDeprecated(SourceRange ReferenceRange,
28452845
// FIXME: [availability] Remap before emitting diagnostic above.
28462846
llvm::VersionTuple RemappedDeprecatedVersion;
28472847
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
2848-
Attr->getParsedAttr(), Context, Platform, RemappedDeprecatedVersion))
2848+
*Attr, Context, Platform, RemappedDeprecatedVersion))
28492849
DeprecatedVersion = RemappedDeprecatedVersion;
28502850

28512851
SmallString<32> newNameBuf;
@@ -2920,7 +2920,7 @@ static bool diagnoseIfDeprecated(SourceLoc loc,
29202920

29212921
llvm::VersionTuple remappedDeprecatedVersion;
29222922
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
2923-
attr->getParsedAttr(), ctx, platform, remappedDeprecatedVersion))
2923+
*attr, ctx, platform, remappedDeprecatedVersion))
29242924
deprecatedVersion = remappedDeprecatedVersion;
29252925

29262926
auto message = attr->getMessage();
@@ -3575,7 +3575,7 @@ bool diagnoseExplicitUnavailability(
35753575
} else {
35763576
auto unavailableDiagnosticPlatform = platform;
35773577
AvailabilityInference::updatePlatformStringForFallback(
3578-
Attr.getParsedAttr(), ctx, unavailableDiagnosticPlatform);
3578+
Attr, ctx, unavailableDiagnosticPlatform);
35793579
EncodedDiagnosticMessage EncodedMessage(message);
35803580
diags
35813581
.diagnose(Loc, diag::availability_decl_unavailable, D, platform.empty(),

0 commit comments

Comments
 (0)