Skip to content

Commit fc2c66f

Browse files
committed
[NFC] Adopt %kind for Sema ValueDecl diagnostics
1 parent 84592b8 commit fc2c66f

21 files changed

+378
-507
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 239 additions & 249 deletions
Large diffs are not rendered by default.

lib/AST/TypeCheckRequests.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -811,14 +811,12 @@ void GenericSignatureRequest::diagnoseCycle(DiagnosticEngine &diags) const {
811811
auto *D = GC->getAsDecl();
812812

813813
if (auto *VD = dyn_cast<ValueDecl>(D)) {
814-
VD->diagnose(diag::recursive_generic_signature,
815-
VD->getDescriptiveKind(), VD->getBaseName());
814+
VD->diagnose(diag::recursive_generic_signature, VD);
816815
} else {
817816
auto *ED = cast<ExtensionDecl>(D);
818817
auto *NTD = ED->getExtendedNominal();
819818

820-
ED->diagnose(diag::recursive_generic_signature_extension,
821-
NTD->getDescriptiveKind(), NTD->getName());
819+
ED->diagnose(diag::recursive_generic_signature_extension, NTD);
822820
}
823821
}
824822

@@ -852,9 +850,7 @@ void UnderlyingTypeRequest::cacheResult(Type value) const {
852850

853851
void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
854852
auto aliasDecl = std::get<0>(getStorage());
855-
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
856-
aliasDecl->getDescriptiveKind(),
857-
aliasDecl->getName());
853+
diags.diagnose(aliasDecl, diag::recursive_decl_reference, aliasDecl);
858854
}
859855

860856
//----------------------------------------------------------------------------//
@@ -863,9 +859,7 @@ void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
863859

864860
void StructuralTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
865861
auto aliasDecl = std::get<0>(getStorage());
866-
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
867-
aliasDecl->getDescriptiveKind(),
868-
aliasDecl->getName());
862+
diags.diagnose(aliasDecl, diag::recursive_decl_reference, aliasDecl);
869863
}
870864

871865
//----------------------------------------------------------------------------//

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ namespace {
16471647
Swift3ObjCInferenceWarnings::Minimal) {
16481648
context.Diags.diagnose(
16491649
memberLoc, diag::expr_dynamic_lookup_swift3_objc_inference,
1650-
member->getDescriptiveKind(), member->getName(),
1650+
member,
16511651
member->getDeclContext()->getSelfNominalTypeDecl()->getName());
16521652
context.Diags
16531653
.diagnose(member, diag::make_decl_objc,
@@ -4844,7 +4844,7 @@ namespace {
48444844
de.diagnose(E->getModifierLoc(),
48454845
diag::expr_selector_expected_property,
48464846
E->getSelectorKind() == ObjCSelectorExpr::Setter,
4847-
foundDecl->getDescriptiveKind(), foundDecl->getName())
4847+
foundDecl)
48484848
.fixItRemoveChars(E->getModifierLoc(),
48494849
E->getSubExpr()->getStartLoc());
48504850

@@ -4914,16 +4914,15 @@ namespace {
49144914
// Make sure we actually have a setter.
49154915
if (!var->isSettable(dc)) {
49164916
de.diagnose(E->getLoc(), diag::expr_selector_property_not_settable,
4917-
var->getDescriptiveKind(), var->getName());
4917+
var);
49184918
de.diagnose(var, diag::decl_declared_here, var->getName());
49194919
return E;
49204920
}
49214921

49224922
// Make sure the setter is accessible.
49234923
if (!var->isSetterAccessibleFrom(dc)) {
49244924
de.diagnose(E->getLoc(),
4925-
diag::expr_selector_property_setter_inaccessible,
4926-
var->getDescriptiveKind(), var->getName());
4925+
diag::expr_selector_property_setter_inaccessible, var);
49274926
de.diagnose(var, diag::decl_declared_here, var->getName());
49284927
return E;
49294928
}
@@ -4954,8 +4953,7 @@ namespace {
49544953
return E;
49554954
}
49564955

4957-
de.diagnose(E->getLoc(), diag::expr_selector_not_objc,
4958-
foundDecl->getDescriptiveKind(), foundDecl->getName())
4956+
de.diagnose(E->getLoc(), diag::expr_selector_not_objc, foundDecl)
49594957
.highlight(subExpr->getSourceRange());
49604958
de.diagnose(foundDecl, diag::make_decl_objc,
49614959
foundDecl->getDescriptiveKind())
@@ -4968,10 +4966,9 @@ namespace {
49684966
cs.getASTContext().LangOpts.WarnSwift3ObjCInference ==
49694967
Swift3ObjCInferenceWarnings::Minimal) {
49704968
de.diagnose(E->getLoc(), diag::expr_selector_swift3_objc_inference,
4971-
foundDecl->getDescriptiveKind(), foundDecl->getName(),
4972-
foundDecl->getDeclContext()
4973-
->getSelfNominalTypeDecl()
4974-
->getName())
4969+
foundDecl, foundDecl->getDeclContext()
4970+
->getSelfNominalTypeDecl()
4971+
->getName())
49754972
.highlight(subExpr->getSourceRange());
49764973
de.diagnose(foundDecl, diag::make_decl_objc,
49774974
foundDecl->getDescriptiveKind())

lib/Sema/CSDiagnostics.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ bool RequirementFailure::diagnoseAsError() {
455455
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
456456
auto *namingDecl = OTD->getNamingDecl();
457457
emitDiagnostic(diag::type_does_not_conform_in_opaque_return,
458-
namingDecl->getDescriptiveKind(), namingDecl->getName(),
459-
lhs, rhs, rhs->isAnyObject());
458+
namingDecl, lhs, rhs, rhs->isAnyObject());
460459

461460
if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
462461
emitDiagnosticAt(repr->getLoc(), diag::opaque_return_type_declared_here)
@@ -470,11 +469,10 @@ bool RequirementFailure::diagnoseAsError() {
470469
isStaticOrInstanceMember(AffectedDecl))) {
471470
auto *NTD = reqDC->getSelfNominalTypeDecl();
472471
emitDiagnostic(
473-
getDiagnosticInRereference(), AffectedDecl->getDescriptiveKind(),
474-
AffectedDecl->getName(), NTD->getDeclaredType(), lhs, rhs);
472+
getDiagnosticInRereference(), AffectedDecl, NTD->getDeclaredType(),
473+
lhs, rhs);
475474
} else {
476-
emitDiagnostic(getDiagnosticOnDecl(), AffectedDecl->getDescriptiveKind(),
477-
AffectedDecl->getName(), lhs, rhs);
475+
emitDiagnostic(getDiagnosticOnDecl(), AffectedDecl, lhs, rhs);
478476
}
479477

480478
maybeEmitRequirementNote(reqDC->getAsDecl(), lhs, rhs);
@@ -669,8 +667,7 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
669667
auto *namingDecl = OTD->getNamingDecl();
670668
if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
671669
emitDiagnosticAt(repr->getLoc(), diag::required_by_opaque_return,
672-
namingDecl->getDescriptiveKind(),
673-
namingDecl->getName())
670+
namingDecl)
674671
.highlight(repr->getSourceRange());
675672
}
676673
return true;
@@ -692,15 +689,12 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
692689
} else if (genericCtx != reqDC && (genericCtx->isChildContextOf(reqDC) ||
693690
isStaticOrInstanceMember(AffectedDecl))) {
694691
emitDiagnosticAt(noteLocation, diag::required_by_decl_ref,
695-
AffectedDecl->getDescriptiveKind(),
696-
AffectedDecl->getName(),
692+
AffectedDecl,
697693
reqDC->getSelfNominalTypeDecl()->getDeclaredType(),
698694
req.getFirstType(), nonConformingType);
699695
} else {
700696
emitDiagnosticAt(noteLocation, diag::required_by_decl,
701-
AffectedDecl->getDescriptiveKind(),
702-
AffectedDecl->getName(), req.getFirstType(),
703-
nonConformingType);
697+
AffectedDecl, req.getFirstType(), nonConformingType);
704698
}
705699

706700
return true;
@@ -1912,8 +1906,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsNote() {
19121906
return false;
19131907

19141908
auto *decl = overload->choice.getDecl();
1915-
emitDiagnosticAt(decl, diag::candidate_is_not_assignable,
1916-
decl->getDescriptiveKind(), decl->getName());
1909+
emitDiagnosticAt(decl, diag::candidate_is_not_assignable, decl);
19171910
return true;
19181911
}
19191912

@@ -3817,8 +3810,7 @@ bool ExtraneousPropertyWrapperUnwrapFailure::diagnoseAsError() {
38173810

38183811
if (auto *member = getReferencedMember()) {
38193812
emitDiagnostic(diag::incorrect_property_wrapper_reference_member,
3820-
member->getDescriptiveKind(), member->getName(), false,
3821-
getToType())
3813+
member, false, getToType())
38223814
.fixItInsert(getLoc(), newPrefix);
38233815
return true;
38243816
}
@@ -3834,8 +3826,7 @@ bool MissingPropertyWrapperUnwrapFailure::diagnoseAsError() {
38343826

38353827
if (auto *member = getReferencedMember()) {
38363828
emitDiagnostic(diag::incorrect_property_wrapper_reference_member,
3837-
member->getDescriptiveKind(), member->getName(), true,
3838-
getToType())
3829+
member, true, getToType())
38393830
.fixItRemoveChars(getLoc(), endLoc);
38403831
return true;
38413832
}
@@ -6088,7 +6079,7 @@ bool InvalidMemberWithMutatingGetterInKeyPath::diagnoseAsError() {
60886079
}
60896080

60906081
bool InvalidMethodRefInKeyPath::diagnoseAsError() {
6091-
emitDiagnostic(diag::expr_keypath_not_property, getKind(), getName(),
6082+
emitDiagnostic(diag::expr_keypath_not_property, getMember(),
60926083
isForKeyPathDynamicMemberLookup());
60936084
return true;
60946085
}
@@ -6931,7 +6922,7 @@ bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
69316922
choice->getDescriptiveKind(), paramTy, subsStr)
69326923
: emitDiagnosticAt(
69336924
args->getLoc(), diag::single_tuple_parameter_mismatch_normal,
6934-
choice->getDescriptiveKind(), name, paramTy, subsStr);
6925+
choice, paramTy, subsStr);
69356926

69366927
auto newLeftParenLoc = args->getStartLoc();
69376928
auto firstArgLabel = args->getLabel(0);
@@ -8040,15 +8031,14 @@ bool MissingQualifierInMemberRefFailure::diagnoseAsError() {
80408031
auto *DC = choice->getDeclContext();
80418032
if (!(DC->isModuleContext() || DC->isModuleScopeContext())) {
80428033
emitDiagnostic(diag::member_shadows_function, UDE->getName(), methodKind,
8043-
choice->getDescriptiveKind(), choice->getName());
8034+
choice);
80448035
return true;
80458036
}
80468037

80478038
auto qualifier = DC->getParentModule()->getName();
80488039

80498040
emitDiagnostic(diag::member_shadows_global_function, UDE->getName(),
8050-
methodKind, choice->getDescriptiveKind(),
8051-
choice->getName(), qualifier);
8041+
methodKind, choice, qualifier);
80528042

80538043
SmallString<32> namePlusDot = qualifier.str();
80548044
namePlusDot.push_back('.');
@@ -8570,7 +8560,7 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {
85708560

85718561
emitDiagnostic(
85728562
diag::contextual_member_ref_on_protocol_requires_self_requirement,
8573-
member->getDescriptiveKind(), member->getName());
8563+
member);
85748564

85758565
auto *extension = dyn_cast<ExtensionDecl>(member->getDeclContext());
85768566

@@ -8920,7 +8910,7 @@ bool SwiftToCPointerConversionInInvalidContext::diagnoseAsError() {
89208910
auto paramType = resolveType(argInfo->getParamType());
89218911

89228912
emitDiagnostic(diag::cannot_convert_argument_value_for_swift_func, argType,
8923-
paramType, callee->getDescriptiveKind(), callee->getName());
8913+
paramType, callee);
89248914
return true;
89258915
}
89268916

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ class FailureDiagnostic {
211211
class RequirementFailure : public FailureDiagnostic {
212212
protected:
213213
using PathEltKind = ConstraintLocator::PathElementKind;
214-
using DiagOnDecl = Diag<DescriptiveDeclKind, DeclName, Type, Type>;
215-
using DiagInReference = Diag<DescriptiveDeclKind, DeclName, Type, Type, Type>;
214+
using DiagOnDecl = Diag<const ValueDecl *, Type, Type>;
215+
using DiagInReference = Diag<const ValueDecl *, Type, Type, Type>;
216216
using DiagAsNote = Diag<Type, Type, Type, Type>;
217217

218218
/// If this failure associated with one of the conditional requirements,
@@ -1701,6 +1701,8 @@ class InvalidMemberRefInKeyPath : public FailureDiagnostic {
17011701
locator->isForKeyPathDynamicMemberLookup());
17021702
}
17031703

1704+
ValueDecl *getMember() const { return Member; }
1705+
17041706
DescriptiveDeclKind getKind() const { return Member->getDescriptiveKind(); }
17051707

17061708
DeclName getName() const { return Member->getName(); }

lib/Sema/DerivedConformances.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
581581
Nominal->getModuleScopeContext() !=
582582
getConformanceContext()->getModuleScopeContext()) {
583583
ConformanceDecl->diagnose(diag::cannot_synthesize_in_crossfile_extension,
584-
Nominal->getDescriptiveKind(), Nominal->getName(),
585-
synthesizing->getName(),
584+
Nominal, synthesizing->getName(),
586585
getProtocolType());
587586
Nominal->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
588587

lib/Sema/MiscDiagnostics.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
784784
Ctx.Diags.diagnose(DRE->getLoc(), diag::warn_unqualified_access,
785785
VD->getBaseIdentifier(),
786786
VD->getDescriptiveKind(),
787-
declParent->getDescriptiveKind(),
788-
declParent->getName());
787+
declParent);
789788
Ctx.Diags.diagnose(VD, diag::decl_declared_here, VD->getName());
790789

791790
if (VD->getDeclContext()->isTypeContext()) {
@@ -4830,7 +4829,7 @@ static bool diagnoseHasSymbolCondition(PoundHasSymbolInfo *info,
48304829
// and may indicate the developer has mis-identified the declaration
48314830
// they want to check (or forgot to import the module weakly).
48324831
ctx.Diags.diagnose(symbolExpr->getLoc(), diag::has_symbol_decl_must_be_weak,
4833-
decl->getDescriptiveKind(), decl->getName());
4832+
decl);
48344833
return true;
48354834
}
48364835

@@ -5039,8 +5038,7 @@ static void diagnoseUnintendedOptionalBehavior(const Expr *E,
50395038
? diag::iuo_to_any_coercion_note_func_result
50405039
: diag::iuo_to_any_coercion_note;
50415040

5042-
Ctx.Diags.diagnose(decl->getLoc(), noteDiag,
5043-
decl->getDescriptiveKind(), decl->getName());
5041+
Ctx.Diags.diagnose(decl->getLoc(), noteDiag, decl);
50445042
}
50455043
} else {
50465044
Ctx.Diags.diagnose(subExpr->getStartLoc(),
@@ -6236,8 +6234,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
62366234
DE.diagnoseWithNotes(
62376235
copyableNominalType->diagnose(
62386236
diag::noncopyable_within_copyable,
6239-
copyableNominalType->getDescriptiveKind(),
6240-
copyableNominalType->getBaseName()),
6237+
copyableNominalType),
62416238
[&]() {
62426239
eltDecl->diagnose(
62436240
diag::
@@ -6252,8 +6249,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
62526249
DE.diagnoseWithNotes(
62536250
copyableNominalType->diagnose(
62546251
diag::noncopyable_within_copyable,
6255-
copyableNominalType->getDescriptiveKind(),
6256-
copyableNominalType->getBaseName()),
6252+
copyableNominalType),
62576253
[&]() {
62586254
varDecl->diagnose(
62596255
diag::noncopyable_within_copyable_location,

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,14 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
224224
auto reason = where.getExportabilityReason();
225225

226226
if (fragileKind.kind == FragileFunctionKind::None) {
227-
auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
228-
diag::decl_from_hidden_module_warn:
229-
diag::decl_from_hidden_module;
230-
ctx.Diags.diagnose(loc, errorOrWarning,
231-
D->getDescriptiveKind(),
232-
diagName,
227+
DiagnosticBehavior limit = downgradeToWarning == DowngradeToWarning::Yes
228+
? DiagnosticBehavior::Warning
229+
: DiagnosticBehavior::Unspecified;
230+
ctx.Diags.diagnose(loc, diag::decl_from_hidden_module, D,
233231
static_cast<unsigned>(*reason),
234232
definingModule->getName(),
235-
static_cast<unsigned>(originKind));
233+
static_cast<unsigned>(originKind))
234+
.limitBehavior(limit);
236235

237236
D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
238237
} else {
@@ -241,14 +240,12 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
241240
assert(downgradeToWarning == DowngradeToWarning::No ||
242241
originKind == DisallowedOriginKind::MissingImport &&
243242
"Only implicitly imported decls should be reported as a warning.");
244-
auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
245-
diag::inlinable_decl_ref_from_hidden_module_warn:
246-
diag::inlinable_decl_ref_from_hidden_module;
247243

248-
ctx.Diags.diagnose(loc, errorOrWarning,
249-
D->getDescriptiveKind(), diagName,
244+
ctx.Diags.diagnose(loc, diag::inlinable_decl_ref_from_hidden_module, D,
250245
fragileKind.getSelector(), definingModule->getName(),
251-
static_cast<unsigned>(originKind));
246+
static_cast<unsigned>(originKind))
247+
.warnUntilSwiftVersionIf(downgradeToWarning == DowngradeToWarning::Yes,
248+
6);
252249

253250
if (originKind == DisallowedOriginKind::MissingImport &&
254251
downgradeToWarning == DowngradeToWarning::Yes)

lib/Sema/TypeCheckAccess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ void AccessControlCheckerBase::checkGlobalActorAccess(const Decl *D) {
494494
AccessLevel diagAccessLevel) {
495495
if (checkUsableFromInline) {
496496
auto diag = D->diagnose(diag::global_actor_not_usable_from_inline,
497-
D->getDescriptiveKind(), VD->getName());
497+
VD);
498498
highlightOffendingType(diag, complainRepr);
499499
noteLimitingImport(D->getASTContext(), importLimit, complainRepr);
500500
return;
@@ -2324,7 +2324,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
23242324

23252325
auto &DE = PGD->getASTContext().Diags;
23262326
auto diag =
2327-
DE.diagnose(diagLoc, diag::decl_from_hidden_module,
2327+
DE.diagnose(diagLoc, diag::decl_from_hidden_module_name,
23282328
PGD->getDescriptiveKind(), PGD->getName(),
23292329
static_cast<unsigned>(ExportabilityReason::General), M->getName(),
23302330
static_cast<unsigned>(DisallowedOriginKind::ImplementationOnly)

0 commit comments

Comments
 (0)