Skip to content

Commit c89df2f

Browse files
committed
AST/Sema: Adopt AvailabilityDomain arguments in more diagnostics.
Update explicit unavailability and deprecation diagnostics to take `AvailabiiltyDomain` instead of a platform string.
1 parent 272b2b4 commit c89df2f

File tree

9 files changed

+143
-148
lines changed

9 files changed

+143
-148
lines changed

include/swift/AST/AvailabilityInference.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace swift {
2626
class ASTContext;
27+
class AvailabilityDomain;
2728
class BackDeployedAttr;
2829
class Decl;
2930
class SemanticAvailableAttr;
@@ -62,35 +63,35 @@ class AvailabilityInference {
6263
/// For the attribute's introduction version, update the platform and version
6364
/// values to the re-mapped platform's, if using a fallback platform.
6465
/// Returns `true` if a remap occured.
65-
static bool updateIntroducedPlatformForFallback(
66-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
67-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
66+
static bool updateIntroducedAvailabilityDomainForFallback(
67+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
68+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);
6869

6970
/// For the attribute's deprecation version, update the platform and version
7071
/// values to the re-mapped platform's, if using a fallback platform.
7172
/// Returns `true` if a remap occured.
72-
static bool updateDeprecatedPlatformForFallback(
73-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
74-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
73+
static bool updateDeprecatedAvailabilityDomainForFallback(
74+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
75+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);
7576

7677
/// For the attribute's obsoletion version, update the platform and version
7778
/// values to the re-mapped platform's, if using a fallback platform.
7879
/// Returns `true` if a remap occured.
79-
static bool updateObsoletedPlatformForFallback(
80-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
81-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
80+
static bool updateObsoletedAvailabilityDomainForFallback(
81+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
82+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);
8283

83-
static void updatePlatformStringForFallback(const SemanticAvailableAttr &attr,
84-
const ASTContext &Ctx,
85-
llvm::StringRef &Platform);
84+
static void
85+
updateAvailabilityDomainForFallback(const SemanticAvailableAttr &attr,
86+
const ASTContext &ctx,
87+
AvailabilityDomain &domain);
8688

8789
/// For the attribute's before version, update the platform and version
8890
/// values to the re-mapped platform's, if using a fallback platform.
8991
/// Returns `true` if a remap occured.
90-
static bool updateBeforePlatformForFallback(const BackDeployedAttr *attr,
91-
const ASTContext &Ctx,
92-
llvm::StringRef &Platform,
93-
llvm::VersionTuple &PlatformVer);
92+
static bool updateBeforeAvailabilityDomainForFallback(
93+
const BackDeployedAttr *attr, const ASTContext &ctx,
94+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);
9495
};
9596

9697
// FIXME: This should become a utility on Decl.

include/swift/AST/DiagnosticsIDE.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ WARNING(ide_availability_softdeprecated, Deprecation,
3030
"%0 will be deprecated"
3131
" in %select{a future version|%select{a future version of %2|%2 %4}3}1"
3232
"%select{|: %5}5",
33-
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple,
33+
(const ValueDecl *, bool, AvailabilityDomain, bool, llvm::VersionTuple,
3434
StringRef))
3535

3636
WARNING(ide_availability_softdeprecated_rename, Deprecation,
3737
"%0 will be deprecated"
3838
" in %select{a future version|%select{a future version of %2|%2 %4}3}1"
3939
": renamed to '%5'",
40-
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple, StringRef))
40+
(const ValueDecl *, bool, AvailabilityDomain, bool, llvm::VersionTuple,
41+
StringRef))
4142

4243
WARNING(ide_recursive_accessor_reference,none,
4344
"attempting to %select{access|modify}1 %0 within its own "

include/swift/AST/DiagnosticsSema.def

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,11 +4006,11 @@ ERROR(attr_not_on_decl_with_invalid_access_level,none,
40064006
ERROR(attr_has_no_effect_decl_not_available_before,none,
40074007
"'%0' has no effect because %1 is not "
40084008
"available before %2 %3",
4009-
(DeclAttribute, const ValueDecl *, StringRef, llvm::VersionTuple))
4009+
(DeclAttribute, const ValueDecl *, AvailabilityDomain, llvm::VersionTuple))
40104010

40114011
ERROR(attr_has_no_effect_on_unavailable_decl,none,
40124012
"'%0' has no effect because %1 is unavailable on %2",
4013-
(DeclAttribute, const ValueDecl *, StringRef))
4013+
(DeclAttribute, const ValueDecl *, AvailabilityDomain))
40144014

40154015
ERROR(attr_ambiguous_reference_to_decl,none,
40164016
"ambiguous reference to %0 in '@%1' attribute", (DeclNameRef, StringRef))
@@ -6780,7 +6780,7 @@ ERROR(attr_availability_requires_custom_availability, none,
67806780

67816781
ERROR(availability_decl_unavailable, none,
67826782
"%0 is unavailable%select{ in %2|}1%select{|: %3}3",
6783-
(const ValueDecl *, bool, StringRef, StringRef))
6783+
(const ValueDecl *, bool, AvailabilityDomain, StringRef))
67846784

67856785
#define REPLACEMENT_DECL_KIND_SELECT "select{| instance method| property}"
67866786
ERROR(availability_decl_unavailable_rename, none,
@@ -6794,26 +6794,26 @@ NOTE(availability_marked_unavailable, none,
67946794

67956795
NOTE(availability_introduced_in_version, none,
67966796
"%0 was introduced in %1 %2",
6797-
(const ValueDecl *, StringRef, llvm::VersionTuple))
6797+
(const ValueDecl *, AvailabilityDomain, llvm::VersionTuple))
67986798

67996799
NOTE(availability_obsoleted, none,
68006800
"%0 was obsoleted in %1 %2",
6801-
(const ValueDecl *, StringRef, llvm::VersionTuple))
6801+
(const ValueDecl *, AvailabilityDomain, llvm::VersionTuple))
68026802

68036803
GROUPED_WARNING(availability_deprecated, DeprecatedDeclaration, Deprecation,
68046804
"%0 %select{is|%select{is|was}3}1 "
68056805
"deprecated%select{| in %2%select{| %4}3}1%select{|: %5}5",
6806-
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple,
6807-
StringRef))
6806+
(const ValueDecl *, bool, AvailabilityDomain, bool,
6807+
llvm::VersionTuple, StringRef))
68086808

68096809
GROUPED_WARNING(
68106810
availability_deprecated_rename, DeprecatedDeclaration, Deprecation,
68116811
"%0 %select{is|%select{is|was}3}1 "
68126812
"deprecated%select{| in %2%select{| %4}3}1: "
68136813
"%select{renamed to|replaced by}5%" REPLACEMENT_DECL_KIND_SELECT "6 "
68146814
"'%7'",
6815-
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple, bool,
6816-
unsigned, StringRef))
6815+
(const ValueDecl *, bool, AvailabilityDomain, bool, llvm::VersionTuple,
6816+
bool, unsigned, StringRef))
68176817
#undef REPLACEMENT_DECL_KIND_SELECT
68186818

68196819
NOTE(note_deprecated_rename, none,
@@ -6972,25 +6972,25 @@ NOTE(availability_unavailable_implicit_init, none,
69726972
ERROR(conformance_availability_unavailable, none,
69736973
"conformance of %0 to %1 is unavailable"
69746974
"%select{ in %3|}2%select{|: %4}4",
6975-
(Type, Type, bool, StringRef, StringRef))
6975+
(Type, Type, bool, AvailabilityDomain, StringRef))
69766976

69776977
NOTE(conformance_availability_marked_unavailable, none,
69786978
"conformance of %0 to %1 has been explicitly marked "
69796979
"unavailable here", (Type, Type))
69806980

69816981
NOTE(conformance_availability_introduced_in_version, none,
69826982
"conformance of %0 to %1 was introduced in %2 %3",
6983-
(Type, Type, StringRef, llvm::VersionTuple))
6983+
(Type, Type, AvailabilityDomain, llvm::VersionTuple))
69846984

69856985
NOTE(conformance_availability_obsoleted, none,
69866986
"conformance of %0 to %1 was obsoleted in %2 %3",
6987-
(Type, Type, StringRef, llvm::VersionTuple))
6987+
(Type, Type, AvailabilityDomain, llvm::VersionTuple))
69886988

69896989
GROUPED_WARNING(conformance_availability_deprecated,
69906990
DeprecatedDeclaration, Deprecation,
69916991
"conformance of %0 to %1 %select{is|%select{is|was}4}2 "
69926992
"deprecated%select{| in %3%select{| %5}4}2%select{|: %6}6",
6993-
(Type, Type, bool, StringRef, bool, llvm::VersionTuple,
6993+
(Type, Type, bool, AvailabilityDomain, bool, llvm::VersionTuple,
69946994
StringRef))
69956995

69966996
ERROR(conformance_availability_only_version_newer, none,

lib/AST/Availability.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -330,86 +330,86 @@ getRemappedDeprecatedObsoletedVersionForFallbackPlatform(
330330
return Mapping->mapDeprecatedObsoletedAvailabilityVersion(Version);
331331
}
332332

333-
bool AvailabilityInference::updateIntroducedPlatformForFallback(
334-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
335-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer) {
336-
std::optional<llvm::VersionTuple> IntroducedVersion = attr.getIntroduced();
333+
bool AvailabilityInference::updateIntroducedAvailabilityDomainForFallback(
334+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
335+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
336+
std::optional<llvm::VersionTuple> introducedVersion = attr.getIntroduced();
337337
if (attr.getPlatform() == PlatformKind::iOS &&
338-
IntroducedVersion.has_value() &&
339-
isPlatformActive(PlatformKind::visionOS, Ctx.LangOpts)) {
338+
introducedVersion.has_value() &&
339+
isPlatformActive(PlatformKind::visionOS, ctx.LangOpts)) {
340340
// We re-map the iOS introduced version to the corresponding visionOS version
341-
auto PotentiallyRemappedIntroducedVersion =
342-
getRemappedIntroducedVersionForFallbackPlatform(Ctx,
343-
*IntroducedVersion);
344-
if (PotentiallyRemappedIntroducedVersion.has_value()) {
345-
Platform = swift::prettyPlatformString(PlatformKind::visionOS);
346-
PlatformVer = PotentiallyRemappedIntroducedVersion.value();
341+
auto potentiallyRemappedIntroducedVersion =
342+
getRemappedIntroducedVersionForFallbackPlatform(ctx,
343+
*introducedVersion);
344+
if (potentiallyRemappedIntroducedVersion.has_value()) {
345+
domain = AvailabilityDomain::forPlatform(PlatformKind::visionOS);
346+
platformVer = potentiallyRemappedIntroducedVersion.value();
347347
return true;
348348
}
349349
}
350350
return false;
351351
}
352352

353-
bool AvailabilityInference::updateDeprecatedPlatformForFallback(
354-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
355-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer) {
356-
std::optional<llvm::VersionTuple> DeprecatedVersion = attr.getDeprecated();
353+
bool AvailabilityInference::updateDeprecatedAvailabilityDomainForFallback(
354+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
355+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
356+
std::optional<llvm::VersionTuple> deprecatedVersion = attr.getDeprecated();
357357
if (attr.getPlatform() == PlatformKind::iOS &&
358-
DeprecatedVersion.has_value() &&
359-
isPlatformActive(PlatformKind::visionOS, Ctx.LangOpts)) {
358+
deprecatedVersion.has_value() &&
359+
isPlatformActive(PlatformKind::visionOS, ctx.LangOpts)) {
360360
// We re-map the iOS deprecated version to the corresponding visionOS version
361-
auto PotentiallyRemappedDeprecatedVersion =
361+
auto potentiallyRemappedDeprecatedVersion =
362362
getRemappedDeprecatedObsoletedVersionForFallbackPlatform(
363-
Ctx, *DeprecatedVersion);
364-
if (PotentiallyRemappedDeprecatedVersion.has_value()) {
365-
Platform = swift::prettyPlatformString(PlatformKind::visionOS);
366-
PlatformVer = PotentiallyRemappedDeprecatedVersion.value();
363+
ctx, *deprecatedVersion);
364+
if (potentiallyRemappedDeprecatedVersion.has_value()) {
365+
domain = AvailabilityDomain::forPlatform(PlatformKind::visionOS);
366+
platformVer = potentiallyRemappedDeprecatedVersion.value();
367367
return true;
368368
}
369369
}
370370
return false;
371371
}
372372

373-
bool AvailabilityInference::updateObsoletedPlatformForFallback(
374-
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
375-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer) {
376-
std::optional<llvm::VersionTuple> ObsoletedVersion = attr.getObsoleted();
377-
if (attr.getPlatform() == PlatformKind::iOS && ObsoletedVersion.has_value() &&
378-
isPlatformActive(PlatformKind::visionOS, Ctx.LangOpts)) {
373+
bool AvailabilityInference::updateObsoletedAvailabilityDomainForFallback(
374+
const SemanticAvailableAttr &attr, const ASTContext &ctx,
375+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
376+
std::optional<llvm::VersionTuple> obsoletedVersion = attr.getObsoleted();
377+
if (attr.getPlatform() == PlatformKind::iOS && obsoletedVersion.has_value() &&
378+
isPlatformActive(PlatformKind::visionOS, ctx.LangOpts)) {
379379
// We re-map the iOS obsoleted version to the corresponding visionOS version
380-
auto PotentiallyRemappedObsoletedVersion =
380+
auto potentiallyRemappedObsoletedVersion =
381381
getRemappedDeprecatedObsoletedVersionForFallbackPlatform(
382-
Ctx, *ObsoletedVersion);
383-
if (PotentiallyRemappedObsoletedVersion.has_value()) {
384-
Platform = swift::prettyPlatformString(PlatformKind::visionOS);
385-
PlatformVer = PotentiallyRemappedObsoletedVersion.value();
382+
ctx, *obsoletedVersion);
383+
if (potentiallyRemappedObsoletedVersion.has_value()) {
384+
domain = AvailabilityDomain::forPlatform(PlatformKind::visionOS);
385+
platformVer = potentiallyRemappedObsoletedVersion.value();
386386
return true;
387387
}
388388
}
389389
return false;
390390
}
391391

392-
void AvailabilityInference::updatePlatformStringForFallback(
392+
void AvailabilityInference::updateAvailabilityDomainForFallback(
393393
const SemanticAvailableAttr &attr, const ASTContext &Ctx,
394-
llvm::StringRef &Platform) {
394+
AvailabilityDomain &domain) {
395395
if (attr.getPlatform() == PlatformKind::iOS &&
396396
isPlatformActive(PlatformKind::visionOS, Ctx.LangOpts)) {
397-
Platform = swift::prettyPlatformString(PlatformKind::visionOS);
397+
domain = AvailabilityDomain::forPlatform(PlatformKind::visionOS);
398398
}
399399
}
400400

401-
bool AvailabilityInference::updateBeforePlatformForFallback(
402-
const BackDeployedAttr *attr, const ASTContext &Ctx,
403-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer) {
404-
auto BeforeVersion = attr->Version;
401+
bool AvailabilityInference::updateBeforeAvailabilityDomainForFallback(
402+
const BackDeployedAttr *attr, const ASTContext &ctx,
403+
AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
404+
auto beforeVersion = attr->Version;
405405
if (attr->Platform == PlatformKind::iOS &&
406-
isPlatformActive(PlatformKind::visionOS, Ctx.LangOpts)) {
406+
isPlatformActive(PlatformKind::visionOS, ctx.LangOpts)) {
407407
// We re-map the iOS before version to the corresponding visionOS version
408408
auto PotentiallyRemappedIntroducedVersion =
409-
getRemappedIntroducedVersionForFallbackPlatform(Ctx, BeforeVersion);
409+
getRemappedIntroducedVersionForFallbackPlatform(ctx, beforeVersion);
410410
if (PotentiallyRemappedIntroducedVersion.has_value()) {
411-
Platform = swift::prettyPlatformString(PlatformKind::visionOS);
412-
PlatformVer = PotentiallyRemappedIntroducedVersion.value();
411+
domain = AvailabilityDomain::forPlatform(PlatformKind::visionOS);
412+
platformVer = PotentiallyRemappedIntroducedVersion.value();
413413
return true;
414414
}
415415
}
@@ -492,10 +492,10 @@ std::optional<SemanticAvailableAttr> Decl::getDeprecatedAttr() const {
492492

493493
auto deprecatedVersion = attr.getDeprecated();
494494

495-
StringRef deprecatedPlatform;
495+
AvailabilityDomain unusedDomain;
496496
llvm::VersionTuple remappedDeprecatedVersion;
497-
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
498-
attr, ctx, deprecatedPlatform, remappedDeprecatedVersion))
497+
if (AvailabilityInference::updateDeprecatedAvailabilityDomainForFallback(
498+
attr, ctx, unusedDomain, remappedDeprecatedVersion))
499499
deprecatedVersion = remappedDeprecatedVersion;
500500

501501
if (!deprecatedVersion.has_value())
@@ -892,10 +892,10 @@ SemanticAvailableAttr::getIntroducedRange(const ASTContext &Ctx) const {
892892
return AvailabilityRange::alwaysAvailable();
893893

894894
llvm::VersionTuple IntroducedVersion = getIntroduced().value();
895-
StringRef Platform;
895+
AvailabilityDomain UnusedDomain;
896896
llvm::VersionTuple RemappedIntroducedVersion;
897-
if (AvailabilityInference::updateIntroducedPlatformForFallback(
898-
*this, Ctx, Platform, RemappedIntroducedVersion))
897+
if (AvailabilityInference::updateIntroducedAvailabilityDomainForFallback(
898+
*this, Ctx, UnusedDomain, RemappedIntroducedVersion))
899899
IntroducedVersion = RemappedIntroducedVersion;
900900

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

lib/AST/AvailabilityConstraint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ getAvailabilityConstraintForAttr(const Decl *decl,
154154
std::optional<llvm::VersionTuple> obsoletedVersion = attr.getObsoleted();
155155

156156
{
157-
StringRef obsoletedPlatform;
157+
AvailabilityDomain unusedDomain;
158158
llvm::VersionTuple remappedObsoletedVersion;
159-
if (AvailabilityInference::updateObsoletedPlatformForFallback(
160-
attr, ctx, obsoletedPlatform, remappedObsoletedVersion))
159+
if (AvailabilityInference::updateObsoletedAvailabilityDomainForFallback(
160+
attr, ctx, unusedDomain, remappedObsoletedVersion))
161161
obsoletedVersion = remappedObsoletedVersion;
162162
}
163163

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,9 @@ Decl::getBackDeployedBeforeOSVersion(ASTContext &Ctx,
593593
bool forTargetVariant) const {
594594
if (auto *attr = getAttrs().getBackDeployed(Ctx, forTargetVariant)) {
595595
auto version = attr->Version;
596-
StringRef ignoredPlatformString;
597-
AvailabilityInference::updateBeforePlatformForFallback(
598-
attr, getASTContext(), ignoredPlatformString, version);
596+
AvailabilityDomain ignoredDomain;
597+
AvailabilityInference::updateBeforeAvailabilityDomainForFallback(
598+
attr, getASTContext(), ignoredDomain, version);
599599

600600
// If the remap for fallback resulted in 1.0, then the
601601
// backdeployment prior to that is not meaningful.

0 commit comments

Comments
 (0)