Skip to content

Commit a0930de

Browse files
committed
AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSema.def
1 parent d93b6a4 commit a0930de

27 files changed

+452
-513
lines changed

include/swift/AST/DiagnosticsCommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#include "swift/Config.h"
2525

2626
namespace swift {
27+
class AccessorDecl;
2728
class ConstructorDecl;
29+
class MacroDecl;
30+
class SubscriptDecl;
2831
class SwitchStmt;
2932
class TypeAliasDecl;
3033

include/swift/AST/DiagnosticsSema.def

Lines changed: 233 additions & 209 deletions
Large diffs are not rendered by default.

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,9 +1267,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
12671267
inheritedType->getDeclContext()->getSelfNominalTypeDecl();
12681268
ctx.Diags.diagnose(assocTypeDecl,
12691269
diag::associated_type_override_typealias,
1270-
assocTypeDecl->getName(),
1271-
inheritedOwningDecl->getDescriptiveKind(),
1272-
inheritedOwningDecl->getDeclaredInterfaceType());
1270+
assocTypeDecl->getName(), inheritedOwningDecl);
12731271

12741272
recordInheritedTypeRequirement(assocTypeDecl, inheritedType);
12751273
}

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,17 +3411,16 @@ namespace {
34113411
auto &DE = ctx.Diags;
34123412
DE.diagnose(UDE->getLoc(),
34133413
diag::warn_deprecated_conditional_conformance_outer_access,
3414-
UDE->getName(),
3415-
choice->getDescriptiveKind(), choiceParentDecl,
3416-
innerChoice->getDescriptiveKind(), innerParentDecl);
3414+
UDE->getName(), choice, choiceParentDecl, innerChoice,
3415+
innerParentDecl);
34173416

34183417
auto name = choiceParentDecl->getName().getBaseIdentifier();
34193418
SmallString<32> namePlusDot = name.str();
34203419
namePlusDot.push_back('.');
34213420

34223421
DE.diagnose(UDE->getLoc(),
34233422
diag::fix_deprecated_conditional_conformance_outer_access,
3424-
namePlusDot, choice->getDescriptiveKind())
3423+
namePlusDot, choice)
34253424
.fixItInsert(UDE->getStartLoc(), namePlusDot);
34263425
}
34273426

@@ -5052,8 +5051,7 @@ namespace {
50525051

50535052
de.diagnose(E->getLoc(), diag::expr_selector_not_objc, foundDecl)
50545053
.highlight(subExpr->getSourceRange());
5055-
de.diagnose(foundDecl, diag::make_decl_objc,
5056-
foundDecl->getDescriptiveKind())
5054+
de.diagnose(foundDecl, diag::make_decl_objc, foundDecl)
50575055
.fixItInsert(foundDecl->getAttributeInsertionLoc(false), "@objc ");
50585056
return E;
50595057
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ bool AssignmentFailure::diagnoseAsError() {
22742274

22752275
if (foundProperty != results.end()) {
22762276
auto startLoc = immutableExpr->getStartLoc();
2277-
auto *property = *foundProperty;
2277+
auto *property = cast<VarDecl>(*foundProperty);
22782278
auto selfTy = typeContext->getSelfTypeInContext();
22792279

22802280
// If we found an instance property, suggest inserting "self.",
@@ -2286,7 +2286,7 @@ bool AssignmentFailure::diagnoseAsError() {
22862286
fixItText = selfTy->getString() + ".";
22872287
}
22882288
emitDiagnosticAt(startLoc, diag::masked_mutable_property, fixItText,
2289-
property->getDescriptiveKind(), selfTy)
2289+
property, selfTy)
22902290
.fixItInsert(startLoc, fixItText);
22912291
}
22922292
}
@@ -3565,9 +3565,8 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
35653565

35663566
// Emit a diagnostic to inform the user that they need to conform to the
35673567
// missing protocols.
3568-
auto conformanceDiag =
3569-
emitDiagnostic(diag::assign_protocol_conformance_fix_it, constraint,
3570-
nominal->getDescriptiveKind(), fromType);
3568+
auto conformanceDiag = emitDiagnostic(
3569+
diag::assign_protocol_conformance_fix_it, constraint, nominal);
35713570
if (!nominal->getInherited().empty()) {
35723571
auto lastInheritedEndLoc = nominal->getInherited().getEndLoc();
35733572
conformanceDiag.fixItInsertAfter(lastInheritedEndLoc, ", " + protoString);
@@ -6461,7 +6460,7 @@ bool InvalidMutatingMethodRefInKeyPath::diagnoseAsError() {
64616460
}
64626461

64636462
bool InvalidAsyncOrThrowsMethodRefInKeyPath::diagnoseAsError() {
6464-
emitDiagnostic(diag::effectful_keypath_component, getKind(),
6463+
emitDiagnostic(diag::effectful_keypath_component, getMember(),
64656464
isForKeyPathDynamicMemberLookup());
64666465
return true;
64676466
}
@@ -7242,10 +7241,10 @@ bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
72427241
name.isSpecial()
72437242
? emitDiagnosticAt(args->getLoc(),
72447243
diag::single_tuple_parameter_mismatch_special,
7245-
choice->getDescriptiveKind(), paramTy, subsStr)
7246-
: emitDiagnosticAt(
7247-
args->getLoc(), diag::single_tuple_parameter_mismatch_normal,
7248-
choice, paramTy, subsStr);
7244+
choice, paramTy, subsStr)
7245+
: emitDiagnosticAt(args->getLoc(),
7246+
diag::single_tuple_parameter_mismatch_normal,
7247+
choice, paramTy, subsStr);
72497248

72507249
auto newLeftParenLoc = args->getStartLoc();
72517250
auto firstArgLabel = args->getLabel(0);
@@ -8442,7 +8441,8 @@ bool MissingQualifierInMemberRefFailure::diagnoseAsError() {
84428441
return true;
84438442
}
84448443

8445-
auto qualifier = DC->getParentModule()->getName();
8444+
auto *module = DC->getParentModule();
8445+
auto qualifier = module->getName();
84468446

84478447
emitDiagnostic(diag::member_shadows_global_function, UDE->getName(),
84488448
methodKind, choice, qualifier);
@@ -8451,7 +8451,7 @@ bool MissingQualifierInMemberRefFailure::diagnoseAsError() {
84518451
namePlusDot.push_back('.');
84528452

84538453
emitDiagnostic(diag::fix_unqualified_access_top_level_multi, namePlusDot,
8454-
choice->getDescriptiveKind(), qualifier)
8454+
choice, module)
84558455
.fixItInsert(UDE->getStartLoc(), namePlusDot);
84568456

84578457
emitDiagnosticAt(choice, diag::decl_declared_here, choice);

lib/Sema/CodeSynthesis.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,10 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
403403
decl->getDeclaredType(), existingIsolation, isolation)
404404
.warnUntilSwiftVersion(6);
405405
if (previousVar) {
406-
previousVar->diagnose(
407-
diag::property_requires_actor,
408-
previousVar->getDescriptiveKind(),
409-
previousVar->getName(), existingIsolation);
406+
previousVar->diagnose(diag::property_requires_actor,
407+
previousVar, existingIsolation);
410408
}
411-
var->diagnose(
412-
diag::property_requires_actor,
413-
var->getDescriptiveKind(),
414-
var->getName(), isolation);
409+
var->diagnose(diag::property_requires_actor, var, isolation);
415410
hasError = true;
416411
return false;
417412
}

lib/Sema/DerivedConformance/DerivedConformance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ void DerivedConformance::diagnoseIfSynthesisUnsupportedForDecl(
274274

275275
if (shouldDiagnose) {
276276
auto &ctx = nominal->getASTContext();
277-
ctx.Diags.diagnose(
278-
nominal->getLoc(), diag::automatic_protocol_synthesis_unsupported,
279-
protocol->getName().str(), nominal->getDescriptiveKind());
277+
ctx.Diags.diagnose(nominal->getLoc(),
278+
diag::automatic_protocol_synthesis_unsupported, protocol,
279+
nominal);
280280
}
281281
}
282282

lib/Sema/MiscDiagnostics.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
343343
if (auto asd = dyn_cast<AbstractStorageDecl>(decl)) {
344344
if (asd->getEffectfulGetAccessor()) {
345345
Ctx.Diags.diagnose(component.getLoc(),
346-
diag::effectful_keypath_component,
347-
asd->getDescriptiveKind(),
346+
diag::effectful_keypath_component, asd,
348347
/*dynamic member lookup*/ false);
349348
Ctx.Diags.diagnose(asd->getLoc(), diag::kind_declared_here,
350349
asd->getDescriptiveKind());
@@ -807,9 +806,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
807806
declParent = VD->getDeclContext()->getParentModule();
808807
}
809808

810-
Ctx.Diags.diagnose(DRE->getLoc(), diag::warn_unqualified_access,
811-
VD->getBaseIdentifier(),
812-
VD->getDescriptiveKind(),
809+
Ctx.Diags.diagnose(DRE->getLoc(), diag::warn_unqualified_access, VD,
813810
declParent);
814811
Ctx.Diags.diagnose(VD, diag::decl_declared_here, VD);
815812

@@ -847,14 +844,13 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
847844
topLevelDiag = diag::fix_unqualified_access_top_level_multi;
848845

849846
for (const ModuleValuePair &pair : sortedResults) {
850-
DescriptiveDeclKind k = pair.second->getDescriptiveKind();
851-
852847
SmallString<32> namePlusDot = pair.first->getName().str();
853848
namePlusDot.push_back('.');
854849

855-
Ctx.Diags.diagnose(DRE->getLoc(), topLevelDiag,
856-
namePlusDot, k, pair.first->getName())
857-
.fixItInsert(DRE->getStartLoc(), namePlusDot);
850+
Ctx.Diags
851+
.diagnose(DRE->getLoc(), topLevelDiag, namePlusDot, pair.second,
852+
pair.first)
853+
.fixItInsert(DRE->getStartLoc(), namePlusDot);
858854
}
859855
}
860856

lib/Sema/TypeCheckAccess.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void AccessControlCheckerBase::checkGenericParamAccess(
499499
if (downgradeToWarning == DowngradeToWarning::Yes)
500500
diagID = diag::generic_param_usable_from_inline_warn;
501501
auto diag =
502-
Context.Diags.diagnose(ownerDecl, diagID, ownerDecl->getDescriptiveKind(),
502+
Context.Diags.diagnose(ownerDecl, diagID, ownerDecl,
503503
accessControlErrorKind == ACEK::Requirement);
504504
highlightOffendingType(diag, complainRepr);
505505
noteLimitingImport(/*userDecl*/nullptr, Context, minImportLimit, complainRepr);
@@ -515,9 +515,8 @@ void AccessControlCheckerBase::checkGenericParamAccess(
515515
if (downgradeToWarning == DowngradeToWarning::Yes)
516516
diagID = diag::generic_param_access_warn;
517517
auto diag = Context.Diags.diagnose(
518-
ownerDecl, diagID, ownerDecl->getDescriptiveKind(), isExplicit,
519-
contextAccess, minAccess, isa<FileUnit>(DC),
520-
accessControlErrorKind == ACEK::Requirement);
518+
ownerDecl, diagID, ownerDecl, isExplicit, contextAccess, minAccess,
519+
isa<FileUnit>(DC), accessControlErrorKind == ACEK::Requirement);
521520
highlightOffendingType(diag, complainRepr);
522521
noteLimitingImport(/*userDecl*/nullptr, Context, minImportLimit, complainRepr);
523522
}

0 commit comments

Comments
 (0)