Skip to content

Commit 2d899d0

Browse files
committed
AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def
1 parent cdb2aac commit 2d899d0

31 files changed

+93
-111
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ enum class DescriptiveDeclKind : uint8_t {
169169
PostfixOperator,
170170
PrecedenceGroup,
171171
TypeAlias,
172+
GenericTypeAlias,
172173
GenericTypeParam,
173174
AssociatedType,
174175
Type,
@@ -183,7 +184,6 @@ enum class DescriptiveDeclKind : uint8_t {
183184
GenericClass,
184185
GenericActor,
185186
GenericDistributedActor,
186-
GenericType,
187187
Subscript,
188188
StaticSubscript,
189189
ClassSubscript,

include/swift/AST/DiagnosticsCommon.def

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
ERROR(invalid_diagnostic,none,
2424
"INTERNAL ERROR: this diagnostic should not be produced", ())
2525

26+
NOTE(kind_declname_declared_here,none,
27+
"%0 %1 declared here", (DescriptiveDeclKind, DeclName))
28+
NOTE(decl_declared_here_with_kind,none,
29+
"%kind0 declared here", (const Decl *))
30+
2631
ERROR(not_implemented,none,
2732
"INTERNAL ERROR: feature not implemented: %0", (StringRef))
2833

@@ -176,9 +181,6 @@ ERROR(circular_enum_inheritance,none,
176181
ERROR(circular_protocol_def,none,
177182
"protocol %0 refines itself", (Identifier))
178183

179-
NOTE(kind_declname_declared_here,none,
180-
"%0 %1 declared here", (DescriptiveDeclKind, DeclName))
181-
182184
WARNING(warn_property_wrapper_module_scope,none,
183185
"ignoring associated type %0 in favor of module-scoped property "
184186
"wrapper %0; please qualify the reference with %1",

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ NOTE(opaque_return_type_declared_here,none,
4242
"opaque return type declared here", ())
4343
NOTE(default_value_declared_here,none,
4444
"default value declared here", ())
45+
NOTE(requirement_declared_here,none,
46+
"requirement %0 declared here", (const ValueDecl *))
4547

4648
//------------------------------------------------------------------------------
4749
// MARK: Constraint solver diagnostics

lib/AST/Decl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ DescriptiveDeclKind Decl::getDescriptiveKind() const {
176176
TRIVIAL_KIND(InfixOperator);
177177
TRIVIAL_KIND(PrefixOperator);
178178
TRIVIAL_KIND(PostfixOperator);
179-
TRIVIAL_KIND(TypeAlias);
180179
TRIVIAL_KIND(GenericTypeParam);
181180
TRIVIAL_KIND(AssociatedType);
182181
TRIVIAL_KIND(Protocol);
@@ -190,6 +189,11 @@ DescriptiveDeclKind Decl::getDescriptiveKind() const {
190189
TRIVIAL_KIND(Macro);
191190
TRIVIAL_KIND(MacroExpansion);
192191

192+
case DeclKind::TypeAlias:
193+
return cast<TypeAliasDecl>(this)->getGenericParams()
194+
? DescriptiveDeclKind::GenericTypeAlias
195+
: DescriptiveDeclKind::TypeAlias;
196+
193197
case DeclKind::Enum:
194198
return cast<EnumDecl>(this)->getGenericParams()
195199
? DescriptiveDeclKind::GenericEnum
@@ -350,6 +354,7 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
350354
ENTRY(PrefixOperator, "prefix operator");
351355
ENTRY(PostfixOperator, "postfix operator");
352356
ENTRY(TypeAlias, "type alias");
357+
ENTRY(GenericTypeAlias, "generic type alias");
353358
ENTRY(GenericTypeParam, "generic parameter");
354359
ENTRY(AssociatedType, "associated type");
355360
ENTRY(Type, "type");
@@ -364,7 +369,6 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
364369
ENTRY(GenericClass, "generic class");
365370
ENTRY(GenericActor, "generic actor");
366371
ENTRY(GenericDistributedActor, "generic distributed actor");
367-
ENTRY(GenericType, "generic type");
368372
ENTRY(Subscript, "subscript");
369373
ENTRY(StaticSubscript, "static subscript");
370374
ENTRY(ClassSubscript, "class subscript");

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,9 +3953,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
39533953
.diagnose(loc, diag::warn_property_wrapper_module_scope, name,
39543954
moduleName)
39553955
.fixItInsert(loc, moduleName.str().str() + ".");
3956-
ctx.Diags.diagnose(assocType, diag::kind_declname_declared_here,
3957-
assocType->getDescriptiveKind(),
3958-
assocType->getName());
3956+
ctx.Diags.diagnose(assocType, diag::decl_declared_here_with_kind,
3957+
assocType);
39593958

39603959
auto *baseTR = UnqualifiedIdentTypeRepr::create(
39613960
ctx, nameLoc, DeclNameRef(moduleName));

lib/AST/NameLookupRequests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ void SuperclassDeclRequest::diagnoseCycle(DiagnosticEngine &diags) const {
5858

5959
void SuperclassDeclRequest::noteCycleStep(DiagnosticEngine &diags) const {
6060
auto decl = std::get<0>(getStorage());
61-
diags.diagnose(decl, diag::kind_declname_declared_here,
62-
decl->getDescriptiveKind(), decl->getName());
61+
diags.diagnose(decl, diag::decl_declared_here_with_kind, decl);
6362
}
6463

6564
std::optional<ClassDecl *> SuperclassDeclRequest::getCachedResult() const {

lib/AST/TypeCheckRequests.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ void EnumRawTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
217217

218218
void EnumRawTypeRequest::noteCycleStep(DiagnosticEngine &diags) const {
219219
auto *decl = std::get<0>(getStorage());
220-
diags.diagnose(decl, diag::kind_declname_declared_here,
221-
decl->getDescriptiveKind(), decl->getName());
220+
diags.diagnose(decl, diag::decl_declared_here_with_kind, decl);
222221
}
223222

224223
//----------------------------------------------------------------------------//
@@ -248,10 +247,8 @@ void ProtocolRequiresClassRequest::diagnoseCycle(DiagnosticEngine &diags) const
248247
}
249248

250249
void ProtocolRequiresClassRequest::noteCycleStep(DiagnosticEngine &diags) const {
251-
auto requirement = std::get<0>(getStorage());
252-
diags.diagnose(requirement, diag::kind_declname_declared_here,
253-
DescriptiveDeclKind::Protocol,
254-
requirement->getName());
250+
auto *proto = std::get<0>(getStorage());
251+
diags.diagnose(proto, diag::decl_declared_here_with_kind, proto);
255252
}
256253

257254
std::optional<bool> ProtocolRequiresClassRequest::getCachedResult() const {
@@ -274,9 +271,8 @@ void ExistentialConformsToSelfRequest::diagnoseCycle(DiagnosticEngine &diags) co
274271
}
275272

276273
void ExistentialConformsToSelfRequest::noteCycleStep(DiagnosticEngine &diags) const {
277-
auto requirement = std::get<0>(getStorage());
278-
diags.diagnose(requirement, diag::kind_declname_declared_here,
279-
DescriptiveDeclKind::Protocol, requirement->getName());
274+
auto *proto = std::get<0>(getStorage());
275+
diags.diagnose(proto, diag::decl_declared_here_with_kind, proto);
280276
}
281277

282278
std::optional<bool> ExistentialConformsToSelfRequest::getCachedResult() const {
@@ -301,9 +297,8 @@ void HasSelfOrAssociatedTypeRequirementsRequest::diagnoseCycle(
301297

302298
void HasSelfOrAssociatedTypeRequirementsRequest::noteCycleStep(
303299
DiagnosticEngine &diags) const {
304-
auto requirement = std::get<0>(getStorage());
305-
diags.diagnose(requirement, diag::kind_declname_declared_here,
306-
DescriptiveDeclKind::Protocol, requirement->getName());
300+
auto *proto = std::get<0>(getStorage());
301+
diags.diagnose(proto, diag::decl_declared_here_with_kind, proto);
307302
}
308303

309304
std::optional<bool>
@@ -1419,8 +1414,7 @@ void HasCircularInheritedProtocolsRequest::diagnoseCycle(
14191414
void HasCircularInheritedProtocolsRequest::noteCycleStep(
14201415
DiagnosticEngine &diags) const {
14211416
auto *decl = std::get<0>(getStorage());
1422-
diags.diagnose(decl, diag::kind_declname_declared_here,
1423-
decl->getDescriptiveKind(), decl->getName());
1417+
diags.diagnose(decl, diag::decl_declared_here_with_kind, decl);
14241418
}
14251419

14261420
//----------------------------------------------------------------------------//
@@ -1434,8 +1428,7 @@ void HasCircularRawValueRequest::diagnoseCycle(DiagnosticEngine &diags) const {
14341428

14351429
void HasCircularRawValueRequest::noteCycleStep(DiagnosticEngine &diags) const {
14361430
auto *decl = std::get<0>(getStorage());
1437-
diags.diagnose(decl, diag::kind_declname_declared_here,
1438-
decl->getDescriptiveKind(), decl->getName());
1431+
diags.diagnose(decl, diag::decl_declared_here_with_kind, decl);
14391432
}
14401433

14411434
//----------------------------------------------------------------------------//

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7161,8 +7161,7 @@ bool SkipUnhandledConstructInResultBuilderFailure::diagnoseAsError() {
71617161
}
71627162

71637163
diagnosePrimary(/*asNote=*/false);
7164-
emitDiagnosticAt(builder, diag::kind_declname_declared_here,
7165-
builder->getDescriptiveKind(), builder->getName());
7164+
emitDiagnosticAt(builder, diag::decl_declared_here_with_kind, builder);
71667165
return true;
71677166
}
71687167

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,9 +1833,7 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
18331833
proto->diagnose(diag::objc_protocol_inherits_non_objc_protocol,
18341834
proto->getDeclaredInterfaceType(),
18351835
inherited->getDeclaredInterfaceType());
1836-
inherited->diagnose(diag::kind_declname_declared_here,
1837-
DescriptiveDeclKind::Protocol,
1838-
inherited->getName());
1836+
inherited->diagnose(diag::decl_declared_here_with_kind, inherited);
18391837
isObjC = std::nullopt;
18401838
}
18411839
}

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
7373
nominal->diagnose(diag::property_wrapper_ambiguous_value_property,
7474
nominal->getDeclaredType(), name);
7575
for (auto var : vars) {
76-
var->diagnose(diag::kind_declname_declared_here,
77-
var->getDescriptiveKind(), var->getName());
76+
var->diagnose(diag::decl_declared_here_with_kind, var);
7877
}
7978
return nullptr;
8079
}
@@ -310,9 +309,7 @@ static SubscriptDecl *findEnclosingSelfSubscript(ASTContext &ctx,
310309
nominal->diagnose(diag::property_wrapper_ambiguous_enclosing_self_subscript,
311310
nominal->getDeclaredType(), subscriptName);
312311
for (auto subscript : subscripts) {
313-
subscript->diagnose(diag::kind_declname_declared_here,
314-
subscript->getDescriptiveKind(),
315-
subscript->getName());
312+
subscript->diagnose(diag::decl_declared_here_with_kind, subscript);
316313
}
317314
return nullptr;
318315

0 commit comments

Comments
 (0)