Skip to content

Commit 1bcf094

Browse files
authored
Merge pull request #74530 from gottesmm/release/6.0-rdar129975097
[6.0][region-isolation] Check if we have a self param before attempting to get the self type.
2 parents 43d0b83 + 976e944 commit 1bcf094

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,16 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
538538
//
539539
auto *func = fri->getReferencedFunction();
540540
auto funcType = func->getLoweredFunctionType();
541-
auto selfParam = funcType->getSelfInstanceType(
542-
fri->getModule(), func->getTypeExpansionContext());
543-
if (auto *nomDecl = selfParam->getNominalOrBoundGenericNominal()) {
544-
auto isolation = swift::getActorIsolation(nomDecl);
545-
if (isolation.isGlobalActor()) {
546-
return SILIsolationInfo::getGlobalActorIsolated(
547-
fri, isolation.getGlobalActor())
541+
if (funcType->hasSelfParam()) {
542+
auto selfParam = funcType->getSelfInstanceType(
543+
fri->getModule(), func->getTypeExpansionContext());
544+
if (auto *nomDecl = selfParam->getNominalOrBoundGenericNominal()) {
545+
auto isolation = swift::getActorIsolation(nomDecl);
546+
if (isolation.isGlobalActor()) {
547+
return SILIsolationInfo::getGlobalActorIsolated(
548+
fri, isolation.getGlobalActor())
548549
.withUnsafeNonIsolated(true);
550+
}
549551
}
550552
}
551553
}

test/Concurrency/transfernonsendable_nonisolatedunsafe.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ protocol ProvidesStaticValue {
3030
@MainActor func transferToMainIndirectConsuming<T>(_ t: consuming T) async {}
3131
@MainActor func transferToMainDirectConsuming(_ t: consuming NonSendableKlass) async {}
3232

33+
func useInOut<T>(_ t: inout T) {}
34+
3335
actor CustomActorInstance {}
3436

3537
@globalActor
@@ -349,13 +351,28 @@ func testAccessStaticGlobals() async {
349351
nonisolated(unsafe) let globalNonIsolatedUnsafeLetObject = NonSendableKlass()
350352
nonisolated(unsafe) var globalNonIsolatedUnsafeVarObject = NonSendableKlass()
351353

352-
func testAccessGlobals() async {
354+
func testPassGlobalToMainActorIsolatedFunction() async {
353355
await transferToMainDirect(globalNonIsolatedUnsafeLetObject)
354356
await transferToMainIndirect(globalNonIsolatedUnsafeLetObject)
355357
await transferToMainDirect(globalNonIsolatedUnsafeVarObject)
356358
await transferToMainIndirect(globalNonIsolatedUnsafeVarObject)
357359
}
358360

361+
// We use this to force the modify in testPassGlobalToModify
362+
nonisolated(unsafe)
363+
var computedGlobalNonIsolatedUnsafeVarObject : NonSendableKlass {
364+
_read {
365+
yield globalNonIsolatedUnsafeVarObject
366+
}
367+
_modify {
368+
yield &globalNonIsolatedUnsafeVarObject
369+
}
370+
}
371+
372+
func testPassGlobalToModify() async {
373+
useInOut(&computedGlobalNonIsolatedUnsafeVarObject)
374+
}
375+
359376
///////////////////////
360377
// MARK: Field Tests //
361378
///////////////////////

0 commit comments

Comments
 (0)