Skip to content

Commit f5d547c

Browse files
AnthonyLatsisgottesmm
authored andcommitted
AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSIL.def
(cherry picked from commit 5c190b9)
1 parent 065ffa3 commit f5d547c

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))
@@ -984,16 +985,16 @@ NOTE(regionbasedisolation_type_use_after_send, none,
984985
"sending value of non-Sendable type %0 to %1 callee risks causing data races between %1 and local %2 uses",
985986
(Type, ActorIsolation, ActorIsolation))
986987
NOTE(regionbasedisolation_type_use_after_send_callee, none,
987-
"sending value of non-Sendable type %0 to %1 %2 %3 risks causing data "
988-
"races between %1 and local %4 uses",
989-
(Type, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
988+
"sending value of non-Sendable type %0 to %1 %kind2 risks causing data "
989+
"races between %1 and local %3 uses",
990+
(Type, ActorIsolation, const ValueDecl *, ActorIsolation))
990991

991992
NOTE(regionbasedisolation_named_info_send_yields_race, none,
992993
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
993994
(Identifier, StringRef, ActorIsolation, ActorIsolation))
994995
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
995-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and local %5 uses",
996-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
996+
"sending %1%0 to %2 %kind3 risks causing data races between %2 and local %4 uses",
997+
(Identifier, StringRef, ActorIsolation, const ValueDecl *, ActorIsolation))
997998

998999
// Use after send closure.
9991000
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
@@ -1016,8 +1017,8 @@ NOTE(regionbasedisolation_typed_use_after_sending, none,
10161017
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
10171018
(Type))
10181019
NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
1019-
"Passing value of non-Sendable type %0 as a 'sending' argument to %1 %2 risks causing races in between local and caller code",
1020-
(Type, DescriptiveDeclKind, DeclName))
1020+
"Passing value of non-Sendable type %0 as a 'sending' argument to %kind1 risks causing races in between local and caller code",
1021+
(Type, const ValueDecl *))
10211022

10221023
//===
10231024
// Sending Never Sendable Emitter
@@ -1026,8 +1027,8 @@ NOTE(regionbasedisolation_named_send_never_sendable, none,
10261027
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
10271028
(Identifier, StringRef, ActorIsolation, StringRef))
10281029
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
1029-
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
1030-
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
1030+
"sending %1%0 to %2 %kind3 risks causing data races between %2 and %4 uses",
1031+
(Identifier, StringRef, ActorIsolation, const ValueDecl *, StringRef))
10311032

10321033
NOTE(regionbasedisolation_named_send_into_sending_param, none,
10331034
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
@@ -1051,8 +1052,8 @@ NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_
10511052
"closure captures %0 which is accessible to code in the current task",
10521053
(DeclName))
10531054
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_boxed_value_task_isolated, none,
1054-
"closure captures reference to mutable %1 %0 which is accessible to code in the current task",
1055-
(DeclName, DescriptiveDeclKind))
1055+
"closure captures reference to mutable %kind0 which is accessible to code in the current task",
1056+
(const ValueDecl *))
10561057
NOTE(regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_value_region, none,
10571058
"closure captures %1 which is accessible to %0 code",
10581059
(StringRef, DeclName))
@@ -1068,8 +1069,8 @@ NOTE(regionbasedisolation_closure_captures_actor, none,
10681069
(DeclName, StringRef))
10691070

10701071
NOTE(regionbasedisolation_typed_tns_passed_to_sending_callee, none,
1071-
"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",
1072-
(StringRef, Type, DescriptiveDeclKind, DeclName))
1072+
"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",
1073+
(StringRef, Type, const ValueDecl *))
10731074

10741075
NOTE(regionbasedisolation_named_send_nt_asynclet_capture, none,
10751076
"sending %1 %0 into async let risks causing data races between nonisolated and %1 uses",
@@ -1078,8 +1079,8 @@ NOTE(regionbasedisolation_typed_sendneversendable_via_arg, none,
10781079
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
10791080
(StringRef, Type, ActorIsolation))
10801081
NOTE(regionbasedisolation_typed_sendneversendable_via_arg_callee, none,
1081-
"sending %0 value of non-Sendable type %1 to %2 %3 %4 risks causing races in between %0 and %2 uses",
1082-
(StringRef, Type, ActorIsolation, DescriptiveDeclKind, DeclName))
1082+
"sending %0 value of non-Sendable type %1 to %2 %kind3 risks causing races in between %0 and %2 uses",
1083+
(StringRef, Type, ActorIsolation, const ValueDecl *))
10831084

10841085
NOTE(regionbasedisolation_isolated_conformance_introduced, none,
10851086
"isolated conformance to %kind0 can be introduced here",

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

@@ -1341,10 +1335,9 @@ class SendNeverSentDiagnosticEmitter {
13411335
getOperand()->getFunction());
13421336
}
13431337

1344-
/// If we can find a callee decl name, return that. None otherwise.
1345-
std::optional<std::pair<DescriptiveDeclKind, DeclName>>
1346-
getSendingCalleeInfo() const {
1347-
return getSendingApplyCalleeInfo(sendingOperand->getUser());
1338+
/// Attempts to retrieve and return the callee declaration.
1339+
std::optional<const ValueDecl *> getSendingCallee() const {
1340+
return getSendingApplyCallee(sendingOperand->getUser());
13481341
}
13491342

13501343
SILLocation getLoc() const { return sendingOperand->getUser()->getLoc(); }
@@ -1384,12 +1377,12 @@ class SendNeverSentDiagnosticEmitter {
13841377
getIsolationRegionInfo().printForDiagnostics(os);
13851378
}
13861379

1387-
if (auto calleeInfo = getSendingCalleeInfo()) {
1380+
if (auto callee = getSendingCallee()) {
13881381
diagnoseNote(
13891382
loc,
13901383
diag::regionbasedisolation_typed_sendneversendable_via_arg_callee,
13911384
descriptiveKindStr, inferredType, crossing.getCalleeIsolation(),
1392-
calleeInfo->first, calleeInfo->second);
1385+
callee.value());
13931386
} else {
13941387
diagnoseNote(
13951388
loc, diag::regionbasedisolation_typed_sendneversendable_via_arg,
@@ -1428,11 +1421,10 @@ class SendNeverSentDiagnosticEmitter {
14281421
getIsolationRegionInfo().printForDiagnostics(os);
14291422
}
14301423

1431-
if (auto calleeInfo = getSendingCalleeInfo()) {
1424+
if (auto callee = getSendingCallee()) {
14321425
diagnoseNote(
14331426
loc, diag::regionbasedisolation_typed_tns_passed_to_sending_callee,
1434-
descriptiveKindStr, inferredType, calleeInfo->first,
1435-
calleeInfo->second);
1427+
descriptiveKindStr, inferredType, callee.value());
14361428
} else {
14371429
diagnoseNote(loc, diag::regionbasedisolation_typed_tns_passed_to_sending,
14381430
descriptiveKindStr, inferredType);
@@ -1494,8 +1486,7 @@ class SendNeverSentDiagnosticEmitter {
14941486
fArg->getType().is<SILBoxType>()) {
14951487
auto diag = diag::
14961488
regionbasedisolation_typed_tns_passed_to_sending_closure_helper_have_boxed_value_task_isolated;
1497-
diagnoseNote(actualUse, diag, fArg->getDecl()->getName(),
1498-
fArg->getDecl()->getDescriptiveKind());
1489+
diagnoseNote(actualUse, diag, fArg->getDecl());
14991490
return;
15001491
}
15011492

@@ -1632,12 +1623,12 @@ class SendNeverSentDiagnosticEmitter {
16321623
descriptiveKindStrWithSpace.push_back(' ');
16331624
}
16341625
}
1635-
if (auto calleeInfo = getSendingCalleeInfo()) {
1626+
if (auto callee = getSendingCallee()) {
16361627
diagnoseNote(loc,
16371628
diag::regionbasedisolation_named_send_never_sendable_callee,
16381629
name, descriptiveKindStrWithSpace,
1639-
isolationCrossing.getCalleeIsolation(), calleeInfo->first,
1640-
calleeInfo->second, descriptiveKindStr);
1630+
isolationCrossing.getCalleeIsolation(), callee.value(),
1631+
descriptiveKindStr);
16411632
} else {
16421633
diagnoseNote(loc, diag::regionbasedisolation_named_send_never_sendable,
16431634
name, descriptiveKindStrWithSpace,

0 commit comments

Comments
 (0)