Skip to content

Commit 40c1120

Browse files
committed
[region-isolation] Add support for strong_copy_weak_value.
1 parent 7d4f8c2 commit 40c1120

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
224224
case SILInstructionKind::UpcastInst:
225225
case SILInstructionKind::ValueToBridgeObjectInst:
226226
case SILInstructionKind::WeakCopyValueInst:
227+
case SILInstructionKind::StrongCopyWeakValueInst:
227228
return true;
228229
case SILInstructionKind::UnconditionalCheckedCastInst: {
229230
auto cast = SILDynamicCastInst::getAs(inst);
@@ -2344,6 +2345,7 @@ CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
23442345
CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
23452346
CONSTANT_TRANSLATION(OpenExistentialValueInst, LookThrough)
23462347
CONSTANT_TRANSLATION(WeakCopyValueInst, LookThrough)
2348+
CONSTANT_TRANSLATION(StrongCopyWeakValueInst, LookThrough)
23472349

23482350
//===---
23492351
// Store
@@ -2475,7 +2477,6 @@ CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
24752477
// Unhandled Instructions
24762478
//
24772479

2478-
CONSTANT_TRANSLATION(StrongCopyWeakValueInst, Unhandled)
24792480
CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, Unhandled)
24802481
CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
24812482

test/Concurrency/transfernonsendable_instruction_matching_opaquevalues.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ sil @initPAnyObject : $@convention(thin) () -> @owned PAnyObject
6565
sil @initPAnyObjectOptional : $@convention(thin) () -> @owned Optional<PAnyObject>
6666
sil @transferPAnyObject : $@async @convention(thin) (@guaranteed PAnyObject) -> ()
6767
sil @usePAnyObjectWeak : $@convention(thin) (@guaranteed @sil_weak Optional<PAnyObject>) -> ()
68+
sil @usePAnyObject : $@convention(thin) (@guaranteed Optional<PAnyObject>) -> ()
6869

6970
/////////////////
7071
// MARK: Tests //
@@ -147,3 +148,27 @@ bb0:
147148
%9999 = tuple ()
148149
return %9999 : $()
149150
}
151+
152+
sil [ossa] @strong_copy_weak_value_test : $@async @convention(thin) () -> () {
153+
bb0:
154+
%f = function_ref @initPAnyObjectOptional : $@convention(thin) () -> @owned Optional<PAnyObject>
155+
%p = apply %f() : $@convention(thin) () -> @owned Optional<PAnyObject>
156+
157+
%pBorrowed = begin_borrow %p : $Optional<PAnyObject>
158+
%pExt = unchecked_enum_data %pBorrowed : $Optional<PAnyObject>, #Optional.some!enumelt
159+
%transferP = function_ref @transferPAnyObject : $@async @convention(thin) (@guaranteed PAnyObject) -> ()
160+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferP(%pExt) : $@async @convention(thin) (@guaranteed PAnyObject) -> () // expected-warning {{transferring value of non-Sendable type 'any PAnyObject' from nonisolated context to global actor '<null>'-isolated context}}
161+
162+
%w = weak_copy_value %pBorrowed : $Optional<PAnyObject>
163+
%s = strong_copy_weak_value %w : $@sil_weak Optional<PAnyObject>
164+
%weakFunc = function_ref @usePAnyObject : $@convention(thin) (@guaranteed Optional<PAnyObject>) -> ()
165+
apply %weakFunc(%s) : $@convention(thin) (@guaranteed Optional<PAnyObject>) -> () // expected-note {{access here could race}}
166+
destroy_value %s : $Optional<PAnyObject>
167+
destroy_value %w : $@sil_weak Optional<PAnyObject>
168+
169+
end_borrow %pBorrowed : $Optional<PAnyObject>
170+
destroy_value %p : $Optional<PAnyObject>
171+
172+
%9999 = tuple ()
173+
return %9999 : $()
174+
}

0 commit comments

Comments
 (0)