Skip to content

Commit 010fa39

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.
1 parent 14634b6 commit 010fa39

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
@@ -1005,11 +1005,11 @@ NOTE(regionbasedisolation_type_use_after_send_callee, none,
10051005
(Type, StringRef, const ValueDecl *, StringRef))
10061006

10071007
NOTE(regionbasedisolation_named_info_send_yields_race, none,
1008-
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
1009-
(Identifier, StringRef, StringRef, StringRef))
1008+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and local %4 uses",
1009+
(bool, Identifier, StringRef, StringRef, StringRef))
10101010
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
1011-
"sending %1%0 to %2 %kind3 risks causing data races between %2 and local %4 uses",
1012-
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
1011+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and local %5 uses",
1012+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
10131013

10141014
// Use after send closure.
10151015
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
@@ -1025,8 +1025,8 @@ NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
10251025
"%0 used after being passed as a 'sending' parameter; Later uses could race",
10261026
(Identifier))
10271027
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
1028-
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
1029-
(StringRef, Identifier, StringRef, StringRef))
1028+
"%select{%1 |}0%2 is captured by a %3 closure. %3 uses in closure may race against later %4 uses",
1029+
(bool, StringRef, Identifier, StringRef, StringRef))
10301030

10311031
NOTE(regionbasedisolation_typed_use_after_sending, none,
10321032
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
@@ -1039,19 +1039,19 @@ NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
10391039
// Sending Never Sendable Emitter
10401040

10411041
NOTE(regionbasedisolation_named_send_never_sendable, none,
1042-
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
1043-
(Identifier, StringRef, StringRef, StringRef))
1042+
"sending %select{%2 |}0%1 to %3 callee risks causing data races between %3 and %4 uses",
1043+
(bool, Identifier, StringRef, StringRef, StringRef))
10441044
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
1045-
"sending %1%0 to %2 %kind3 risks causing data races between %2 and %4 uses",
1046-
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
1045+
"sending %select{%2 |}0%1 to %3 %kind4 risks causing data races between %3 and %5 uses",
1046+
(bool, Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
10471047

10481048
NOTE(regionbasedisolation_named_send_into_sending_param, none,
1049-
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
1050-
"later %0uses",
1051-
(StringRef, Identifier))
1049+
"%select{%1 |}0%2 is passed as a 'sending' parameter; Uses in callee may race with "
1050+
"later %1 uses",
1051+
(bool, StringRef, Identifier))
10521052
NOTE(regionbasedisolation_named_nosend_send_into_result, none,
1053-
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
1054-
(StringRef, Identifier, StringRef))
1053+
"%select{%1 |}0%2 cannot be a 'sending' result. %3 uses may race with caller uses",
1054+
(bool, StringRef, Identifier, StringRef))
10551055
NOTE(regionbasedisolation_typed_tns_passed_to_sending, none,
10561056
"Passing %0 value of non-Sendable type %1 as a 'sending' parameter risks "
10571057
"causing races inbetween %0 uses and uses reachable from the callee",
@@ -1109,10 +1109,10 @@ NOTE(regionbasedisolation_inout_sending_must_be_reinitialized, none,
11091109
"'inout sending' parameter must be reinitialized before function exit with a non-actor-isolated value",
11101110
())
11111111
ERROR(regionbasedisolation_inout_sending_cannot_be_actor_isolated, none,
1112-
"'inout sending' parameter %0 cannot be %1at end of function",
1112+
"'inout sending' parameter %0 cannot be %1 at end of function",
11131113
(Identifier, StringRef))
11141114
NOTE(regionbasedisolation_inout_sending_cannot_be_actor_isolated_note, none,
1115-
"%1%0 risks causing races in between %1uses and caller uses since caller assumes value is not actor isolated",
1115+
"%1 %0 risks causing races in between %1 uses and caller uses since caller assumes value is not actor isolated",
11161116
(Identifier, StringRef))
11171117

11181118
//===

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
@@ -332,8 +332,16 @@ class SILIsolationInfo {
332332
/// form of diagnostic than other cases.
333333
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const;
334334

335+
/// Overload of printForCodeDiagnostics that returns an interned StringRef
336+
/// owned by the AST.
337+
StringRef printForCodeDiagnostic(SILFunction *fn) const;
338+
335339
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const;
336340

341+
/// Overload of printForDiagnostics that returns an interned StringRef owned
342+
/// by the AST.
343+
StringRef printForDiagnostics(SILFunction *fn) const;
344+
337345
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
338346
printForDiagnostics(fn, llvm::dbgs());
339347
llvm::dbgs() << '\n';
@@ -524,6 +532,12 @@ class SILIsolationInfo {
524532
SILFunction *fn, ActorIsolation iso, llvm::raw_ostream &os,
525533
StringRef openingQuotationMark = "'", bool asNoun = false);
526534

535+
/// Overload for printActorIsolationForDiagnostics that produces a StringRef.
536+
static StringRef
537+
printActorIsolationForDiagnostics(SILFunction *fn, ActorIsolation iso,
538+
StringRef openingQuotationMark = "'",
539+
bool asNoun = false);
540+
527541
void Profile(llvm::FoldingSetNodeID &id) const;
528542

529543
private:
@@ -593,6 +607,10 @@ class SILDynamicMergedIsolationInfo {
593607
innerInfo.printForDiagnostics(fn, os);
594608
}
595609

610+
StringRef printForDiagnostics(SILFunction *fn) const {
611+
return innerInfo.printForDiagnostics(fn);
612+
}
613+
596614
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
597615
innerInfo.dumpForDiagnostics(fn);
598616
}
@@ -601,6 +619,10 @@ class SILDynamicMergedIsolationInfo {
601619
innerInfo.printForCodeDiagnostic(fn, os);
602620
}
603621

622+
StringRef printForCodeDiagnostic(SILFunction *fn) const {
623+
return innerInfo.printForCodeDiagnostic(fn);
624+
}
625+
604626
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const {
605627
innerInfo.printForOneLineLogging(fn, os);
606628
}

0 commit comments

Comments
 (0)