Skip to content

Commit fc41265

Browse files
authored
Merge pull request swiftlang#79711 from tshortli/availability-diagnostics
AST/Sema: Adopt `AvailabilityDomain` arguments in diagnostics
2 parents 54ada67 + 309db1c commit fc41265

26 files changed

+287
-272
lines changed

include/swift/AST/ASTContext.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace swift {
7272
class AbstractFunctionDecl;
7373
class ASTContext;
7474
enum class Associativity : unsigned char;
75+
class AvailabilityDomain;
7576
class AvailabilityMacroMap;
7677
class AvailabilityRange;
7778
class BoundGenericType;
@@ -1596,9 +1597,10 @@ class ASTContext final {
15961597
public:
15971598
clang::DarwinSDKInfo *getDarwinSDKInfo() const;
15981599

1599-
/// Returns the string to use in diagnostics when printing the platform being
1600-
/// targetted.
1601-
StringRef getTargetPlatformStringForDiagnostics() const;
1600+
/// Returns the availability domain corresponding to the target triple. If
1601+
/// there isn't a `PlatformKind` associated with the current target triple,
1602+
/// then this returns the universal domain (`*`).
1603+
AvailabilityDomain getTargetAvailabilityDomain() const;
16021604
};
16031605

16041606
} // end namespace swift

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/DiagnosticEngine.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define SWIFT_BASIC_DIAGNOSTICENGINE_H
2020

2121
#include "swift/AST/ActorIsolation.h"
22+
#include "swift/AST/AvailabilityDomain.h"
2223
#include "swift/AST/DeclNameLoc.h"
2324
#include "swift/AST/DiagnosticConsumer.h"
2425
#include "swift/AST/TypeLoc.h"
@@ -143,6 +144,7 @@ namespace swift {
143144
DescriptiveDeclKind,
144145
DescriptiveStmtKind,
145146
DeclAttribute,
147+
AvailabilityDomain,
146148
VersionTuple,
147149
LayoutConstraint,
148150
ActorIsolation,
@@ -179,6 +181,7 @@ namespace swift {
179181
DescriptiveDeclKind DescriptiveDeclKindVal;
180182
StmtKind DescriptiveStmtKindVal;
181183
const DeclAttribute *DeclAttributeVal;
184+
AvailabilityDomain AvailabilityDomainVal;
182185
llvm::VersionTuple VersionVal;
183186
LayoutConstraint LayoutConstraintVal;
184187
ActorIsolation ActorIsolationVal;
@@ -278,6 +281,10 @@ namespace swift {
278281
: Kind(DiagnosticArgumentKind::DeclAttribute),
279282
DeclAttributeVal(attr) {}
280283

284+
DiagnosticArgument(const AvailabilityDomain domain)
285+
: Kind(DiagnosticArgumentKind::AvailabilityDomain),
286+
AvailabilityDomainVal(domain) {}
287+
281288
DiagnosticArgument(llvm::VersionTuple version)
282289
: Kind(DiagnosticArgumentKind::VersionTuple),
283290
VersionVal(version) { }
@@ -400,6 +407,11 @@ namespace swift {
400407
return DeclAttributeVal;
401408
}
402409

410+
const AvailabilityDomain getAsAvailabilityDomain() const {
411+
assert(Kind == DiagnosticArgumentKind::AvailabilityDomain);
412+
return AvailabilityDomainVal;
413+
}
414+
403415
llvm::VersionTuple getAsVersionTuple() const {
404416
assert(Kind == DiagnosticArgumentKind::VersionTuple);
405417
return VersionVal;

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/DiagnosticsIRGen.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ERROR(attr_objc_implementation_resilient_property_deployment_target, none,
7575
"'@implementation' on %0 %1 does not support stored properties whose "
7676
"size can change due to library evolution; raise the minimum deployment "
7777
"target to %0 %2 or store this value in an object or 'any' type",
78-
(StringRef, const llvm::VersionTuple, const llvm::VersionTuple))
78+
(AvailabilityDomain, const llvm::VersionTuple, const llvm::VersionTuple))
7979

8080
ERROR(unable_to_load_pass_plugin,none,
8181
"unable to load plugin '%0': '%1'", (StringRef, StringRef))

0 commit comments

Comments
 (0)