Skip to content

Commit 325ab91

Browse files
committed
[NFC] Adopt new features in availability diagnostics
Allows the removal of a helper function.
1 parent 1d6b041 commit 325ab91

7 files changed

+64
-138
lines changed

include/swift/AST/DiagnosticEngine.h

-7
Original file line numberDiff line numberDiff line change
@@ -1498,13 +1498,6 @@ namespace swift {
14981498
const StringRef Message;
14991499
};
15001500

1501-
/// Returns a value that can be used to select between accessor kinds in
1502-
/// diagnostics.
1503-
///
1504-
/// This is correlated with diag::availability_deprecated and others.
1505-
std::pair<unsigned, DeclName>
1506-
getAccessorKindAndNameForDiagnostics(const ValueDecl *D);
1507-
15081501
/// Retrieve the macro name for a generated source info that represents
15091502
/// a macro expansion.
15101503
DeclName getGeneratedSourceInfoMacroName(const GeneratedSourceInfo &info);

include/swift/AST/DiagnosticsIDE.def

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ NOTE(ide_redundant_import_indirect, none,
3838
"module %0 is already imported via another module import", (StringRef))
3939

4040
WARNING(ide_availability_softdeprecated, Deprecation,
41-
"%select{getter for |setter for |}0%1 will be deprecated"
42-
" in %select{a future version|%select{a future version of %3|%3 %5}4}2"
43-
"%select{|: %6}6",
44-
(unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple,
41+
"%0 will be deprecated"
42+
" in %select{a future version|%select{a future version of %2|%2 %4}3}1"
43+
"%select{|: %5}5",
44+
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple,
4545
StringRef))
4646

4747
WARNING(ide_availability_softdeprecated_rename, Deprecation,
48-
"%select{getter for |setter for |}0%1 will be deprecated"
49-
" in %select{a future version|%select{a future version of %3|%3 %5}4}2"
50-
": renamed to '%6'",
51-
(unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple, StringRef))
48+
"%0 will be deprecated"
49+
" in %select{a future version|%select{a future version of %2|%2 %4}3}1"
50+
": renamed to '%5'",
51+
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple, StringRef))
5252

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

include/swift/AST/DiagnosticsSema.def

+24-38
Original file line numberDiff line numberDiff line change
@@ -3638,14 +3638,13 @@ ERROR(attr_not_on_decl_with_invalid_access_level,none,
36383638
(DeclAttribute, AccessLevel))
36393639

36403640
ERROR(attr_has_no_effect_decl_not_available_before,none,
3641-
"'%0' has no effect because %select{getter for |setter for |}1%2 is not "
3642-
"available before %3 %4",
3643-
(DeclAttribute, unsigned, DeclName, StringRef, llvm::VersionTuple))
3641+
"'%0' has no effect because %1 is not "
3642+
"available before %2 %3",
3643+
(DeclAttribute, const ValueDecl *, StringRef, llvm::VersionTuple))
36443644

36453645
ERROR(attr_has_no_effect_on_unavailable_decl,none,
3646-
"'%0' has no effect because %select{getter for |setter for |}1%2 is "
3647-
"unavailable on %3",
3648-
(DeclAttribute, unsigned, DeclName, StringRef))
3646+
"'%0' has no effect because %1 is unavailable on %2",
3647+
(DeclAttribute, const ValueDecl *, StringRef))
36493648

36503649
ERROR(attr_ambiguous_reference_to_decl,none,
36513650
"ambiguous reference to %0 in '@%1' attribute", (DeclNameRef, StringRef))
@@ -6212,52 +6211,39 @@ NOTE(type_eraser_init_spi,none,
62126211
//------------------------------------------------------------------------------
62136212

62146213
ERROR(availability_decl_unavailable, none,
6215-
"%select{getter for |setter for |}0%1 is unavailable"
6216-
"%select{ in %3|}2%select{|: %4}4",
6217-
(unsigned, DeclName, bool, StringRef, StringRef))
6218-
6219-
WARNING(availability_decl_unavailable_warn, none,
6220-
"%select{getter for |setter for |}0%1 is unavailable"
6221-
"%select{ in %3|}2%select{|: %4}4",
6222-
(unsigned, DeclName, bool, StringRef, StringRef))
6214+
"%0 is unavailable%select{ in %2|}1%select{|: %3}3",
6215+
(const ValueDecl *, bool, StringRef, StringRef))
62236216

62246217
#define REPLACEMENT_DECL_KIND_SELECT "select{| instance method| property}"
62256218
ERROR(availability_decl_unavailable_rename, none,
6226-
"%select{getter for |setter for |}0%1 has been "
6227-
"%select{renamed to|replaced by}2%" REPLACEMENT_DECL_KIND_SELECT "3 "
6228-
"'%4'%select{|: %5}5",
6229-
(unsigned, DeclName, bool, unsigned, StringRef, StringRef))
6230-
6231-
WARNING(availability_decl_unavailable_rename_warn, none,
6232-
"%select{getter for |setter for |}0%1 has been "
6233-
"%select{renamed to|replaced by}2%" REPLACEMENT_DECL_KIND_SELECT "3 "
6234-
"'%4'%select{|: %5}5",
6235-
(unsigned, DeclName, bool, unsigned, StringRef, StringRef))
6219+
"%0 has been %select{renamed to|replaced by}1"
6220+
"%" REPLACEMENT_DECL_KIND_SELECT "2 '%3'%select{|: %4}4",
6221+
(const ValueDecl *, bool, unsigned, StringRef, StringRef))
62366222

62376223
NOTE(availability_marked_unavailable, none,
6238-
"%select{getter for |setter for |}0%1 has been explicitly marked "
6239-
"unavailable here", (unsigned, DeclName))
6224+
"%0 has been explicitly marked unavailable here",
6225+
(const ValueDecl *))
62406226

62416227
NOTE(availability_introduced_in_version, none,
6242-
"%select{getter for |setter for |}0%1 was introduced in %2 %3",
6243-
(unsigned, DeclName, StringRef, llvm::VersionTuple))
6228+
"%0 was introduced in %1 %2",
6229+
(const ValueDecl *, StringRef, llvm::VersionTuple))
62446230

62456231
NOTE(availability_obsoleted, none,
6246-
"%select{getter for |setter for |}0%1 was obsoleted in %2 %3",
6247-
(unsigned, DeclName, StringRef, llvm::VersionTuple))
6232+
"%0 was obsoleted in %1 %2",
6233+
(const ValueDecl *, StringRef, llvm::VersionTuple))
62486234

62496235
WARNING(availability_deprecated, Deprecation,
6250-
"%select{getter for |setter for |}0%1 %select{is|%select{is|was}4}2 "
6251-
"deprecated%select{| in %3%select{| %5}4}2%select{|: %6}6",
6252-
(unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple,
6236+
"%0 %select{is|%select{is|was}3}1 "
6237+
"deprecated%select{| in %2%select{| %4}3}1%select{|: %5}5",
6238+
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple,
62536239
StringRef))
62546240

62556241
WARNING(availability_deprecated_rename, Deprecation,
6256-
"%select{getter for |setter for |}0%1 %select{is|%select{is|was}4}2 "
6257-
"deprecated%select{| in %3%select{| %5}4}2: "
6258-
"%select{renamed to|replaced by}6%" REPLACEMENT_DECL_KIND_SELECT "7 "
6259-
"'%8'",
6260-
(unsigned, DeclName, bool, StringRef, bool, llvm::VersionTuple, bool,
6242+
"%0 %select{is|%select{is|was}3}1 "
6243+
"deprecated%select{| in %2%select{| %4}3}1: "
6244+
"%select{renamed to|replaced by}5%" REPLACEMENT_DECL_KIND_SELECT "6 "
6245+
"'%7'",
6246+
(const ValueDecl *, bool, StringRef, bool, llvm::VersionTuple, bool,
62616247
unsigned, StringRef))
62626248
#undef REPLACEMENT_DECL_KIND_SELECT
62636249

lib/AST/DiagnosticEngine.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -1577,22 +1577,6 @@ EncodedDiagnosticMessage::EncodedDiagnosticMessage(StringRef S)
15771577
/*IsLastSegment=*/true,
15781578
/*IndentToStrip=*/~0U)) {}
15791579

1580-
std::pair<unsigned, DeclName>
1581-
swift::getAccessorKindAndNameForDiagnostics(const ValueDecl *D) {
1582-
// This should always be one more than the last AccessorKind supported in
1583-
// the diagnostics. If you need to change it, change the assertion below as
1584-
// well.
1585-
static const unsigned NOT_ACCESSOR_INDEX = 2;
1586-
1587-
if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
1588-
DeclName Name = accessor->getStorage()->getName();
1589-
assert(accessor->isGetterOrSetter());
1590-
return {static_cast<unsigned>(accessor->getAccessorKind()), Name};
1591-
}
1592-
1593-
return {NOT_ACCESSOR_INDEX, D->getName()};
1594-
}
1595-
15961580
DeclName
15971581
swift::getGeneratedSourceInfoMacroName(const GeneratedSourceInfo &info) {
15981582
ASTNode expansionNode = ASTNode::getFromOpaqueValue(info.astNode);

lib/IDE/CodeCompletionDiagnostics.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
8686
if (!Attr)
8787
return true;
8888

89-
DeclName Name;
90-
unsigned RawAccessorKind;
91-
std::tie(RawAccessorKind, Name) = getAccessorKindAndNameForDiagnostics(D);
92-
// FIXME: 'RawAccessorKind' is always 2 (NOT_ACCESSOR_INDEX).
93-
// Code completion doesn't offer accessors. It only emits 'VarDecl's.
89+
// FIXME: Code completion doesn't offer accessors. It only emits 'VarDecl's.
9490
// So getter/setter specific availability doesn't work in code completion.
9591

9692
StringRef Platform = Attr->prettyPlatformString();
@@ -101,18 +97,18 @@ bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
10197
if (!isSoftDeprecated) {
10298
if (Attr->Message.empty() && Attr->Rename.empty()) {
10399
getDiagnostics(severity, Out, diag::availability_deprecated,
104-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
100+
D, Attr->hasPlatform(), Platform,
105101
Attr->Deprecated.has_value(), DeprecatedVersion,
106102
/*message*/ StringRef());
107103
} else if (!Attr->Message.empty()) {
108104
EncodedDiagnosticMessage EncodedMessage(Attr->Message);
109105
getDiagnostics(severity, Out, diag::availability_deprecated,
110-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
106+
D, Attr->hasPlatform(), Platform,
111107
Attr->Deprecated.has_value(), DeprecatedVersion,
112108
EncodedMessage.Message);
113109
} else {
114110
getDiagnostics(severity, Out, diag::availability_deprecated_rename,
115-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
111+
D, Attr->hasPlatform(), Platform,
116112
Attr->Deprecated.has_value(), DeprecatedVersion, false,
117113
/*ReplaceKind*/ 0, Attr->Rename);
118114
}
@@ -125,18 +121,18 @@ bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
125121

126122
if (Attr->Message.empty() && Attr->Rename.empty()) {
127123
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated,
128-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
124+
D, Attr->hasPlatform(), Platform,
129125
!isDistantFuture, DeprecatedVersion,
130126
/*message*/ StringRef());
131127
} else if (!Attr->Message.empty()) {
132128
EncodedDiagnosticMessage EncodedMessage(Attr->Message);
133129
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated,
134-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
130+
D, Attr->hasPlatform(), Platform,
135131
!isDistantFuture, DeprecatedVersion,
136132
EncodedMessage.Message);
137133
} else {
138134
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated_rename,
139-
RawAccessorKind, Name, Attr->hasPlatform(), Platform,
135+
D, Attr->hasPlatform(), Platform,
140136
!isDistantFuture, DeprecatedVersion, Attr->Rename);
141137
}
142138
}

lib/Sema/TypeCheckAttr.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -4406,13 +4406,10 @@ void AttributeChecker::checkBackDeployedAttrs(
44064406

44074407
if (unavailableAttr->Platform == PlatformKind::none ||
44084408
unavailableAttr->Platform == Attr->Platform) {
4409-
DeclName name;
4410-
unsigned accessorKind;
4411-
std::tie(accessorKind, name) = getAccessorKindAndNameForDiagnostics(VD);
44124409
diagnose(AtLoc, diag::attr_has_no_effect_on_unavailable_decl, Attr,
4413-
accessorKind, name, prettyPlatformString(Platform));
4410+
VD, prettyPlatformString(Platform));
44144411
diagnose(unavailableAttr->AtLoc, diag::availability_marked_unavailable,
4415-
accessorKind, name)
4412+
VD)
44164413
.highlight(unavailableAttr->getRange());
44174414
continue;
44184415
}
@@ -4424,15 +4421,11 @@ void AttributeChecker::checkBackDeployedAttrs(
44244421
if (auto availableRangeAttrPair = VD->getSemanticAvailableRangeAttr()) {
44254422
auto availableAttr = availableRangeAttrPair.value().first;
44264423
if (Attr->Version <= availableAttr->Introduced.value()) {
4427-
DeclName name;
4428-
unsigned accessorKind;
4429-
std::tie(accessorKind, name) = getAccessorKindAndNameForDiagnostics(VD);
44304424
diagnose(AtLoc, diag::attr_has_no_effect_decl_not_available_before,
4431-
Attr, accessorKind, name, prettyPlatformString(Platform),
4425+
Attr, VD, prettyPlatformString(Platform),
44324426
Attr->Version);
44334427
diagnose(availableAttr->AtLoc, diag::availability_introduced_in_version,
4434-
accessorKind, name,
4435-
prettyPlatformString(availableAttr->Platform),
4428+
VD, prettyPlatformString(availableAttr->Platform),
44364429
*availableAttr->Introduced)
44374430
.highlight(availableAttr->getRange());
44384431
continue;

0 commit comments

Comments
 (0)