Skip to content

Commit 7d13d27

Browse files
committed
[region-isolation] Add support for init_existential_value.
1 parent 9b686f5 commit 7d13d27

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
228228
case SILInstructionKind::StrongCopyUnmanagedValueInst:
229229
case SILInstructionKind::RefToUnmanagedInst:
230230
case SILInstructionKind::UnmanagedToRefInst:
231+
case SILInstructionKind::InitExistentialValueInst:
231232
return true;
232233
case SILInstructionKind::UnconditionalCheckedCastInst: {
233234
auto cast = SILDynamicCastInst::getAs(inst);
@@ -2350,6 +2351,7 @@ CONSTANT_TRANSLATION(StrongCopyWeakValueInst, LookThrough)
23502351
CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, LookThrough)
23512352
CONSTANT_TRANSLATION(RefToUnmanagedInst, LookThrough)
23522353
CONSTANT_TRANSLATION(UnmanagedToRefInst, LookThrough)
2354+
CONSTANT_TRANSLATION(InitExistentialValueInst, LookThrough)
23532355

23542356
//===---
23552357
// Store
@@ -2477,12 +2479,6 @@ CONSTANT_TRANSLATION(ProjectExistentialBoxInst, Assign)
24772479
CONSTANT_TRANSLATION(OpenExistentialBoxValueInst, Assign)
24782480
CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
24792481

2480-
//===---
2481-
// Unhandled Instructions
2482-
//
2483-
2484-
CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
2485-
24862482
//===---
24872483
// Differentiable
24882484
//

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,4 +1626,4 @@ bb0:
16261626

16271627
%9999 = tuple ()
16281628
return %9999 : $()
1629-
}
1629+
}

test/Concurrency/transfernonsendable_instruction_matching_opaquevalues.sil

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sil @constructSendableKlass : $@convention(thin) () -> @owned SendableKlass
3939

4040
sil @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
4141
sil @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
42-
sil @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
42+
sil @initNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
4343

4444
sil @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
4545
sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
@@ -58,6 +58,7 @@ protocol P {
5858

5959
sil @initP : $@convention(thin) () -> @owned P
6060
sil @transferP : $@async @convention(thin) (@guaranteed P) -> ()
61+
sil @useP : $@convention(thin) (@in_guaranteed P) -> ()
6162

6263
protocol PAnyObject : AnyObject {}
6364

@@ -67,6 +68,10 @@ sil @transferPAnyObject : $@async @convention(thin) (@guaranteed PAnyObject) ->
6768
sil @usePAnyObjectWeak : $@convention(thin) (@guaranteed @sil_weak Optional<PAnyObject>) -> ()
6869
sil @usePAnyObject : $@convention(thin) (@guaranteed Optional<PAnyObject>) -> ()
6970

71+
extension NonSendableKlass : P {
72+
func doSomething()
73+
}
74+
7075
/////////////////
7176
// MARK: Tests //
7277
/////////////////
@@ -172,3 +177,21 @@ bb0:
172177
%9999 = tuple ()
173178
return %9999 : $()
174179
}
180+
181+
sil [ossa] @test_init_existential_value : $@async @convention(thin) () -> () {
182+
bb0:
183+
%f = function_ref @initNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
184+
%1 = apply %f() : $@convention(thin) () -> @owned NonSendableKlass
185+
186+
%2 = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
187+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
188+
// expected-warning @-1 {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
189+
190+
%i = init_existential_value %1 : $NonSendableKlass, $NonSendableKlass, $P
191+
%f2 = function_ref @useP : $@convention(thin) (@in_guaranteed P) -> ()
192+
apply %f2(%i) : $@convention(thin) (@in_guaranteed P) -> () // expected-note {{access here could race}}
193+
destroy_value %i : $P
194+
195+
%9999 = tuple ()
196+
return %9999 : $()
197+
}

0 commit comments

Comments
 (0)