Skip to content

Commit 067dbad

Browse files
committed
[region-isolation] Add a print command that emits errors of the form "*-isolated code" or "code in the current task"
This makes it so that one does not need to deal with the differences in text in between the task isolated case and the actor isolated case. This is done by swallowing the entire part of this message in one method rather than having the caller do the work.
1 parent 2b150bf commit 067dbad

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

include/swift/SILOptimizer/Utils/SILIsolationInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ class SILIsolationInfo {
291291
llvm::dbgs() << '\n';
292292
}
293293

294+
/// Prints out the message for a diagnostic that states that the value is
295+
/// exposed to a specific code.
296+
///
297+
/// We do this programatically since task-isolated code needs a very different
298+
/// form of diagnostic than other cases.
299+
void printForCodeDiagnostic(llvm::raw_ostream &os) const;
300+
294301
void printForDiagnostics(llvm::raw_ostream &os) const;
295302

296303
SWIFT_DEBUG_DUMPER(dumpForDiagnostics()) {
@@ -525,6 +532,10 @@ class SILDynamicMergedIsolationInfo {
525532
innerInfo.dumpForDiagnostics();
526533
}
527534

535+
void printForCodeDiagnostic(llvm::raw_ostream &os) const {
536+
innerInfo.printForCodeDiagnostic(os);
537+
}
538+
528539
void printForOneLineLogging(llvm::raw_ostream &os) const {
529540
innerInfo.printForOneLineLogging(os);
530541
}

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,50 @@ void SILIsolationInfo::printForDiagnostics(llvm::raw_ostream &os) const {
11171117
}
11181118
}
11191119

1120+
void SILIsolationInfo::printForCodeDiagnostic(llvm::raw_ostream &os) const {
1121+
switch (Kind(*this)) {
1122+
case Unknown:
1123+
llvm::report_fatal_error("Printing unknown for code diagnostic?!");
1124+
return;
1125+
case Disconnected:
1126+
llvm::report_fatal_error("Printing disconnected for code diagnostic?!");
1127+
return;
1128+
case Actor:
1129+
if (auto instance = getActorInstance()) {
1130+
switch (instance.getKind()) {
1131+
case ActorInstance::Kind::Value: {
1132+
SILValue value = instance.getValue();
1133+
if (auto name = VariableNameInferrer::inferName(value)) {
1134+
os << "'" << *name << "'-isolated code";
1135+
return;
1136+
}
1137+
break;
1138+
}
1139+
case ActorInstance::Kind::ActorAccessorInit:
1140+
os << "'self'-isolated code";
1141+
return;
1142+
case ActorInstance::Kind::CapturedActorSelf:
1143+
os << "'self'-isolated code";
1144+
return;
1145+
}
1146+
}
1147+
1148+
if (getActorIsolation().getKind() == ActorIsolation::ActorInstance) {
1149+
if (auto *vd = getActorIsolation().getActorInstance()) {
1150+
os << "'" << vd->getBaseIdentifier() << "'-isolated code";
1151+
return;
1152+
}
1153+
}
1154+
1155+
getActorIsolation().printForDiagnostics(os);
1156+
os << " code";
1157+
return;
1158+
case Task:
1159+
os << "code in the current task";
1160+
return;
1161+
}
1162+
}
1163+
11201164
void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
11211165
switch (Kind(*this)) {
11221166
case Unknown:

0 commit comments

Comments
 (0)