Skip to content

Commit 5c190b9

Browse files
committed
AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSIL.def
1 parent 3c3dd54 commit 5c190b9

File tree

4 files changed

+55
-66
lines changed

4 files changed

+55
-66
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ ERROR(missing_never_call_closure,none,
315315
(Type))
316316

317317
ERROR(missing_return_decl,none,
318-
"missing return in %1 expected to return %0",
319-
(Type, DescriptiveDeclKind))
318+
"missing return in %kindonly1 expected to return %0",
319+
(Type, const AbstractFunctionDecl *))
320320
ERROR(missing_never_call_decl,none,
321-
"%1 with uninhabited return type %0 is missing "
321+
"%kindonly1 with uninhabited return type %0 is missing "
322322
"call to another never-returning function on all paths",
323-
(Type, DescriptiveDeclKind))
323+
(Type, const AbstractFunctionDecl *))
324324

325325
NOTE(missing_return_last_expr_note,none,
326326
"did you mean to return the last expression?", ())
@@ -701,8 +701,9 @@ WARNING(warning_int_to_fp_inexact, none,
701701

702702
// Flow-isolation diagnostics
703703
ERROR(isolated_after_nonisolated, none,
704-
"cannot access %1 %2 here in %select{nonisolated initializer|deinitializer}0",
705-
(bool, DescriptiveDeclKind, DeclName))
704+
"cannot access %kind1 here in "
705+
"%select{nonisolated initializer|deinitializer}0",
706+
(bool, const ValueDecl *))
706707
NOTE(nonisolated_blame, none, "after %1%2 %3, "
707708
"only nonisolated properties of 'self' can be accessed from "
708709
"%select{this init|a deinit}0", (bool, StringRef, StringRef, DeclName))
@@ -981,16 +982,16 @@ NOTE(regionbasedisolation_type_use_after_send, none,
981982
"sending value of non-Sendable type %0 to %1 callee risks causing data races between %1 and local %2 uses",
982983
(Type, ActorIsolation, ActorIsolation))
983984
NOTE(regionbasedisolation_type_use_after_send_callee, none,
984-
"sending value of non-Sendable type %0 to %1 %2 %3 risks causing data "
985-
"races between %1 and local %4 uses",
986-
(Type, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
985+
"sending value of non-Sendable type %0 to %1 %kind2 risks causing data "
986+
"races between %1 and local %3 uses",
987+
(Type, ActorIsolation, const ValueDecl *, ActorIsolation))
987988

988989
NOTE(regionbasedisolation_named_info_send_yields_race, none,
989990
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
990991
(Identifier, StringRef, ActorIsolation, ActorIsolation))
991992
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
992-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and local %5 uses",
993-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
993+
"sending %1%0 to %2 %kind3 risks causing data races between %2 and local %4 uses",
994+
(Identifier, StringRef, ActorIsolation, const ValueDecl *, ActorIsolation))
994995

995996
// Use after send closure.
996997
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
@@ -1013,8 +1014,8 @@ NOTE(regionbasedisolation_typed_use_after_sending, none,
10131014
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
10141015
(Type))
10151016
NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
1016-
"Passing value of non-Sendable type %0 as a 'sending' argument to %1 %2 risks causing races in between local and caller code",
1017-
(Type, DescriptiveDeclKind, DeclName))
1017+
"Passing value of non-Sendable type %0 as a 'sending' argument to %kind1 risks causing races in between local and caller code",
1018+
(Type, const ValueDecl *))
10181019

10191020
//===
10201021
// Sending Never Sendable Emitter
@@ -1023,8 +1024,8 @@ NOTE(regionbasedisolation_named_send_never_sendable, none,
10231024
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
10241025
(Identifier, StringRef, ActorIsolation, StringRef))
10251026
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
1026-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
1027-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
1027+
"sending %1%0 to %2 %kind3 risks causing data races between %2 and %4 uses",
1028+
(Identifier, StringRef, ActorIsolation, const ValueDecl *, StringRef))
10281029

10291030
NOTE(regionbasedisolation_named_send_into_sending_param, none,
10301031
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
@@ -1048,8 +1049,8 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_
10481049
"closure captures %0 which is accessible to code in the current task",
10491050
(DeclName))
10501051
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_boxed_value_task_isolated, none,
1051-
"closure captures reference to mutable %1 %0 which is accessible to code in the current task",
1052-
(DeclName, DescriptiveDeclKind))
1052+
"closure captures reference to mutable %kind0 which is accessible to code in the current task",
1053+
(const ValueDecl *))
10531054
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_region, none,
10541055
"closure captures %1 which is accessible to %0 code",
10551056
(StringRef, DeclName))
@@ -1065,8 +1066,8 @@ NOTE(regionbasedisolation_closure_captures_actor, none,
10651066
(DeclName, StringRef))
10661067

10671068
NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
1068-
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %2 %3 risks causing races inbetween %0 uses and uses reachable from %3",
1069-
(StringRef, Type, DescriptiveDeclKind, DeclName))
1069+
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter to %kind2 risks causing races inbetween %0 uses and uses reachable from %2",
1070+
(StringRef, Type, const ValueDecl *))
10701071

10711072
NOTE(regionbasedisolation_named_send_nt_asynclet_capture, none,
10721073
"sending %1 %0 into async let risks causing data races between nonisolated and %1 uses",
@@ -1075,8 +1076,8 @@ NOTE(regionbasedisolation_typed_sendneversendable_via_arg, none,
10751076
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
10761077
(StringRef, Type, ActorIsolation))
10771078
NOTE(regionbasedisolation_typed_sendneversendable_via_arg_callee, none,
1078-
"sending %0 value of non-Sendable type %1 to %2 %3 %4 risks causing races in between %0 and %2 uses",
1079-
(StringRef, Type, ActorIsolation, DescriptiveDeclKind, DeclName))
1079+
"sending %0 value of non-Sendable type %1 to %2 %kind3 risks causing races in between %0 and %2 uses",
1080+
(StringRef, Type, ActorIsolation, const ValueDecl *))
10801081

10811082
// Error that is only used when the send non sendable emitter cannot discover any
10821083
// information to give a better diagnostic.

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ static void diagnoseMissingReturn(const UnreachableInst *UI,
6969
Context.Diags.diagnose(expr->getStartLoc(),
7070
diag::missing_return_closure, ResTy);
7171
} else {
72-
auto *DC = FLoc.getAsDeclContext();
73-
assert(DC && DC->getAsDecl() && "not a declaration?");
72+
auto *FD = FLoc.castToASTNode<AbstractFunctionDecl>();
7473
Context.Diags.diagnose(expr->getStartLoc(), diag::missing_return_decl,
75-
ResTy, DC->getAsDecl()->getDescriptiveKind());
74+
ResTy, FD);
7675
}
7776
Context.Diags
7877
.diagnose(expr->getStartLoc(), diag::missing_return_last_expr_note)
@@ -89,12 +88,10 @@ static void diagnoseMissingReturn(const UnreachableInst *UI,
8988
: diag::missing_return_closure;
9089
diagnose(Context, L.getEndSourceLoc(), diagID, ResTy);
9190
} else {
92-
auto *DC = FLoc.getAsDeclContext();
93-
assert(DC && DC->getAsDecl() && "not a declaration?");
91+
auto *FD = FLoc.castToASTNode<AbstractFunctionDecl>();
9492
auto diagID = isNoReturnFn ? diag::missing_never_call_decl
9593
: diag::missing_return_decl;
96-
diagnose(Context, L.getEndSourceLoc(), diagID, ResTy,
97-
DC->getAsDecl()->getDescriptiveKind());
94+
diagnose(Context, L.getEndSourceLoc(), diagID, ResTy, FD);
9895
}
9996
}
10097

lib/SILOptimizer/Mandatory/FlowIsolation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ void Info::diagnoseAll(AnalysisInfo &info, bool forDeinit,
484484
VarDecl *var = cast<RefElementAddrInst>(use)->getField();
485485

486486
diag.diagnose(illegalLoc.getSourceLoc(), diag::isolated_after_nonisolated,
487-
forDeinit, var->getDescriptiveKind(), var->getName())
488-
.highlight(illegalLoc.getSourceRange())
489-
.warnUntilSwiftVersion(6);
487+
forDeinit, var)
488+
.highlight(illegalLoc.getSourceRange())
489+
.warnUntilSwiftVersion(6);
490490

491491
// after <verb><adjective> <subject>, ... can't use self anymore, etc ...
492492
// example:

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,16 @@ static std::optional<SILDeclRef> getDeclRefForCallee(SILInstruction *inst) {
149149
}
150150
}
151151

152-
static std::optional<std::pair<DescriptiveDeclKind, DeclName>>
153-
getSendingApplyCalleeInfo(SILInstruction *inst) {
152+
static std::optional<ValueDecl *> getSendingApplyCallee(SILInstruction *inst) {
154153
auto declRef = getDeclRefForCallee(inst);
155154
if (!declRef)
156155
return {};
157156

158157
auto *decl = declRef->getDecl();
159-
if (!decl || !decl->hasName())
158+
if (!decl)
160159
return {};
161160

162-
return {{decl->getDescriptiveKind(), decl->getName()}};
161+
return decl;
163162
}
164163

165164
static Expr *inferArgumentExprFromApplyExpr(ApplyExpr *sourceApply,
@@ -672,10 +671,9 @@ class UseAfterSendDiagnosticEmitter {
672671
getFunction());
673672
}
674673

675-
/// If we can find a callee decl name, return that. None otherwise.
676-
std::optional<std::pair<DescriptiveDeclKind, DeclName>>
677-
getSendingCalleeInfo() const {
678-
return getSendingApplyCalleeInfo(sendingOp->getUser());
674+
/// Attempts to retrieve and return the callee declaration.
675+
std::optional<const ValueDecl *> getSendingCallee() const {
676+
return getSendingApplyCallee(sendingOp->getUser());
679677
}
680678

681679
void
@@ -697,12 +695,11 @@ class UseAfterSendDiagnosticEmitter {
697695
}
698696
}
699697

700-
if (auto calleeInfo = getSendingCalleeInfo()) {
698+
if (auto callee = getSendingCallee()) {
701699
diagnoseNote(
702700
loc, diag::regionbasedisolation_named_info_send_yields_race_callee,
703701
name, descriptiveKindStr, isolationCrossing.getCalleeIsolation(),
704-
calleeInfo->first, calleeInfo->second,
705-
isolationCrossing.getCallerIsolation());
702+
callee.value(), isolationCrossing.getCallerIsolation());
706703
} else {
707704
diagnoseNote(loc, diag::regionbasedisolation_named_info_send_yields_race,
708705
name, descriptiveKindStr,
@@ -716,8 +713,7 @@ class UseAfterSendDiagnosticEmitter {
716713
emitNamedIsolationCrossingError(SILLocation loc, Identifier name,
717714
SILIsolationInfo namedValuesIsolationInfo,
718715
ApplyIsolationCrossing isolationCrossing,
719-
DeclName calleeDeclName,
720-
DescriptiveDeclKind calleeDeclKind) {
716+
const ValueDecl *callee) {
721717
// Emit the short error.
722718
diagnoseError(loc, diag::regionbasedisolation_named_send_yields_race, name)
723719
.highlight(loc.getSourceRange())
@@ -736,7 +732,7 @@ class UseAfterSendDiagnosticEmitter {
736732
diagnoseNote(
737733
loc, diag::regionbasedisolation_named_info_send_yields_race_callee,
738734
name, descriptiveKindStr, isolationCrossing.getCalleeIsolation(),
739-
calleeDeclKind, calleeDeclName, isolationCrossing.getCallerIsolation());
735+
callee, isolationCrossing.getCallerIsolation());
740736
emitRequireInstDiagnostics();
741737
}
742738

@@ -759,11 +755,10 @@ class UseAfterSendDiagnosticEmitter {
759755
.highlight(loc.getSourceRange())
760756
.limitBehaviorIf(getBehaviorLimit());
761757

762-
if (auto calleeInfo = getSendingCalleeInfo()) {
758+
if (auto callee = getSendingCallee()) {
763759
diagnoseNote(loc, diag::regionbasedisolation_type_use_after_send_callee,
764760
inferredType, isolationCrossing.getCalleeIsolation(),
765-
calleeInfo->first, calleeInfo->second,
766-
isolationCrossing.getCallerIsolation());
761+
callee.value(), isolationCrossing.getCallerIsolation());
767762
} else {
768763
diagnoseNote(loc, diag::regionbasedisolation_type_use_after_send,
769764
inferredType, isolationCrossing.getCalleeIsolation(),
@@ -793,10 +788,10 @@ class UseAfterSendDiagnosticEmitter {
793788
inferredType)
794789
.highlight(loc.getSourceRange())
795790
.limitBehaviorIf(getBehaviorLimit());
796-
if (auto calleeInfo = getSendingCalleeInfo()) {
791+
if (auto callee = getSendingCallee()) {
797792
diagnoseNote(loc,
798793
diag::regionbasedisolation_typed_use_after_sending_callee,
799-
inferredType, calleeInfo->first, calleeInfo->second);
794+
inferredType, callee.value());
800795
} else {
801796
diagnoseNote(loc, diag::regionbasedisolation_typed_use_after_sending,
802797
inferredType);
@@ -1106,8 +1101,7 @@ struct UseAfterSendDiagnosticInferrer::AutoClosureWalker : ASTWalker {
11061101
if (valueDecl->hasName()) {
11071102
foundTypeInfo.diagnosticEmitter.emitNamedIsolationCrossingError(
11081103
foundTypeInfo.baseLoc, targetDecl->getBaseIdentifier(),
1109-
targetDeclIsolationInfo, *isolationCrossing,
1110-
valueDecl->getName(), valueDecl->getDescriptiveKind());
1104+
targetDeclIsolationInfo, *isolationCrossing, valueDecl);
11111105
continue;
11121106
}
11131107

@@ -1322,10 +1316,9 @@ class SendNeverSentDiagnosticEmitter {
13221316
getOperand()->getFunction());
13231317
}
13241318

1325-
/// If we can find a callee decl name, return that. None otherwise.
1326-
std::optional<std::pair<DescriptiveDeclKind, DeclName>>
1327-
getSendingCalleeInfo() const {
1328-
return getSendingApplyCalleeInfo(sendingOperand->getUser());
1319+
/// Attempts to retrieve and return the callee declaration.
1320+
std::optional<const ValueDecl *> getSendingCallee() const {
1321+
return getSendingApplyCallee(sendingOperand->getUser());
13291322
}
13301323

13311324
SILLocation getLoc() const { return sendingOperand->getUser()->getLoc(); }
@@ -1365,12 +1358,12 @@ class SendNeverSentDiagnosticEmitter {
13651358
getIsolationRegionInfo().printForDiagnostics(os);
13661359
}
13671360

1368-
if (auto calleeInfo = getSendingCalleeInfo()) {
1361+
if (auto callee = getSendingCallee()) {
13691362
diagnoseNote(
13701363
loc,
13711364
diag::regionbasedisolation_typed_sendneversendable_via_arg_callee,
13721365
descriptiveKindStr, inferredType, crossing.getCalleeIsolation(),
1373-
calleeInfo->first, calleeInfo->second);
1366+
callee.value());
13741367
} else {
13751368
diagnoseNote(
13761369
loc, diag::regionbasedisolation_typed_sendneversendable_via_arg,
@@ -1409,11 +1402,10 @@ class SendNeverSentDiagnosticEmitter {
14091402
getIsolationRegionInfo().printForDiagnostics(os);
14101403
}
14111404

1412-
if (auto calleeInfo = getSendingCalleeInfo()) {
1405+
if (auto callee = getSendingCallee()) {
14131406
diagnoseNote(
14141407
loc, diag::regionbasedisolation_typed_tns_passed_to_sending_callee,
1415-
descriptiveKindStr, inferredType, calleeInfo->first,
1416-
calleeInfo->second);
1408+
descriptiveKindStr, inferredType, callee.value());
14171409
} else {
14181410
diagnoseNote(loc, diag::regionbasedisolation_typed_tns_passed_to_sending,
14191411
descriptiveKindStr, inferredType);
@@ -1475,8 +1467,7 @@ class SendNeverSentDiagnosticEmitter {
14751467
fArg->getType().is<SILBoxType>()) {
14761468
auto diag = diag::
14771469
regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_boxed_value_task_isolated;
1478-
diagnoseNote(actualUse, diag, fArg->getDecl()->getName(),
1479-
fArg->getDecl()->getDescriptiveKind());
1470+
diagnoseNote(actualUse, diag, fArg->getDecl());
14801471
return;
14811472
}
14821473

@@ -1614,12 +1605,12 @@ class SendNeverSentDiagnosticEmitter {
16141605
descriptiveKindStrWithSpace.push_back(' ');
16151606
}
16161607
}
1617-
if (auto calleeInfo = getSendingCalleeInfo()) {
1608+
if (auto callee = getSendingCallee()) {
16181609
diagnoseNote(loc,
16191610
diag::regionbasedisolation_named_send_never_sendable_callee,
16201611
name, descriptiveKindStrWithSpace,
1621-
isolationCrossing.getCalleeIsolation(), calleeInfo->first,
1622-
calleeInfo->second, descriptiveKindStr);
1612+
isolationCrossing.getCalleeIsolation(), callee.value(),
1613+
descriptiveKindStr);
16231614
} else {
16241615
diagnoseNote(loc, diag::regionbasedisolation_named_send_never_sendable,
16251616
name, descriptiveKindStrWithSpace,

0 commit comments

Comments
 (0)