Skip to content

Commit c90097f

Browse files
committed
[region-isolation] Add support for *_existential_box instructions.
NOTE: I am just adding coverage that we support these instructions. One can only use this with Error today and Error is always Sendable. So this is just going for completeness.
1 parent f375f2e commit c90097f

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,11 +2434,22 @@ CONSTANT_TRANSLATION(CondBranchInst, TerminatorPhi)
24342434
CONSTANT_TRANSLATION(CheckedCastBranchInst, TerminatorPhi)
24352435
CONSTANT_TRANSLATION(DynamicMethodBranchInst, TerminatorPhi)
24362436

2437+
//===---
2438+
// Existential Box
2439+
//
2440+
2441+
// NOTE: Today these can only be used with Errors. Since Error is a sub-protocol
2442+
// of Sendable, we actually do not have any way to truly test them. These are
2443+
// just hypothetical assignments so we are complete.
2444+
CONSTANT_TRANSLATION(AllocExistentialBoxInst, AssignFresh)
2445+
CONSTANT_TRANSLATION(ProjectExistentialBoxInst, Assign)
2446+
CONSTANT_TRANSLATION(OpenExistentialBoxValueInst, Assign)
2447+
CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
2448+
24372449
//===---
24382450
// Unhandled Instructions
24392451
//
24402452

2441-
CONSTANT_TRANSLATION(AllocExistentialBoxInst, Unhandled)
24422453
CONSTANT_TRANSLATION(IndexRawPointerInst, Unhandled)
24432454
CONSTANT_TRANSLATION(UncheckedTrivialBitCastInst, Unhandled)
24442455
CONSTANT_TRANSLATION(UncheckedBitwiseCastInst, Unhandled)
@@ -2460,7 +2471,6 @@ CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, Unhandled)
24602471
CONSTANT_TRANSLATION(DropDeinitInst, Unhandled)
24612472
CONSTANT_TRANSLATION(IsUniqueInst, Unhandled)
24622473
CONSTANT_TRANSLATION(LoadUnownedInst, Unhandled)
2463-
CONSTANT_TRANSLATION(ProjectExistentialBoxInst, Unhandled)
24642474
CONSTANT_TRANSLATION(ValueMetatypeInst, Unhandled)
24652475
CONSTANT_TRANSLATION(ExistentialMetatypeInst, Unhandled)
24662476
CONSTANT_TRANSLATION(VectorInst, Unhandled)
@@ -2472,7 +2482,6 @@ CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
24722482
CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Unhandled)
24732483
CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Unhandled)
24742484
CONSTANT_TRANSLATION(OpenExistentialValueInst, Unhandled)
2475-
CONSTANT_TRANSLATION(OpenExistentialBoxValueInst, Unhandled)
24762485
CONSTANT_TRANSLATION(OpenPackElementInst, Unhandled)
24772486
CONSTANT_TRANSLATION(PackLengthInst, Unhandled)
24782487
CONSTANT_TRANSLATION(DynamicPackIndexInst, Unhandled)
@@ -2494,7 +2503,6 @@ CONSTANT_TRANSLATION(DeallocPackInst, Unhandled)
24942503
CONSTANT_TRANSLATION(DeallocStackRefInst, Unhandled)
24952504
CONSTANT_TRANSLATION(DeallocRefInst, Unhandled)
24962505
CONSTANT_TRANSLATION(DeallocPartialRefInst, Unhandled)
2497-
CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Unhandled)
24982506
CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
24992507
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
25002508
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,38 @@ sil [ossa] @mark_dependence_test_base_is_a_require : $@convention(thin) @async (
442442

443443
%9999 = tuple ()
444444
return %9999 : $()
445-
}
445+
}
446+
447+
// NOTE: Since Error is Sendable, this just validates that we handle the
448+
// instruction and don't crash.
449+
sil [ossa] @alloc_existential_box_test : $@convention(thin) @async <T : Error> (@in T) -> @owned any Error {
450+
bb0(%inError : $*T):
451+
%b = alloc_existential_box $Error, $T
452+
%p = project_existential_box $T in %b : $Error
453+
copy_addr [take] %inError to [init] %p : $*T
454+
455+
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
456+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<T>(%p) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
457+
458+
return %b : $Error
459+
}
460+
461+
sil [ossa] @alloc_existential_box_test_2 : $@convention(thin) @async <T : Error> (@in T) -> () {
462+
bb0(%inError : $*T):
463+
%b = alloc_existential_box $Error, $T
464+
%p = project_existential_box $T in %b : $Error
465+
copy_addr [take] %inError to [init] %p : $*T
466+
467+
%bb = begin_borrow %b : $Error
468+
%addr = open_existential_box %bb : $any Error to $*@opened("169A6848-B636-11EC-83C4-D0817AD59B9D", any Error) Self
469+
470+
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
471+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<@opened("169A6848-B636-11EC-83C4-D0817AD59B9D", any Error) Self>(%addr) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
472+
end_borrow %bb : $Error
473+
474+
destroy_addr %p : $*T
475+
dealloc_existential_box %b : $Error, $T
476+
477+
%9999 = tuple ()
478+
return %9999 : $()
479+
}

0 commit comments

Comments
 (0)