Skip to content

Commit f920aba

Browse files
committed
[rbi] Use interned StringRefs for diagnostics instead of SmallString<64>.
This makes the code easier to write and also prevents any lifetime issues from a diagnostic outliving the SmallString due to diagnostic transactions. (cherry picked from commit 010fa39)
1 parent 85fafa5 commit f920aba

File tree

5 files changed

+181
-269
lines changed

5 files changed

+181
-269
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,11 @@ NOTE(regionbasedisolation_type_use_after_send_callee, none,
990990
(Type, StringRef, const ValueDecl *, StringRef))
991991

992992
NOTE(regionbasedisolation_named_info_send_yields_race, none,
993-
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
994-
(Identifier, StringRef, StringRef, StringRef))
993+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and local %4 uses",
994+
(bool, Identifier, StringRef, StringRef, StringRef))
995995
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
996-
"sending %1%0 to %2 %kind3 risks causing data races between %2 and local %4 uses",
997-
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
996+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and local %5 uses",
997+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
998998

999999
// Use after send closure.
10001000
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
@@ -1010,8 +1010,8 @@ NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
10101010
"%0 used after being passed as a 'sending' parameter; Later uses could race",
10111011
(Identifier))
10121012
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
1013-
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
1014-
(StringRef, Identifier, StringRef, StringRef))
1013+
"%select{%1 |}0%2 is captured by a %3 closure. %3 uses in closure may race against later %4 uses",
1014+
(bool, StringRef, Identifier, StringRef, StringRef))
10151015

10161016
NOTE(regionbasedisolation_typed_use_after_sending, none,
10171017
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
@@ -1024,19 +1024,19 @@ NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
10241024
// Sending Never Sendable Emitter
10251025

10261026
NOTE(regionbasedisolation_named_send_never_sendable, none,
1027-
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
1028-
(Identifier, StringRef, StringRef, StringRef))
1027+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and %4 uses",
1028+
(bool, Identifier, StringRef, StringRef, StringRef))
10291029
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
1030-
"sending %1%0 to %2 %kind3 risks causing data races between %2 and %4 uses",
1031-
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
1030+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and %5 uses",
1031+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
10321032

10331033
NOTE(regionbasedisolation_named_send_into_sending_param, none,
1034-
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
1035-
"later %0uses",
1036-
(StringRef, Identifier))
1034+
"%select{%1 |}0%2 is passed as a 'sending' parameter; Uses in callee may race with "
1035+
"later %1 uses",
1036+
(bool, StringRef, Identifier))
10371037
NOTE(regionbasedisolation_named_nosend_send_into_result, none,
1038-
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
1039-
(StringRef, Identifier, StringRef))
1038+
"%select{%1 |}0%2 cannot be a 'sending' result. %3 uses may race with caller uses",
1039+
(bool, StringRef, Identifier, StringRef))
10401040
NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
10411041
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter risks "
10421042
"causing races inbetween %0 uses and uses reachable from the callee",
@@ -1098,10 +1098,10 @@ NOTE(regionbasedisolation_inout_sending_must_be_reinitialized, none,
10981098
"'inout sending' parameter must be reinitialized before function exit with a non-actor isolated value",
10991099
())
11001100
ERROR(regionbasedisolation_inout_sending_cannot_be_actor_isolated, none,
1101-
"'inout sending' parameter %0 cannot be %1at end of function",
1101+
"'inout sending' parameter %0 cannot be %1 at end of function",
11021102
(Identifier, StringRef))
11031103
NOTE(regionbasedisolation_inout_sending_cannot_be_actor_isolated_note, none,
1104-
"%1%0 risks causing races in between %1uses and caller uses since caller assumes value is not actor isolated",
1104+
"%1 %0 risks causing races in between %1 uses and caller uses since caller assumes value is not actor isolated",
11051105
(Identifier, StringRef))
11061106

11071107
//===

include/swift/AST/Identifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Identifier {
230230
private:
231231
bool isOperatorSlow() const;
232232
};
233-
233+
234234
class DeclName;
235235
class DeclNameRef;
236236
class ObjCSelector;

include/swift/SILOptimizer/Utils/SILIsolationInfo.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,16 @@ class SILIsolationInfo {
380380
/// form of diagnostic than other cases.
381381
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const;
382382

383+
/// Overload of printForCodeDiagnostics that returns an interned StringRef
384+
/// owned by the AST.
385+
StringRef printForCodeDiagnostic(SILFunction *fn) const;
386+
383387
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const;
384388

389+
/// Overload of printForDiagnostics that returns an interned StringRef owned
390+
/// by the AST.
391+
StringRef printForDiagnostics(SILFunction *fn) const;
392+
385393
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
386394
printForDiagnostics(fn, llvm::dbgs());
387395
llvm::dbgs() << '\n';
@@ -579,6 +587,12 @@ class SILIsolationInfo {
579587
SILFunction *fn, ActorIsolation iso, llvm::raw_ostream &os,
580588
StringRef openingQuotationMark = "'", bool asNoun = false);
581589

590+
/// Overload for printActorIsolationForDiagnostics that produces a StringRef.
591+
static StringRef
592+
printActorIsolationForDiagnostics(SILFunction *fn, ActorIsolation iso,
593+
StringRef openingQuotationMark = "'",
594+
bool asNoun = false);
595+
582596
void Profile(llvm::FoldingSetNodeID &id) const;
583597

584598
private:
@@ -648,6 +662,10 @@ class SILDynamicMergedIsolationInfo {
648662
innerInfo.printForDiagnostics(fn, os);
649663
}
650664

665+
StringRef printForDiagnostics(SILFunction *fn) const {
666+
return innerInfo.printForDiagnostics(fn);
667+
}
668+
651669
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
652670
innerInfo.dumpForDiagnostics(fn);
653671
}
@@ -656,6 +674,10 @@ class SILDynamicMergedIsolationInfo {
656674
innerInfo.printForCodeDiagnostic(fn, os);
657675
}
658676

677+
StringRef printForCodeDiagnostic(SILFunction *fn) const {
678+
return innerInfo.printForCodeDiagnostic(fn);
679+
}
680+
659681
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const {
660682
innerInfo.printForOneLineLogging(fn, os);
661683
}

0 commit comments

Comments
 (0)