Skip to content

Commit 88d420f

Browse files
authored
Merge pull request #74321 from gottesmm/pr-5b09ff36784666ef5fde4abfcfbe138bf6135412
[region-isolation] Dont crash when processing global actor isolated init accessors.
2 parents 28af977 + f035590 commit 88d420f

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -813,26 +813,31 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
813813
}
814814
}
815815

816-
// Otherwise, see if we have an allocator decl ref. If we do and we have an
817-
// actor instance isolation, then we know that we are actively just calling
818-
// the initializer. To just make region isolation work, treat this as
819-
// disconnected so we can construct the actor value. Users cannot write
820-
// allocator functions so we just need to worry about compiler generated
821-
// code. In the case of a non-actor, we can only have an allocator that is
822-
// global actor isolated, so we will never hit this code path.
816+
// Otherwise, see if we need to handle this isolation computation specially
817+
// due to information from the decl ref if we have one.
823818
if (auto declRef = fArg->getFunction()->getDeclRef()) {
819+
// First check if we have an allocator decl ref. If we do and we have an
820+
// actor instance isolation, then we know that we are actively just calling
821+
// the initializer. To just make region isolation work, treat this as
822+
// disconnected so we can construct the actor value. Users cannot write
823+
// allocator functions so we just need to worry about compiler generated
824+
// code. In the case of a non-actor, we can only have an allocator that is
825+
// global actor isolated, so we will never hit this code path.
824826
if (declRef.kind == SILDeclRef::Kind::Allocator) {
825827
if (fArg->getFunction()->getActorIsolation().isActorInstanceIsolated()) {
826828
return SILIsolationInfo::getDisconnected(false /*nonisolated(unsafe)*/);
827829
}
828830
}
829831

832+
// Then see if we have an init accessor that is isolated to an actor
833+
// instance, but for which we have not actually passed self. In such a case,
834+
// we need to pass in a "fake" ActorInstance that users know is a sentinel
835+
// for the self value.
830836
if (auto functionIsolation = fArg->getFunction()->getActorIsolation()) {
831-
if (declRef.getDecl()) {
837+
if (functionIsolation.isActorInstanceIsolated() && declRef.getDecl()) {
832838
if (auto *accessor =
833839
dyn_cast_or_null<AccessorDecl>(declRef.getFuncDecl())) {
834840
if (accessor->isInitAccessor()) {
835-
assert(functionIsolation.isActorInstanceIsolated());
836841
return SILIsolationInfo::getActorInstanceIsolated(
837842
fArg, ActorInstance::getForActorAccessorInit(),
838843
functionIsolation.getActor());

test/Concurrency/transfernonsendable.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,19 @@ func initAccessorTests() {
16881688
get { fatalError() }
16891689
set { fatalError() }
16901690
}
1691+
1692+
@MainActor
1693+
var third: NonSendableKlass
1694+
@MainActor
1695+
var fourth: NonSendableKlass? = nil {
1696+
@storageRestrictions(initializes: third)
1697+
init(initialValue) {
1698+
third = initialValue!
1699+
}
1700+
1701+
get { fatalError() }
1702+
set { fatalError() }
1703+
}
16911704
}
16921705
}
16931706

0 commit comments

Comments
 (0)