Skip to content

Commit

Permalink
[NFC] Adopt ValueDecl * for decl_declared_here
Browse files Browse the repository at this point in the history
  • Loading branch information
beccadax committed Jul 1, 2023
1 parent e7b753c commit f3dcacc
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 73 deletions.
8 changes: 6 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ DIAG(REMARK,ID,Options,Text,Signature)
#endif

NOTE(decl_declared_here,none,
"%0 declared here", (const ValueDecl *))
NOTE(decl_declared_here_base,none,
"%base0 declared here", (const ValueDecl *))
NOTE(name_declared_here,none,
"%0 declared here", (DeclName))
NOTE(kind_declared_here,none,
"%0 declared here", (DescriptiveDeclKind))
NOTE(descriptive_decl_declared_here,none,
"'%0' declared here", (StringRef))
NOTE(implicit_member_declared_here,none,
"%1 '%0' is implicitly declared", (StringRef, StringRef))
"%kindbase0 is implicitly declared", (const ValueDecl *))
NOTE(extended_type_declared_here,none,
"extended type declared here", ())
NOTE(opaque_return_type_declared_here,none,
Expand Down Expand Up @@ -1040,7 +1044,7 @@ ERROR(cannot_find_type_in_scope,none,
ERROR(cannot_find_type_in_scope_did_you_mean,none,
"cannot find type %0 in scope; did you mean to use '%1'?", (DeclNameRef, StringRef))
NOTE(note_typo_candidate_implicit_member,none,
"did you mean the implicitly-synthesized %1 '%0'?", (StringRef, StringRef))
"did you mean the implicitly-synthesized %kindbase0?", (const ValueDecl *))
NOTE(note_remapped_type,none,
"did you mean to use '%0'?", (StringRef))
NOTE(note_module_as_type,none,
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/RequirementMachine/RequirementLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
.fixItRemove(assocTypeDecl->getSourceRange());

ctx.Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
inheritedAssocTypeDecl->getName());
inheritedAssocTypeDecl);

shouldWarnAboutRedeclaration = false;
}
Expand Down Expand Up @@ -1099,7 +1099,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
getConcreteTypeReq(type, fixItWhere.Item))
.fixItRemove(type->getSourceRange());
ctx.Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
inheritedAssocTypeDecl->getName());
inheritedAssocTypeDecl);

shouldWarnAboutRedeclaration = false;
}
Expand Down
11 changes: 5 additions & 6 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4829,7 +4829,7 @@ namespace {
func->getDeclContext()->isModuleScopeContext(),
func->getName())
.highlight(subExpr->getSourceRange());
de.diagnose(func, diag::decl_declared_here, func->getName());
de.diagnose(func, diag::decl_declared_here, func);
return E;
}

Expand Down Expand Up @@ -4864,7 +4864,7 @@ namespace {
de.diagnose(E->getLoc(), diag::expr_selector_not_property,
isa<ParamDecl>(var), var->getName())
.highlight(subExpr->getSourceRange());
de.diagnose(var, diag::decl_declared_here, var->getName());
de.diagnose(var, diag::decl_declared_here, var);
return E;
}

Expand Down Expand Up @@ -4916,15 +4916,15 @@ namespace {
if (!var->isSettable(dc)) {
de.diagnose(E->getLoc(), diag::expr_selector_property_not_settable,
var);
de.diagnose(var, diag::decl_declared_here, var->getName());
de.diagnose(var, diag::decl_declared_here, var);
return E;
}

// Make sure the setter is accessible.
if (!var->isSetterAccessibleFrom(dc)) {
de.diagnose(E->getLoc(),
diag::expr_selector_property_setter_inaccessible, var);
de.diagnose(var, diag::decl_declared_here, var->getName());
de.diagnose(var, diag::decl_declared_here, var);
return E;
}

Expand All @@ -4935,8 +4935,7 @@ namespace {
// Cannot reference with #selector.
de.diagnose(E->getLoc(), diag::expr_selector_no_declaration)
.highlight(subExpr->getSourceRange());
de.diagnose(foundDecl, diag::decl_declared_here,
foundDecl->getName());
de.diagnose(foundDecl, diag::decl_declared_here, foundDecl);
return E;
}
assert(method && "Didn't find a method?");
Expand Down
23 changes: 11 additions & 12 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,8 +1867,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
if (auto overload = getOverloadChoiceIfAvailable(
getConstraintLocator(member, ConstraintLocator::Member))) {
if (auto *ref = overload->choice.getDeclOrNull())
emitDiagnosticAt(ref, diag::decl_declared_here,
ref->getName());
emitDiagnosticAt(ref, diag::decl_declared_here, ref);
}
return true;
}
Expand Down Expand Up @@ -5066,7 +5065,7 @@ bool MissingArgumentsFailure::diagnoseAsError() {

if (auto selectedOverload = getCalleeOverloadChoiceIfAvailable(locator)) {
if (auto *decl = selectedOverload->choice.getDeclOrNull()) {
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
}
}

Expand Down Expand Up @@ -5234,7 +5233,7 @@ bool MissingArgumentsFailure::diagnoseSingleMissingArgument() const {
if (auto selectedOverload =
getCalleeOverloadChoiceIfAvailable(getLocator())) {
if (auto *decl = selectedOverload->choice.getDeclOrNull()) {
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
}
}

Expand Down Expand Up @@ -5380,7 +5379,7 @@ bool MissingArgumentsFailure::diagnoseInvalidTupleDestructuring() const {
diagnostic.flush();

// Add a note which points to the overload choice location.
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
return true;
}

Expand Down Expand Up @@ -5870,7 +5869,7 @@ bool ExtraneousArgumentsFailure::diagnoseAsError() {

if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
if (auto *decl = overload->choice.getDeclOrNull()) {
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
}
}

Expand Down Expand Up @@ -5999,7 +5998,7 @@ bool InaccessibleMemberFailure::diagnoseAsError() {
.highlight(nameLoc.getSourceRange());
}

emitDiagnosticAt(Member, diag::decl_declared_here, Member->getName());
emitDiagnosticAt(Member, diag::decl_declared_here, Member);
return true;
}

Expand Down Expand Up @@ -7457,7 +7456,7 @@ bool ArgumentMismatchFailure::diagnoseTrailingClosureMismatch() const {

if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
if (auto *decl = overload->choice.getDeclOrNull()) {
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
}
}

Expand Down Expand Up @@ -8048,7 +8047,7 @@ bool MissingQualifierInMemberRefFailure::diagnoseAsError() {
choice->getDescriptiveKind(), qualifier)
.fixItInsert(UDE->getStartLoc(), namePlusDot);

emitDiagnosticAt(choice, diag::decl_declared_here, choice->getName());
emitDiagnosticAt(choice, diag::decl_declared_here, choice);
return true;
}

Expand Down Expand Up @@ -8276,7 +8275,7 @@ bool TrailingClosureRequiresExplicitLabel::diagnoseAsError() {
}

if (auto *callee = argInfo.getCallee()) {
emitDiagnosticAt(callee, diag::decl_declared_here, callee->getName());
emitDiagnosticAt(callee, diag::decl_declared_here, callee);
}

return true;
Expand Down Expand Up @@ -8474,7 +8473,7 @@ bool ReferenceToInvalidDeclaration::diagnoseAsError() {
// about reference to an invalid declaration.

emitDiagnostic(diag::reference_to_invalid_decl, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
return true;
}

Expand Down Expand Up @@ -9102,7 +9101,7 @@ bool DestructureTupleToUseWithPackExpansionParameter::diagnoseAsError() {
return true;

if (auto *decl = selectedOverload->choice.getDeclOrNull()) {
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
emitDiagnosticAt(decl, diag::decl_declared_here, decl);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/ImportResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ ScopedImportLookupRequest::evaluate(Evaluator &evaluator,

if (decls.size() == 1)
ctx.Diags.diagnose(decls.front(), diag::decl_declared_here,
decls.front()->getName());
decls.front());
}
return ctx.AllocateCopy(decls);
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
.fixItInsertAfter(arg->getEndLoc(), ")");

// Point to callee parameter
Ctx.Diags.diagnose(calleeParam, diag::decl_declared_here,
calleeParam->getName());
Ctx.Diags.diagnose(calleeParam, diag::decl_declared_here, calleeParam);
}

llvm::Optional<MagicIdentifierLiteralExpr::Kind>
Expand Down Expand Up @@ -787,7 +786,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
VD->getBaseIdentifier(),
VD->getDescriptiveKind(),
declParent);
Ctx.Diags.diagnose(VD, diag::decl_declared_here, VD->getName());
Ctx.Diags.diagnose(VD, diag::decl_declared_here, VD);

if (VD->getDeclContext()->isTypeContext()) {
Ctx.Diags.diagnose(DRE->getLoc(), diag::fix_unqualified_access_member)
Expand Down Expand Up @@ -2378,7 +2377,7 @@ static void diagnoseUnownedImmediateDeallocationImpl(ASTContext &ctx,
ctx.Diags.diagnose(diagLoc, diag::unowned_assignment_requires_strong)
.highlight(diagRange);

ctx.Diags.diagnose(varDecl, diag::decl_declared_here, varDecl->getName());
ctx.Diags.diagnose(varDecl, diag::decl_declared_here, varDecl);
}

void swift::diagnoseUnownedImmediateDeallocation(ASTContext &ctx,
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/PreCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
if (Lookup.outerResults().empty()) {
Context.Diags.diagnose(Loc, diag::use_local_before_declaration, Name);
Context.Diags.diagnose(innerDecl, diag::decl_declared_here,
localDeclAfterUse->getName());
localDeclAfterUse);
Expr *error = new (Context) ErrorExpr(UDRE->getSourceRange());
return error;
}
Expand Down Expand Up @@ -528,7 +528,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
// module we could offer a fix-it.
for (auto lookupResult : inaccessibleResults) {
auto *VD = lookupResult.getValueDecl();
VD->diagnose(diag::decl_declared_here, VD->getName());
VD->diagnose(diag::decl_declared_here, VD);
}

// Don't try to recover here; we'll get more access-related diagnostics
Expand Down Expand Up @@ -796,7 +796,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
Context.Diags.diagnose(Loc, diag::ambiguous_decl_ref, Name);
for (auto Result : Lookup) {
auto *Decl = Result.getValueDecl();
Context.Diags.diagnose(Decl, diag::decl_declared_here, Decl->getName());
Context.Diags.diagnose(Decl, diag::decl_declared_here, Decl);
}
return new (Context) ErrorExpr(UDRE->getSourceRange());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
if (refRange.isValid())
diag.highlight(refRange);
diag.flush();
PGD->diagnose(diag::decl_declared_here, PGD->getName());
PGD->diagnose(diag::name_declared_here, PGD->getName());
}

void visitInfixOperatorDecl(InfixOperatorDecl *IOD) {
Expand Down
17 changes: 7 additions & 10 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,14 @@ visitObjCImplementationAttr(ObjCImplementationAttr *attr) {
diag::attr_objc_implementation_must_extend_class,
ED->getExtendedNominal());
ED->getExtendedNominal()->diagnose(diag::decl_declared_here,
ED->getExtendedNominal()->getName());
ED->getExtendedNominal());
return;
}

if (!CD->hasClangNode()) {
diagnoseAndRemoveAttr(attr, diag::attr_objc_implementation_must_be_imported,
CD);
CD->diagnose(diag::decl_declared_here, CD->getName());
CD->diagnose(diag::decl_declared_here, CD);
return;
}

Expand Down Expand Up @@ -3946,7 +3946,7 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
}

diagnose(attr->getLocation(), diag::nominal_type_not_attribute, nominal);
nominal->diagnose(diag::decl_declared_here, nominal->getName());
nominal->diagnose(diag::decl_declared_here, nominal);
attr->setInvalid();
}

Expand Down Expand Up @@ -5952,8 +5952,7 @@ static bool typeCheckDerivativeAttr(DerivativeAttr *attr) {
diags.diagnose(originalName.Loc,
diag::derivative_attr_original_stored_property_unsupported,
originalName.Name);
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here,
asd->getName());
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here, asd);
return true;
}
// Diagnose original class property and subscript setters.
Expand All @@ -5962,8 +5961,7 @@ static bool typeCheckDerivativeAttr(DerivativeAttr *attr) {
accessorDecl->getAccessorKind() == AccessorKind::Set) {
diags.diagnose(originalName.Loc,
diag::derivative_attr_class_setter_unsupported);
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here,
asd->getName());
diags.diagnose(originalAFD->getLoc(), diag::decl_declared_here, asd);
return true;
}
}
Expand Down Expand Up @@ -6844,8 +6842,7 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
proto->diagnose(
diag::marker_protocol_inherit_nonmarker,
proto->getName(), inheritedProto->getName());
inheritedProto->diagnose(
diag::decl_declared_here, inheritedProto->getName());
inheritedProto->diagnose( diag::decl_declared_here, inheritedProto);
}
}

Expand Down Expand Up @@ -7611,7 +7608,7 @@ ArrayRef<VarDecl *> InitAccessorReferencedVariablesRequest::evaluate(
DeclNameRef(name));

for (auto *choice : propertyResults) {
ctx.Diags.diagnose(choice, diag::decl_declared_here, choice->getName());
ctx.Diags.diagnose(choice, diag::decl_declared_here, choice);
}

failed = true;
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3573,16 +3573,14 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
if (const AbstractFunctionDecl *asyncAlt = afd->getAsyncAlternative()) {
SourceLoc diagLoc = call ? call->getLoc() : R.Start;
ctx.Diags.diagnose(diagLoc, diag::warn_use_async_alternative);

if (auto *accessor = dyn_cast<AccessorDecl>(asyncAlt)) {
SmallString<32> name;
llvm::raw_svector_ostream os(name);
accessor->printUserFacingName(os);
ctx.Diags.diagnose(asyncAlt->getLoc(),
diag::descriptive_decl_declared_here, name);
} else {
ctx.Diags.diagnose(asyncAlt->getLoc(), diag::decl_declared_here,
asyncAlt->getName());
asyncAlt->diagnose(diag::decl_declared_here, asyncAlt);
}
}
}
Expand Down Expand Up @@ -3612,7 +3610,7 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
ctx.Diags
.diagnose(diagLoc, diag::async_unavailable_decl, D, attr->Message)
.warnUntilSwiftVersion(6);
D->diagnose(diag::decl_declared_here, D->getName());
D->diagnose(diag::decl_declared_here, D);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckCaptures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class FindCapturedVars : public ASTWalker {
NTD->diagnose(diag::kind_declared_here,
DescriptiveDeclKind::Type);

D->diagnose(diag::decl_declared_here, D->getName());
D->diagnose(diag::decl_declared_here, D);
return Action::SkipChildren(DRE);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ llvm::Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,

for (auto result : lookup) {
diags.diagnose(result.getValueDecl(), diag::decl_declared_here,
result.getValueDecl()->getName());
result.getValueDecl());
}
isInvalid = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion,
ctx.Diags.diagnose(loc, diag::external_macro_not_found,
external.moduleName.str(),
external.macroTypeName.str(), macro->getName());
macro->diagnose(diag::decl_declared_here, macro->getName());
macro->diagnose(diag::decl_declared_here, macro);
return nullptr;
}

Expand Down Expand Up @@ -1166,7 +1166,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
external.macroTypeName.str(),
macro->getName()
);
macro->diagnose(diag::decl_declared_here, macro->getName());
macro->diagnose(diag::decl_declared_here, macro);
return nullptr;
}

Expand Down
Loading

0 comments on commit f3dcacc

Please sign in to comment.