Skip to content

Commit e241344

Browse files
committed
[region-isolation] Some small gardening updates in preparation for the next commit.
Specifically, I added a few helper methods and improved the logging printing. This all makes the next commit a more focused commit. (cherry picked from commit 9bfb3b7)
1 parent de2963c commit e241344

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class ActorIsolation {
205205
return getKind() == GlobalActor;
206206
}
207207

208+
bool isActorInstanceIsolated() const { return getKind() == ActorInstance; }
209+
208210
bool isMainActor() const;
209211

210212
bool isDistributedActor() const;
@@ -262,29 +264,7 @@ class ActorIsolation {
262264
state.parameterIndex);
263265
}
264266

265-
void print(llvm::raw_ostream &os) const {
266-
switch (getKind()) {
267-
case Unspecified:
268-
os << "unspecified";
269-
return;
270-
case ActorInstance:
271-
os << "actor_instance";
272-
return;
273-
case Nonisolated:
274-
os << "nonisolated";
275-
return;
276-
case NonisolatedUnsafe:
277-
os << "nonisolated_unsafe";
278-
return;
279-
case GlobalActor:
280-
os << "global_actor";
281-
return;
282-
case Erased:
283-
os << "erased";
284-
return;
285-
}
286-
llvm_unreachable("Covered switch isn't covered?!");
287-
}
267+
void print(llvm::raw_ostream &os) const;
288268

289269
void printForDiagnostics(llvm::raw_ostream &os,
290270
StringRef openingQuotationMark = "'") const;

include/swift/SIL/SILFunction.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,17 @@ class SILFunction
15391539
return getArguments().back();
15401540
}
15411541

1542+
/// If we have an isolated argument, return that. Returns nullptr otherwise.
1543+
const SILArgument *maybeGetIsolatedArgument() const {
1544+
for (auto *arg : getArgumentsWithoutIndirectResults()) {
1545+
if (cast<SILFunctionArgument>(arg)->getKnownParameterInfo().hasOption(
1546+
SILParameterInfo::Isolated))
1547+
return arg;
1548+
}
1549+
1550+
return nullptr;
1551+
}
1552+
15421553
const SILArgument *getDynamicSelfMetadata() const {
15431554
assert(hasDynamicSelfMetadata() && "This method can only be called if the "
15441555
"SILFunction has a self-metadata parameter");

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ class regionanalysisimpl::TrackableValue {
305305
os << "\n Rep Value: " << getRepresentative();
306306
}
307307

308-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
308+
SWIFT_DEBUG_DUMP {
309+
print(llvm::dbgs());
310+
llvm::dbgs() << '\n';
311+
}
309312
};
310313

311314
class RegionAnalysis;

lib/AST/TypeCheckRequests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,33 @@ void ActorIsolation::printForDiagnostics(llvm::raw_ostream &os,
17331733
}
17341734
}
17351735

1736+
void ActorIsolation::print(llvm::raw_ostream &os) const {
1737+
switch (getKind()) {
1738+
case Unspecified:
1739+
os << "unspecified";
1740+
return;
1741+
case ActorInstance:
1742+
os << "actor_instance";
1743+
if (auto *vd = getActorInstance()) {
1744+
os << ". name: '" << vd->getBaseIdentifier() << "'";
1745+
}
1746+
return;
1747+
case Nonisolated:
1748+
os << "nonisolated";
1749+
return;
1750+
case NonisolatedUnsafe:
1751+
os << "nonisolated_unsafe";
1752+
return;
1753+
case GlobalActor:
1754+
os << "global_actor. type: " << getGlobalActor();
1755+
return;
1756+
case Erased:
1757+
os << "erased";
1758+
return;
1759+
}
1760+
llvm_unreachable("Covered switch isn't covered?!");
1761+
}
1762+
17361763
void ActorIsolation::dumpForDiagnostics() const {
17371764
printForDiagnostics(llvm::dbgs());
17381765
llvm::dbgs() << '\n';

lib/SIL/IR/SILPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,12 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
33143314
P.printDebugScopeRef(getDebugScope(), SM);
33153315
}
33163316
OS << '\n';
3317+
3318+
if (auto functionIsolation = getActorIsolation()) {
3319+
OS << "// Isolation: ";
3320+
functionIsolation.print(OS);
3321+
OS << '\n';
3322+
}
33173323
printClangQualifiedNameCommentIfPresent(OS, getClangDecl());
33183324

33193325
OS << "sil ";

lib/SILOptimizer/Utils/PartitionUtils.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,26 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
398398
os << "disconnected";
399399
return;
400400
case Actor:
401-
os << "actor";
401+
if (SILValue instance = getActorInstance()) {
402+
if (auto name = VariableNameInferrer::inferName(instance)) {
403+
os << "'" << *name << "'-isolated\n";
404+
os << "instance: " << *instance;
405+
return;
406+
}
407+
}
408+
409+
if (getActorIsolation().getKind() == ActorIsolation::ActorInstance) {
410+
if (auto *vd = getActorIsolation().getActorInstance()) {
411+
os << "'" << vd->getBaseIdentifier() << "'-isolated";
412+
return;
413+
}
414+
}
415+
416+
getActorIsolation().printForDiagnostics(os);
402417
return;
403418
case Task:
404-
os << "task";
419+
os << "task-isolated\n";
420+
os << "instance: " << *getIsolatedValue();
405421
return;
406422
}
407423
}

0 commit comments

Comments
 (0)