Skip to content

Commit

Permalink
[NFC] Adopt %kind for Sema ValueDecl diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
beccadax committed Jun 30, 2023
1 parent 7d2fbaf commit e7b753c
Show file tree
Hide file tree
Showing 21 changed files with 377 additions and 506 deletions.
486 changes: 238 additions & 248 deletions include/swift/AST/DiagnosticsSema.def

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,14 +812,12 @@ void GenericSignatureRequest::diagnoseCycle(DiagnosticEngine &diags) const {
auto *D = GC->getAsDecl();

if (auto *VD = dyn_cast<ValueDecl>(D)) {
VD->diagnose(diag::recursive_generic_signature,
VD->getDescriptiveKind(), VD->getBaseName());
VD->diagnose(diag::recursive_generic_signature, VD);
} else {
auto *ED = cast<ExtensionDecl>(D);
auto *NTD = ED->getExtendedNominal();

ED->diagnose(diag::recursive_generic_signature_extension,
NTD->getDescriptiveKind(), NTD->getName());
ED->diagnose(diag::recursive_generic_signature_extension, NTD);
}
}

Expand Down Expand Up @@ -853,9 +851,7 @@ void UnderlyingTypeRequest::cacheResult(Type value) const {

void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
auto aliasDecl = std::get<0>(getStorage());
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
aliasDecl->getDescriptiveKind(),
aliasDecl->getName());
diags.diagnose(aliasDecl, diag::recursive_decl_reference, aliasDecl);
}

//----------------------------------------------------------------------------//
Expand All @@ -864,9 +860,7 @@ void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {

void StructuralTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
auto aliasDecl = std::get<0>(getStorage());
diags.diagnose(aliasDecl, diag::recursive_decl_reference,
aliasDecl->getDescriptiveKind(),
aliasDecl->getName());
diags.diagnose(aliasDecl, diag::recursive_decl_reference, aliasDecl);
}

//----------------------------------------------------------------------------//
Expand Down
19 changes: 8 additions & 11 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ namespace {
Swift3ObjCInferenceWarnings::Minimal) {
context.Diags.diagnose(
memberLoc, diag::expr_dynamic_lookup_swift3_objc_inference,
member->getDescriptiveKind(), member->getName(),
member,
member->getDeclContext()->getSelfNominalTypeDecl()->getName());
context.Diags
.diagnose(member, diag::make_decl_objc,
Expand Down Expand Up @@ -4845,7 +4845,7 @@ namespace {
de.diagnose(E->getModifierLoc(),
diag::expr_selector_expected_property,
E->getSelectorKind() == ObjCSelectorExpr::Setter,
foundDecl->getDescriptiveKind(), foundDecl->getName())
foundDecl)
.fixItRemoveChars(E->getModifierLoc(),
E->getSubExpr()->getStartLoc());

Expand Down Expand Up @@ -4915,16 +4915,15 @@ namespace {
// Make sure we actually have a setter.
if (!var->isSettable(dc)) {
de.diagnose(E->getLoc(), diag::expr_selector_property_not_settable,
var->getDescriptiveKind(), var->getName());
var);
de.diagnose(var, diag::decl_declared_here, var->getName());
return E;
}

// Make sure the setter is accessible.
if (!var->isSetterAccessibleFrom(dc)) {
de.diagnose(E->getLoc(),
diag::expr_selector_property_setter_inaccessible,
var->getDescriptiveKind(), var->getName());
diag::expr_selector_property_setter_inaccessible, var);
de.diagnose(var, diag::decl_declared_here, var->getName());
return E;
}
Expand Down Expand Up @@ -4955,8 +4954,7 @@ namespace {
return E;
}

de.diagnose(E->getLoc(), diag::expr_selector_not_objc,
foundDecl->getDescriptiveKind(), foundDecl->getName())
de.diagnose(E->getLoc(), diag::expr_selector_not_objc, foundDecl)
.highlight(subExpr->getSourceRange());
de.diagnose(foundDecl, diag::make_decl_objc,
foundDecl->getDescriptiveKind())
Expand All @@ -4969,10 +4967,9 @@ namespace {
cs.getASTContext().LangOpts.WarnSwift3ObjCInference ==
Swift3ObjCInferenceWarnings::Minimal) {
de.diagnose(E->getLoc(), diag::expr_selector_swift3_objc_inference,
foundDecl->getDescriptiveKind(), foundDecl->getName(),
foundDecl->getDeclContext()
->getSelfNominalTypeDecl()
->getName())
foundDecl, foundDecl->getDeclContext()
->getSelfNominalTypeDecl()
->getName())
.highlight(subExpr->getSourceRange());
de.diagnose(foundDecl, diag::make_decl_objc,
foundDecl->getDescriptiveKind())
Expand Down
42 changes: 16 additions & 26 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ bool RequirementFailure::diagnoseAsError() {
if (auto *OTD = dyn_cast<OpaqueTypeDecl>(AffectedDecl)) {
auto *namingDecl = OTD->getNamingDecl();
emitDiagnostic(diag::type_does_not_conform_in_opaque_return,
namingDecl->getDescriptiveKind(), namingDecl->getName(),
lhs, rhs, rhs->isAnyObject());
namingDecl, lhs, rhs, rhs->isAnyObject());

if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
emitDiagnosticAt(repr->getLoc(), diag::opaque_return_type_declared_here)
Expand All @@ -470,11 +469,10 @@ bool RequirementFailure::diagnoseAsError() {
isStaticOrInstanceMember(AffectedDecl))) {
auto *NTD = reqDC->getSelfNominalTypeDecl();
emitDiagnostic(
getDiagnosticInRereference(), AffectedDecl->getDescriptiveKind(),
AffectedDecl->getName(), NTD->getDeclaredType(), lhs, rhs);
getDiagnosticInRereference(), AffectedDecl, NTD->getDeclaredType(),
lhs, rhs);
} else {
emitDiagnostic(getDiagnosticOnDecl(), AffectedDecl->getDescriptiveKind(),
AffectedDecl->getName(), lhs, rhs);
emitDiagnostic(getDiagnosticOnDecl(), AffectedDecl, lhs, rhs);
}

maybeEmitRequirementNote(reqDC->getAsDecl(), lhs, rhs);
Expand Down Expand Up @@ -669,8 +667,7 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
auto *namingDecl = OTD->getNamingDecl();
if (auto *repr = namingDecl->getOpaqueResultTypeRepr()) {
emitDiagnosticAt(repr->getLoc(), diag::required_by_opaque_return,
namingDecl->getDescriptiveKind(),
namingDecl->getName())
namingDecl)
.highlight(repr->getSourceRange());
}
return true;
Expand All @@ -692,15 +689,12 @@ bool MissingConformanceFailure::diagnoseTypeCannotConform(
} else if (genericCtx != reqDC && (genericCtx->isChildContextOf(reqDC) ||
isStaticOrInstanceMember(AffectedDecl))) {
emitDiagnosticAt(noteLocation, diag::required_by_decl_ref,
AffectedDecl->getDescriptiveKind(),
AffectedDecl->getName(),
AffectedDecl,
reqDC->getSelfNominalTypeDecl()->getDeclaredType(),
req.getFirstType(), nonConformingType);
} else {
emitDiagnosticAt(noteLocation, diag::required_by_decl,
AffectedDecl->getDescriptiveKind(),
AffectedDecl->getName(), req.getFirstType(),
nonConformingType);
AffectedDecl, req.getFirstType(), nonConformingType);
}

return true;
Expand Down Expand Up @@ -1912,8 +1906,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsNote() {
return false;

auto *decl = overload->choice.getDecl();
emitDiagnosticAt(decl, diag::candidate_is_not_assignable,
decl->getDescriptiveKind(), decl->getName());
emitDiagnosticAt(decl, diag::candidate_is_not_assignable, decl);
return true;
}

Expand Down Expand Up @@ -3817,8 +3810,7 @@ bool ExtraneousPropertyWrapperUnwrapFailure::diagnoseAsError() {

if (auto *member = getReferencedMember()) {
emitDiagnostic(diag::incorrect_property_wrapper_reference_member,
member->getDescriptiveKind(), member->getName(), false,
getToType())
member, false, getToType())
.fixItInsert(getLoc(), newPrefix);
return true;
}
Expand All @@ -3834,8 +3826,7 @@ bool MissingPropertyWrapperUnwrapFailure::diagnoseAsError() {

if (auto *member = getReferencedMember()) {
emitDiagnostic(diag::incorrect_property_wrapper_reference_member,
member->getDescriptiveKind(), member->getName(), true,
getToType())
member, true, getToType())
.fixItRemoveChars(getLoc(), endLoc);
return true;
}
Expand Down Expand Up @@ -6091,7 +6082,7 @@ bool InvalidMemberWithMutatingGetterInKeyPath::diagnoseAsError() {
}

bool InvalidMethodRefInKeyPath::diagnoseAsError() {
emitDiagnostic(diag::expr_keypath_not_property, getKind(), getName(),
emitDiagnostic(diag::expr_keypath_not_property, getMember(),
isForKeyPathDynamicMemberLookup());
return true;
}
Expand Down Expand Up @@ -6932,7 +6923,7 @@ bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
choice->getDescriptiveKind(), paramTy, subsStr)
: emitDiagnosticAt(
args->getLoc(), diag::single_tuple_parameter_mismatch_normal,
choice->getDescriptiveKind(), name, paramTy, subsStr);
choice, paramTy, subsStr);

auto newLeftParenLoc = args->getStartLoc();
auto firstArgLabel = args->getLabel(0);
Expand Down Expand Up @@ -8041,15 +8032,14 @@ bool MissingQualifierInMemberRefFailure::diagnoseAsError() {
auto *DC = choice->getDeclContext();
if (!(DC->isModuleContext() || DC->isModuleScopeContext())) {
emitDiagnostic(diag::member_shadows_function, UDE->getName(), methodKind,
choice->getDescriptiveKind(), choice->getName());
choice);
return true;
}

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

emitDiagnostic(diag::member_shadows_global_function, UDE->getName(),
methodKind, choice->getDescriptiveKind(),
choice->getName(), qualifier);
methodKind, choice, qualifier);

SmallString<32> namePlusDot = qualifier.str();
namePlusDot.push_back('.');
Expand Down Expand Up @@ -8571,7 +8561,7 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {

emitDiagnostic(
diag::contextual_member_ref_on_protocol_requires_self_requirement,
member->getDescriptiveKind(), member->getName());
member);

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

Expand Down Expand Up @@ -8921,7 +8911,7 @@ bool SwiftToCPointerConversionInInvalidContext::diagnoseAsError() {
auto paramType = resolveType(argInfo->getParamType());

emitDiagnostic(diag::cannot_convert_argument_value_for_swift_func, argType,
paramType, callee->getDescriptiveKind(), callee->getName());
paramType, callee);
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/CSDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ class FailureDiagnostic {
class RequirementFailure : public FailureDiagnostic {
protected:
using PathEltKind = ConstraintLocator::PathElementKind;
using DiagOnDecl = Diag<DescriptiveDeclKind, DeclName, Type, Type>;
using DiagInReference = Diag<DescriptiveDeclKind, DeclName, Type, Type, Type>;
using DiagOnDecl = Diag<const ValueDecl *, Type, Type>;
using DiagInReference = Diag<const ValueDecl *, Type, Type, Type>;
using DiagAsNote = Diag<Type, Type, Type, Type>;

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

ValueDecl *getMember() const { return Member; }

DescriptiveDeclKind getKind() const { return Member->getDescriptiveKind(); }

DeclName getName() const { return Member->getName(); }
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
Nominal->getModuleScopeContext() !=
getConformanceContext()->getModuleScopeContext()) {
ConformanceDecl->diagnose(diag::cannot_synthesize_in_crossfile_extension,
Nominal->getDescriptiveKind(), Nominal->getName(),
synthesizing->getName(),
Nominal, synthesizing->getName(),
getProtocolType());
Nominal->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);

Expand Down
14 changes: 5 additions & 9 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
Ctx.Diags.diagnose(DRE->getLoc(), diag::warn_unqualified_access,
VD->getBaseIdentifier(),
VD->getDescriptiveKind(),
declParent->getDescriptiveKind(),
declParent->getName());
declParent);
Ctx.Diags.diagnose(VD, diag::decl_declared_here, VD->getName());

if (VD->getDeclContext()->isTypeContext()) {
Expand Down Expand Up @@ -4835,7 +4834,7 @@ static bool diagnoseHasSymbolCondition(PoundHasSymbolInfo *info,
// and may indicate the developer has mis-identified the declaration
// they want to check (or forgot to import the module weakly).
ctx.Diags.diagnose(symbolExpr->getLoc(), diag::has_symbol_decl_must_be_weak,
decl->getDescriptiveKind(), decl->getName());
decl);
return true;
}

Expand Down Expand Up @@ -5044,8 +5043,7 @@ static void diagnoseUnintendedOptionalBehavior(const Expr *E,
? diag::iuo_to_any_coercion_note_func_result
: diag::iuo_to_any_coercion_note;

Ctx.Diags.diagnose(decl->getLoc(), noteDiag,
decl->getDescriptiveKind(), decl->getName());
Ctx.Diags.diagnose(decl->getLoc(), noteDiag, decl);
}
} else {
Ctx.Diags.diagnose(subExpr->getStartLoc(),
Expand Down Expand Up @@ -6249,8 +6247,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
DE.diagnoseWithNotes(
copyableNominalType->diagnose(
diag::noncopyable_within_copyable,
copyableNominalType->getDescriptiveKind(),
copyableNominalType->getBaseName()),
copyableNominalType),
[&]() {
eltDecl->diagnose(
diag::
Expand All @@ -6265,8 +6262,7 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
DE.diagnoseWithNotes(
copyableNominalType->diagnose(
diag::noncopyable_within_copyable,
copyableNominalType->getDescriptiveKind(),
copyableNominalType->getBaseName()),
copyableNominalType),
[&]() {
varDecl->diagnose(
diag::noncopyable_within_copyable_location,
Expand Down
23 changes: 10 additions & 13 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,14 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
auto reason = where.getExportabilityReason();

if (fragileKind.kind == FragileFunctionKind::None) {
auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
diag::decl_from_hidden_module_warn:
diag::decl_from_hidden_module;
ctx.Diags.diagnose(loc, errorOrWarning,
D->getDescriptiveKind(),
diagName,
DiagnosticBehavior limit = downgradeToWarning == DowngradeToWarning::Yes
? DiagnosticBehavior::Warning
: DiagnosticBehavior::Unspecified;
ctx.Diags.diagnose(loc, diag::decl_from_hidden_module, D,
static_cast<unsigned>(*reason),
definingModule->getName(),
static_cast<unsigned>(originKind));
static_cast<unsigned>(originKind))
.limitBehavior(limit);

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

ctx.Diags.diagnose(loc, errorOrWarning,
D->getDescriptiveKind(), diagName,
ctx.Diags.diagnose(loc, diag::inlinable_decl_ref_from_hidden_module, D,
fragileKind.getSelector(), definingModule->getName(),
static_cast<unsigned>(originKind));
static_cast<unsigned>(originKind))
.warnUntilSwiftVersionIf(downgradeToWarning == DowngradeToWarning::Yes,
6);

if (originKind == DisallowedOriginKind::MissingImport &&
downgradeToWarning == DowngradeToWarning::Yes)
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void AccessControlCheckerBase::checkGlobalActorAccess(const Decl *D) {
AccessLevel diagAccessLevel) {
if (checkUsableFromInline) {
auto diag = D->diagnose(diag::global_actor_not_usable_from_inline,
D->getDescriptiveKind(), VD->getName());
VD);
highlightOffendingType(diag, complainRepr);
noteLimitingImport(D->getASTContext(), importLimit, complainRepr);
return;
Expand Down Expand Up @@ -2255,7 +2255,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {

auto &DE = PGD->getASTContext().Diags;
auto diag =
DE.diagnose(diagLoc, diag::decl_from_hidden_module,
DE.diagnose(diagLoc, diag::decl_from_hidden_module_name,
PGD->getDescriptiveKind(), PGD->getName(),
static_cast<unsigned>(ExportabilityReason::General), M->getName(),
static_cast<unsigned>(DisallowedOriginKind::ImplementationOnly)
Expand Down
Loading

0 comments on commit e7b753c

Please sign in to comment.