Skip to content

Commit 4b4583f

Browse files
committed
[region-isolation] Recognize sil_isolated parameters that are global actors as global actors rather than actor instance.
The specific example I ran into was in sendable_continuation.swift where we were passing in the @mainactor instance as a sil_isolated parameter. We were thinking it was an actor instance so we emitted the wrong message. (cherry picked from commit 0cd0868)
1 parent 7500deb commit 4b4583f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,28 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
349349
}
350350

351351
if (auto *isolatedOp = fas.getIsolatedArgumentOperandOrNullPtr()) {
352+
// First pattern match from global actors being passed as isolated
353+
// parameters. This gives us better type information. If we can pattern
354+
// match... we should!
355+
if (auto *ei = dyn_cast<EnumInst>(isolatedOp->get())) {
356+
if (ei->getElement()->getParentEnum()->isOptionalDecl() &&
357+
ei->hasOperand()) {
358+
if (auto *ieri = dyn_cast<InitExistentialRefInst>(ei->getOperand())) {
359+
CanType selfASTType = ieri->getFormalConcreteType();
360+
361+
if (auto *nomDecl = selfASTType->getAnyActor()) {
362+
// The SILValue() parameter doesn't matter until we have isolation
363+
// history.
364+
if (nomDecl->isGlobalActor())
365+
return SILIsolationInfo::getGlobalActorIsolated(SILValue(),
366+
nomDecl);
367+
}
368+
}
369+
}
370+
}
371+
372+
// If we did not find an AST type, just see if we can find a value by
373+
// looking through all optional types. This is conservatively correct.
352374
CanType selfASTType = isolatedOp->get()->getType().getASTType();
353375
selfASTType =
354376
selfASTType->lookThroughAllOptionalTypes()->getCanonicalType();

0 commit comments

Comments
 (0)