mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[rbi] Wrap use ActorIsolation::printForDiagnostics with our own SILIsolationInfo::printActorIsolationForDiagnostics.
I am doing this so that I can change how we emit the diagnostics just for
SendNonSendable depending on if NonisolatedNonsendingByDefault is enabled
without touching the rest of the compiler.
This does not actually change any of the actual output though.
(cherry picked from commit 4ce4fc4f95)
This commit is contained in:
@@ -983,23 +983,23 @@ GROUPED_ERROR(regionbasedisolation_type_send_yields_race, SendingRisksDataRace,
|
||||
(Type))
|
||||
NOTE(regionbasedisolation_type_use_after_send, none,
|
||||
"sending value of non-Sendable type %0 to %1 callee risks causing data races between %1 and local %2 uses",
|
||||
(Type, ActorIsolation, ActorIsolation))
|
||||
(Type, StringRef, StringRef))
|
||||
NOTE(regionbasedisolation_type_use_after_send_callee, none,
|
||||
"sending value of non-Sendable type %0 to %1 %kind2 risks causing data "
|
||||
"races between %1 and local %3 uses",
|
||||
(Type, ActorIsolation, const ValueDecl *, ActorIsolation))
|
||||
(Type, StringRef, const ValueDecl *, StringRef))
|
||||
|
||||
NOTE(regionbasedisolation_named_info_send_yields_race, none,
|
||||
"sending %1%0 to %2 callee risks causing data races between %2 and local %3 uses",
|
||||
(Identifier, StringRef, ActorIsolation, ActorIsolation))
|
||||
(Identifier, StringRef, StringRef, StringRef))
|
||||
NOTE(regionbasedisolation_named_info_send_yields_race_callee, none,
|
||||
"sending %1%0 to %2 %kind3 risks causing data races between %2 and local %4 uses",
|
||||
(Identifier, StringRef, ActorIsolation, const ValueDecl *, ActorIsolation))
|
||||
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
|
||||
|
||||
// Use after send closure.
|
||||
NOTE(regionbasedisolation_type_isolated_capture_yields_race, none,
|
||||
"sending value of non-Sendable type %0 to %1 closure due to closure capture risks causing races in between %1 and %2 uses",
|
||||
(Type, ActorIsolation, ActorIsolation))
|
||||
(Type, StringRef, StringRef))
|
||||
|
||||
// Value captured in async let and reused.
|
||||
NOTE(regionbasedisolation_named_nonisolated_asynclet_name, none,
|
||||
@@ -1011,7 +1011,7 @@ NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
|
||||
(Identifier))
|
||||
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
|
||||
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",
|
||||
(StringRef, Identifier, ActorIsolation, ActorIsolation))
|
||||
(StringRef, Identifier, StringRef, StringRef))
|
||||
|
||||
NOTE(regionbasedisolation_typed_use_after_sending, none,
|
||||
"Passing value of non-Sendable type %0 as a 'sending' argument risks causing races in between local and caller code",
|
||||
@@ -1025,10 +1025,10 @@ NOTE(regionbasedisolation_typed_use_after_sending_callee, none,
|
||||
|
||||
NOTE(regionbasedisolation_named_send_never_sendable, none,
|
||||
"sending %1%0 to %2 callee risks causing data races between %2 and %3 uses",
|
||||
(Identifier, StringRef, ActorIsolation, StringRef))
|
||||
(Identifier, StringRef, StringRef, StringRef))
|
||||
NOTE(regionbasedisolation_named_send_never_sendable_callee, none,
|
||||
"sending %1%0 to %2 %kind3 risks causing data races between %2 and %4 uses",
|
||||
(Identifier, StringRef, ActorIsolation, const ValueDecl *, StringRef))
|
||||
(Identifier, StringRef, StringRef, const ValueDecl *, StringRef))
|
||||
|
||||
NOTE(regionbasedisolation_named_send_into_sending_param, none,
|
||||
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with "
|
||||
@@ -1077,10 +1077,10 @@ NOTE(regionbasedisolation_named_send_nt_asynclet_capture, none,
|
||||
(Identifier, StringRef))
|
||||
NOTE(regionbasedisolation_typed_sendneversendable_via_arg, none,
|
||||
"sending %0 value of non-Sendable type %1 to %2 callee risks causing races in between %0 and %2 uses",
|
||||
(StringRef, Type, ActorIsolation))
|
||||
(StringRef, Type, StringRef))
|
||||
NOTE(regionbasedisolation_typed_sendneversendable_via_arg_callee, none,
|
||||
"sending %0 value of non-Sendable type %1 to %2 %kind3 risks causing races in between %0 and %2 uses",
|
||||
(StringRef, Type, ActorIsolation, const ValueDecl *))
|
||||
(StringRef, Type, StringRef, const ValueDecl *))
|
||||
|
||||
NOTE(regionbasedisolation_isolated_conformance_introduced, none,
|
||||
"isolated conformance to %kind0 can be introduced here",
|
||||
@@ -1126,10 +1126,10 @@ NOTE(regionbasedisolation_out_sending_cannot_be_actor_isolated_note_named, none,
|
||||
// Example: returning main-actor isolated result to a custom-actor isolated context risks causing data races
|
||||
ERROR(rbi_isolation_crossing_result, none,
|
||||
"non-Sendable %0-typed result can not be returned from %1 %kind2 to %3 context",
|
||||
(Type, ActorIsolation, const ValueDecl *, ActorIsolation))
|
||||
(Type, StringRef, const ValueDecl *, StringRef))
|
||||
ERROR(rbi_isolation_crossing_result_no_decl, none,
|
||||
"non-Sendable %0-typed result can not be returned from %1 function to %2 context",
|
||||
(Type, ActorIsolation, ActorIsolation))
|
||||
(Type, StringRef, StringRef))
|
||||
NOTE(rbi_non_sendable_nominal,none,
|
||||
"%kind0 does not conform to the 'Sendable' protocol",
|
||||
(const ValueDecl *))
|
||||
|
||||
@@ -549,6 +549,14 @@ public:
|
||||
/// that the isolation and the isolated value match.
|
||||
bool isEqual(const SILIsolationInfo &other) const;
|
||||
|
||||
/// A helper function that prints ActorIsolation like we normally do except
|
||||
/// that it prints nonisolated(nonsending) as nonisolated. This is needed in
|
||||
/// certain cases when talking about use-after-free uses in send non sendable.
|
||||
static void
|
||||
printActorIsolationForDiagnostics(ActorIsolation iso, llvm::raw_ostream &os,
|
||||
StringRef openingQuotationMark = "'",
|
||||
bool asNoun = false);
|
||||
|
||||
void Profile(llvm::FoldingSetNodeID &id) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -695,16 +695,29 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
if (auto callee = getSendingCallee()) {
|
||||
diagnoseNote(
|
||||
loc, diag::regionbasedisolation_named_info_send_yields_race_callee,
|
||||
name, descriptiveKindStr, isolationCrossing.getCalleeIsolation(),
|
||||
callee.value(), isolationCrossing.getCallerIsolation());
|
||||
name, descriptiveKindStr, calleeIsolationStr, callee.value(),
|
||||
callerIsolationStr);
|
||||
} else {
|
||||
diagnoseNote(loc, diag::regionbasedisolation_named_info_send_yields_race,
|
||||
name, descriptiveKindStr,
|
||||
isolationCrossing.getCalleeIsolation(),
|
||||
isolationCrossing.getCallerIsolation());
|
||||
name, descriptiveKindStr, calleeIsolationStr,
|
||||
callerIsolationStr);
|
||||
}
|
||||
emitRequireInstDiagnostics();
|
||||
}
|
||||
@@ -729,10 +742,24 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
diagnoseNote(
|
||||
loc, diag::regionbasedisolation_named_info_send_yields_race_callee,
|
||||
name, descriptiveKindStr, isolationCrossing.getCalleeIsolation(),
|
||||
callee, isolationCrossing.getCallerIsolation());
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
diagnoseNote(loc,
|
||||
diag::regionbasedisolation_named_info_send_yields_race_callee,
|
||||
name, descriptiveKindStr, calleeIsolationStr, callee,
|
||||
callerIsolationStr);
|
||||
emitRequireInstDiagnostics();
|
||||
}
|
||||
|
||||
@@ -755,14 +782,27 @@ public:
|
||||
.highlight(loc.getSourceRange())
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
if (auto callee = getSendingCallee()) {
|
||||
diagnoseNote(loc, diag::regionbasedisolation_type_use_after_send_callee,
|
||||
inferredType, isolationCrossing.getCalleeIsolation(),
|
||||
callee.value(), isolationCrossing.getCallerIsolation());
|
||||
inferredType, calleeIsolationStr, callee.value(),
|
||||
callerIsolationStr);
|
||||
} else {
|
||||
diagnoseNote(loc, diag::regionbasedisolation_type_use_after_send,
|
||||
inferredType, isolationCrossing.getCalleeIsolation(),
|
||||
isolationCrossing.getCallerIsolation());
|
||||
inferredType, calleeIsolationStr, callerIsolationStr);
|
||||
}
|
||||
emitRequireInstDiagnostics();
|
||||
}
|
||||
@@ -817,10 +857,23 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
diagnoseNote(
|
||||
loc, diag::regionbasedisolation_named_isolated_closure_yields_race,
|
||||
descriptiveKindStr, name, isolationCrossing.getCalleeIsolation(),
|
||||
isolationCrossing.getCallerIsolation())
|
||||
descriptiveKindStr, name, calleeIsolationStr, callerIsolationStr)
|
||||
.highlight(loc.getSourceRange());
|
||||
emitRequireInstDiagnostics();
|
||||
}
|
||||
@@ -832,10 +885,24 @@ public:
|
||||
inferredType)
|
||||
.highlight(loc.getSourceRange())
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
diagnoseNote(loc,
|
||||
diag::regionbasedisolation_type_isolated_capture_yields_race,
|
||||
inferredType, isolationCrossing.getCalleeIsolation(),
|
||||
isolationCrossing.getCallerIsolation());
|
||||
inferredType, calleeIsolationStr, callerIsolationStr);
|
||||
emitRequireInstDiagnostics();
|
||||
}
|
||||
|
||||
@@ -1377,16 +1444,22 @@ public:
|
||||
getIsolationRegionInfo().printForDiagnostics(os);
|
||||
}
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
crossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
if (auto callee = getSendingCallee()) {
|
||||
diagnoseNote(
|
||||
loc,
|
||||
diag::regionbasedisolation_typed_sendneversendable_via_arg_callee,
|
||||
descriptiveKindStr, inferredType, crossing.getCalleeIsolation(),
|
||||
callee.value());
|
||||
descriptiveKindStr, inferredType, calleeIsolationStr, callee.value());
|
||||
} else {
|
||||
diagnoseNote(
|
||||
loc, diag::regionbasedisolation_typed_sendneversendable_via_arg,
|
||||
descriptiveKindStr, inferredType, crossing.getCalleeIsolation());
|
||||
diagnoseNote(loc,
|
||||
diag::regionbasedisolation_typed_sendneversendable_via_arg,
|
||||
descriptiveKindStr, inferredType, calleeIsolationStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1401,10 +1474,24 @@ public:
|
||||
os << ' ';
|
||||
}
|
||||
}
|
||||
diagnoseNote(loc,
|
||||
diag::regionbasedisolation_named_isolated_closure_yields_race,
|
||||
descriptiveKindStr, name, crossing.getCalleeIsolation(),
|
||||
crossing.getCallerIsolation())
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
crossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
crossing.getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
diagnoseNote(
|
||||
loc, diag::regionbasedisolation_named_isolated_closure_yields_race,
|
||||
descriptiveKindStr, name, calleeIsolationStr, callerIsolationStr)
|
||||
.highlight(loc.getSourceRange());
|
||||
}
|
||||
|
||||
@@ -1623,16 +1710,23 @@ public:
|
||||
descriptiveKindStrWithSpace.push_back(' ');
|
||||
}
|
||||
}
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing.getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
if (auto callee = getSendingCallee()) {
|
||||
diagnoseNote(loc,
|
||||
diag::regionbasedisolation_named_send_never_sendable_callee,
|
||||
name, descriptiveKindStrWithSpace,
|
||||
isolationCrossing.getCalleeIsolation(), callee.value(),
|
||||
descriptiveKindStr);
|
||||
name, descriptiveKindStrWithSpace, calleeIsolationStr,
|
||||
callee.value(), descriptiveKindStr);
|
||||
} else {
|
||||
diagnoseNote(loc, diag::regionbasedisolation_named_send_never_sendable,
|
||||
name, descriptiveKindStrWithSpace,
|
||||
isolationCrossing.getCalleeIsolation(), descriptiveKindStr);
|
||||
name, descriptiveKindStrWithSpace, calleeIsolationStr,
|
||||
descriptiveKindStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2623,17 +2717,31 @@ void NonSendableIsolationCrossingResultDiagnosticEmitter::emit() {
|
||||
if (!isolationCrossing)
|
||||
return emitUnknownPatternError();
|
||||
|
||||
SmallString<64> calleeIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(calleeIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing->getCalleeIsolation(), os);
|
||||
}
|
||||
|
||||
SmallString<64> callerIsolationStr;
|
||||
{
|
||||
llvm::raw_svector_ostream os(callerIsolationStr);
|
||||
SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
isolationCrossing->getCallerIsolation(), os);
|
||||
}
|
||||
|
||||
auto type = getType();
|
||||
if (getCalledDecl()) {
|
||||
diagnoseError(error.op->getSourceInst(), diag::rbi_isolation_crossing_result,
|
||||
type, isolationCrossing->getCalleeIsolation(), getCalledDecl(),
|
||||
isolationCrossing->getCallerIsolation())
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
diagnoseError(error.op->getSourceInst(),
|
||||
diag::rbi_isolation_crossing_result, type, calleeIsolationStr,
|
||||
getCalledDecl(), callerIsolationStr)
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
} else {
|
||||
diagnoseError(error.op->getSourceInst(), diag::rbi_isolation_crossing_result_no_decl,
|
||||
type, isolationCrossing->getCalleeIsolation(),
|
||||
isolationCrossing->getCallerIsolation())
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
diagnoseError(error.op->getSourceInst(),
|
||||
diag::rbi_isolation_crossing_result_no_decl, type,
|
||||
calleeIsolationStr, callerIsolationStr)
|
||||
.limitBehaviorIf(getBehaviorLimit());
|
||||
}
|
||||
if (type->is<FunctionType>()) {
|
||||
diagnoseNote(error.op->getSourceInst(),
|
||||
|
||||
@@ -1237,6 +1237,14 @@ void SILIsolationInfo::printOptions(llvm::raw_ostream &os) const {
|
||||
llvm::interleave(data, os, ", ");
|
||||
}
|
||||
|
||||
/// We want to treat nonisolated(nonsending) just like nonisolated. So we use
|
||||
/// this with composition.
|
||||
void SILIsolationInfo::printActorIsolationForDiagnostics(
|
||||
ActorIsolation iso, llvm::raw_ostream &os, StringRef openingQuotationMark,
|
||||
bool asNoun) {
|
||||
return iso.printForDiagnostics(os, openingQuotationMark, asNoun);
|
||||
}
|
||||
|
||||
void SILIsolationInfo::print(llvm::raw_ostream &os) const {
|
||||
switch (Kind(*this)) {
|
||||
case Unknown:
|
||||
@@ -1284,7 +1292,7 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
|
||||
}
|
||||
}
|
||||
|
||||
getActorIsolation().printForDiagnostics(os);
|
||||
printActorIsolationForDiagnostics(getActorIsolation(), os);
|
||||
printOptions(os);
|
||||
return;
|
||||
case Task:
|
||||
@@ -1406,7 +1414,7 @@ void SILIsolationInfo::printForDiagnostics(llvm::raw_ostream &os) const {
|
||||
}
|
||||
}
|
||||
|
||||
getActorIsolation().printForDiagnostics(os);
|
||||
printActorIsolationForDiagnostics(getActorIsolation(), os);
|
||||
return;
|
||||
case Task:
|
||||
os << "task-isolated";
|
||||
@@ -1449,7 +1457,7 @@ void SILIsolationInfo::printForCodeDiagnostic(llvm::raw_ostream &os) const {
|
||||
}
|
||||
}
|
||||
|
||||
getActorIsolation().printForDiagnostics(os);
|
||||
printActorIsolationForDiagnostics(getActorIsolation(), os);
|
||||
os << " code";
|
||||
return;
|
||||
case Task:
|
||||
@@ -1498,7 +1506,7 @@ void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
|
||||
}
|
||||
}
|
||||
|
||||
getActorIsolation().printForDiagnostics(os);
|
||||
printActorIsolationForDiagnostics(getActorIsolation(), os);
|
||||
printOptions(os);
|
||||
return;
|
||||
case Task:
|
||||
|
||||
Reference in New Issue
Block a user