Skip to content

Commit f6d7983

Browse files
committed
[region-isolation] Add support for ref_to_unowned and unowned_to_ref.
1 parent c49fb33 commit f6d7983

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
209209
case SILInstructionKind::ProjectBlockStorageInst:
210210
case SILInstructionKind::ProjectBoxInst:
211211
case SILInstructionKind::RefToBridgeObjectInst:
212+
case SILInstructionKind::RefToUnownedInst:
212213
case SILInstructionKind::UncheckedRefCastInst:
213214
case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
215+
case SILInstructionKind::UnownedToRefInst:
214216
case SILInstructionKind::UpcastInst:
215217
return true;
216218
}
@@ -2052,6 +2054,8 @@ CONSTANT_TRANSLATION(MarkUninitializedInst, LookThrough)
20522054
CONSTANT_TRANSLATION(DestructureTupleInst, LookThrough)
20532055
CONSTANT_TRANSLATION(DestructureStructInst, LookThrough)
20542056
CONSTANT_TRANSLATION(ProjectBlockStorageInst, LookThrough)
2057+
CONSTANT_TRANSLATION(RefToUnownedInst, LookThrough)
2058+
CONSTANT_TRANSLATION(UnownedToRefInst, LookThrough)
20552059

20562060
//===---
20572061
// Store
@@ -2138,8 +2142,6 @@ CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
21382142
// Unhandled Instructions
21392143
//
21402144

2141-
CONSTANT_TRANSLATION(RefToUnownedInst, Unhandled)
2142-
CONSTANT_TRANSLATION(UnownedToRefInst, Unhandled)
21432145
CONSTANT_TRANSLATION(BridgeObjectToWordInst, Unhandled)
21442146
CONSTANT_TRANSLATION(ObjCToThickMetatypeInst, Unhandled)
21452147
CONSTANT_TRANSLATION(ObjCMetatypeToObjectInst, Unhandled)

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,4 +815,20 @@ bb0:
815815
destroy_value %value : $SendableKlass
816816
%9999 = tuple ()
817817
return %9999 : $()
818+
}
819+
820+
sil [ossa] @ref_to_unowned_test_1 : $@convention(thin) @async () -> () {
821+
bb0:
822+
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
823+
%value = apply %constructFn() : $@convention(thin) () -> @owned NonSendableKlass
824+
825+
%unowned = ref_to_unowned %value : $NonSendableKlass to $@sil_unowned NonSendableKlass
826+
%ref = unowned_to_ref %unowned : $@sil_unowned NonSendableKlass to $NonSendableKlass
827+
%refCopy = copy_value %ref : $NonSendableKlass
828+
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
829+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%refCopy) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
830+
destroy_value %refCopy : $NonSendableKlass
831+
destroy_value %value : $NonSendableKlass
832+
%9999 = tuple ()
833+
return %9999 : $()
818834
}

0 commit comments

Comments
 (0)