Skip to content

Commit 9bfb3b7

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.
1 parent 03ea6a1 commit 9bfb3b7

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
@@ -1551,6 +1551,17 @@ class SILFunction
15511551
return getArguments().back();
15521552
}
15531553

1554+
/// If we have an isolated argument, return that. Returns nullptr otherwise.
1555+
const SILArgument *maybeGetIsolatedArgument() const {
1556+
for (auto *arg : getArgumentsWithoutIndirectResults()) {
1557+
if (cast<SILFunctionArgument>(arg)->getKnownParameterInfo().hasOption(
1558+
SILParameterInfo::Isolated))
1559+
return arg;
1560+
}
1561+
1562+
return nullptr;
1563+
}
1564+
15541565
const SILArgument *getDynamicSelfMetadata() const {
15551566
assert(hasDynamicSelfMetadata() && "This method can only be called if the "
15561567
"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
@@ -3328,6 +3328,12 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
33283328
P.printDebugScopeRef(getDebugScope(), SM);
33293329
}
33303330
OS << '\n';
3331+
3332+
if (auto functionIsolation = getActorIsolation()) {
3333+
OS << "// Isolation: ";
3334+
functionIsolation.print(OS);
3335+
OS << '\n';
3336+
}
33313337
printClangQualifiedNameCommentIfPresent(OS, getClangDecl());
33323338

33333339
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)