Skip to content

Commit d10346b

Browse files
committed
[region-isolation] Add support for unowned_copy_value.
1 parent dadc16b commit d10346b

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
212212
case SILInstructionKind::RefToUnownedInst:
213213
case SILInstructionKind::UncheckedRefCastInst:
214214
case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
215+
case SILInstructionKind::UnownedCopyValueInst:
215216
case SILInstructionKind::UnownedToRefInst:
216217
case SILInstructionKind::UpcastInst:
217218
return true;
@@ -2056,6 +2057,7 @@ CONSTANT_TRANSLATION(DestructureStructInst, LookThrough)
20562057
CONSTANT_TRANSLATION(ProjectBlockStorageInst, LookThrough)
20572058
CONSTANT_TRANSLATION(RefToUnownedInst, LookThrough)
20582059
CONSTANT_TRANSLATION(UnownedToRefInst, LookThrough)
2060+
CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
20592061

20602062
//===---
20612063
// Store
@@ -2149,7 +2151,6 @@ CONSTANT_TRANSLATION(ObjCToThickMetatypeInst, Unhandled)
21492151
CONSTANT_TRANSLATION(ObjCMetatypeToObjectInst, Unhandled)
21502152
CONSTANT_TRANSLATION(ObjCExistentialMetatypeToObjectInst, Unhandled)
21512153
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, Unhandled)
2152-
CONSTANT_TRANSLATION(UnownedCopyValueInst, Unhandled)
21532154
CONSTANT_TRANSLATION(WeakCopyValueInst, Unhandled)
21542155
CONSTANT_TRANSLATION(StrongCopyWeakValueInst, Unhandled)
21552156
CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, Unhandled)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: %target-sil-opt -transfer-non-sendable -enable-sil-opaque-values -enable-experimental-feature RegionBasedIsolation -strict-concurrency=complete %s -verify
2+
3+
// PLEASE READ THIS!
4+
//
5+
// This test is specifically to test out individual instruction interactions,
6+
// not for crashers. The idea is to make it so that we have one test for every
7+
// SIL instruction, so please add a test here when you add a new instruction.
8+
//
9+
// For assign/lookthrough, just add a test that triggers an ownership error. If it is
10+
// a more complex instruction, talk with @gottesmm.
11+
12+
sil_stage raw
13+
14+
import Swift
15+
import Builtin
16+
17+
class NonSendableKlass {}
18+
19+
final class SendableKlass : Sendable {}
20+
21+
@_moveOnly
22+
struct NonSendableMoveOnlyStruct {
23+
var ns: NonSendableKlass
24+
}
25+
26+
struct NonSendableStruct {
27+
var ns: NonSendableKlass
28+
}
29+
30+
sil @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
31+
sil @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
32+
33+
sil @transferSendableKlass : $@convention(thin) @async (@guaranteed SendableKlass) -> ()
34+
sil @constructSendableKlass : $@convention(thin) () -> @owned SendableKlass
35+
36+
sil @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
37+
sil @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
38+
sil @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
39+
40+
sil @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
41+
sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
42+
43+
sil @constructMoveOnlyStruct : $@convention(thin) () -> @owned NonSendableMoveOnlyStruct
44+
45+
enum FakeOptional<T> {
46+
case none
47+
case some(T)
48+
}
49+
50+
/////////////////
51+
// MARK: Tests //
52+
/////////////////
53+
54+
sil [ossa] @test_unowned_copy_value : $@convention(thin) @async <T where T : AnyObject> (@owned T) -> () {
55+
bb0(%owned_value : @owned $T):
56+
%unowned_value = unowned_copy_value %owned_value : $T
57+
58+
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
59+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<@sil_unowned T>(%unowned_value) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
60+
61+
destroy_value %unowned_value : $@sil_unowned T
62+
//destroy_value %value : $T
63+
destroy_value %owned_value : $T
64+
65+
%9999 = tuple ()
66+
return %9999 : $()
67+
}

0 commit comments

Comments
 (0)