Skip to content

Commit 4946256

Browse files
authored
Merge pull request #85064 from gottesmm/pr-a4b0eaddab3318c277ebf3a9080a8bcfc79a3ba6
[rbi] Prefer field specific isolation over nominal type isolation when inferring isolation.
2 parents 7648833 + c14e4b0 commit 4946256

File tree

3 files changed

+381
-0
lines changed

3 files changed

+381
-0
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,16 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
601601
if (auto *rei = dyn_cast<RefElementAddrInst>(inst)) {
602602
auto varIsolation = swift::getActorIsolation(rei->getField());
603603

604+
// If we have a global actor isolated field, then we know that we override
605+
// the actual isolation of the actor or global actor isolated class with
606+
// some other form of isolation. In such a case, we need to use that
607+
// isolation instead.
608+
if (varIsolation.isGlobalActor()) {
609+
return SILIsolationInfo::getGlobalActorIsolated(
610+
rei, varIsolation.getGlobalActor())
611+
.withUnsafeNonIsolated(varIsolation.isNonisolatedUnsafe());
612+
}
613+
604614
if (auto instance = ActorInstance::getForValue(rei->getOperand())) {
605615
if (auto *fArg = llvm::dyn_cast_or_null<SILFunctionArgument>(
606616
instance.maybeGetValue())) {
@@ -812,6 +822,16 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
812822
// See if we have a struct_extract from a global-actor-isolated type.
813823
if (auto *sei = dyn_cast<StructExtractInst>(inst)) {
814824
auto varIsolation = swift::getActorIsolation(sei->getField());
825+
826+
// If our var is global actor isolated, then we override the isolation of
827+
// whatever our struct was with a specific isolation on the struct
828+
// itself. We should use that instead.
829+
if (varIsolation.isGlobalActor()) {
830+
return SILIsolationInfo::getGlobalActorIsolated(
831+
sei, varIsolation.getGlobalActor())
832+
.withUnsafeNonIsolated(varIsolation.isNonisolatedUnsafe());
833+
}
834+
815835
if (auto isolation =
816836
SILIsolationInfo::getGlobalActorIsolated(sei, sei->getStructDecl()))
817837
return isolation.withUnsafeNonIsolated(
@@ -822,6 +842,16 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
822842

823843
if (auto *seai = dyn_cast<StructElementAddrInst>(inst)) {
824844
auto varIsolation = swift::getActorIsolation(seai->getField());
845+
846+
// If our var is global actor isolated, then we override the isolation of
847+
// whatever our struct was with a specific isolation on the struct
848+
// itself. We should use that instead.
849+
if (varIsolation.isGlobalActor()) {
850+
return SILIsolationInfo::getGlobalActorIsolated(
851+
seai, varIsolation.getGlobalActor())
852+
.withUnsafeNonIsolated(varIsolation.isNonisolatedUnsafe());
853+
}
854+
825855
if (auto isolation = SILIsolationInfo::getGlobalActorIsolated(
826856
seai, seai->getStructDecl()))
827857
return isolation.withUnsafeNonIsolated(

0 commit comments

Comments
 (0)