[SE-0371] Back-deploy support for main-actor-isolated deinit

When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
This commit is contained in:
Doug Gregor
2025-06-30 17:33:36 -07:00
parent bec4ebd126
commit 7789a0ce64
9 changed files with 123 additions and 11 deletions

View File

@@ -2396,13 +2396,25 @@ FUNCTION(TaskSwitchFunc,
// size_t flags);
FUNCTION(DeinitOnExecutorFunc,
_Concurrency, swift_task_deinitOnExecutor, SwiftCC,
ConcurrencyAvailability,
IsolatedDeinitAvailability,
RETURNS(VoidTy),
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy, SizeTy),
ATTRS(NoUnwind),
EFFECT(RuntimeEffect::Concurrency),
UNKNOWN_MEMEFFECTS)
// void swift_task_deinitOnExecutorMainActorBackDeploy(void *object,
// DeinitWorkFunction *work,
// SerialExecutorRef newExecutor,
// size_t flags);
FUNCTION(DeinitOnExecutorMainActorBackDeployFunc,
_Concurrency, deinitOnExecutorMainActorBackDeploy, SwiftCC,
ConcurrencyAvailability,
RETURNS(VoidTy),
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy, SizeTy),
ATTRS(NoUnwind),
EFFECT(RuntimeEffect::Concurrency),
UNKNOWN_MEMEFFECTS)
// AsyncTask *swift_continuation_init(AsyncContext *continuationContext,
// AsyncContinuationFlags);