[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.
This commit is contained in:
Michael Gottesman
2025-07-02 16:11:43 -07:00
parent 14634b6847
commit 010fa39f31
5 changed files with 180 additions and 268 deletions

View File

@@ -332,8 +332,16 @@ public:
/// form of diagnostic than other cases.
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const;
/// Overload of printForCodeDiagnostics that returns an interned StringRef
/// owned by the AST.
StringRef printForCodeDiagnostic(SILFunction *fn) const;
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const;
/// Overload of printForDiagnostics that returns an interned StringRef owned
/// by the AST.
StringRef printForDiagnostics(SILFunction *fn) const;
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
printForDiagnostics(fn, llvm::dbgs());
llvm::dbgs() << '\n';
@@ -524,6 +532,12 @@ public:
SILFunction *fn, ActorIsolation iso, llvm::raw_ostream &os,
StringRef openingQuotationMark = "'", bool asNoun = false);
/// Overload for printActorIsolationForDiagnostics that produces a StringRef.
static StringRef
printActorIsolationForDiagnostics(SILFunction *fn, ActorIsolation iso,
StringRef openingQuotationMark = "'",
bool asNoun = false);
void Profile(llvm::FoldingSetNodeID &id) const;
private:
@@ -593,6 +607,10 @@ public:
innerInfo.printForDiagnostics(fn, os);
}
StringRef printForDiagnostics(SILFunction *fn) const {
return innerInfo.printForDiagnostics(fn);
}
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
innerInfo.dumpForDiagnostics(fn);
}
@@ -601,6 +619,10 @@ public:
innerInfo.printForCodeDiagnostic(fn, os);
}
StringRef printForCodeDiagnostic(SILFunction *fn) const {
return innerInfo.printForCodeDiagnostic(fn);
}
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const {
innerInfo.printForOneLineLogging(fn, os);
}