Skip to content

Commit 4a635b6

Browse files
committed
[region-isolation] Add support for fix_lifetime.
fix_lifetime just acts as a require.
1 parent 59fe82d commit 4a635b6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,8 +2370,9 @@ CONSTANT_TRANSLATION(StoreInst, Store)
23702370
CONSTANT_TRANSLATION(StoreBorrowInst, Store)
23712371
CONSTANT_TRANSLATION(StoreWeakInst, Store)
23722372

2373-
// These instructions are ignored because they cannot affect the partition
2374-
// state - they do not manipulate what region non-sendable values lie in
2373+
// These instructions are ignored because they cannot affect the region that a
2374+
// value is within or because even though they are technically a use we would
2375+
// rather emit an error on a better instruction.
23752376
CONSTANT_TRANSLATION(AllocGlobalInst, Ignored)
23762377
CONSTANT_TRANSLATION(DeallocBoxInst, Ignored)
23772378
CONSTANT_TRANSLATION(DeallocStackInst, Ignored)
@@ -2389,6 +2390,9 @@ CONSTANT_TRANSLATION(MetatypeInst, Ignored)
23892390
CONSTANT_TRANSLATION(EndApplyInst, Ignored)
23902391
CONSTANT_TRANSLATION(AbortApplyInst, Ignored)
23912392

2393+
// Instructions that only require that the region of the value be live:
2394+
CONSTANT_TRANSLATION(FixLifetimeInst, Require)
2395+
23922396
// Ignored terminators.
23932397
CONSTANT_TRANSLATION(CondFailInst, Ignored)
23942398
// Switch value inst is ignored since we only switch over integers and
@@ -2469,7 +2473,6 @@ CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
24692473
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
24702474
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)
24712475
CONSTANT_TRANSLATION(AutoreleaseValueInst, Unhandled)
2472-
CONSTANT_TRANSLATION(FixLifetimeInst, Unhandled)
24732476
CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Unhandled)
24742477
CONSTANT_TRANSLATION(EndUnpairedAccessInst, Unhandled)
24752478
CONSTANT_TRANSLATION(AssignInst, Unhandled)

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,16 @@ bb0(%0 : @owned $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for
317317
return %9999 : $()
318318
}
319319

320+
sil [ossa] @fix_lifetime_test : $@convention(thin) @async () -> () {
321+
bb0:
322+
%0 = function_ref @constructKlass : $@convention(thin) () -> @owned NonSendableKlass
323+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableKlass
324+
%2 = function_ref @transferKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
325+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
326+
// expected-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context at this call site could yield a race with accesses later in this function}}
327+
fix_lifetime %1 : $NonSendableKlass
328+
// expected-note @-1 {{access here could race}}
329+
destroy_value %1 : $NonSendableKlass
330+
%9999 = tuple ()
331+
return %9999 : $()
332+
}

0 commit comments

Comments
 (0)