mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Rename performOnExecutor into deinitOnExecutor.
It cannot be used for executing general-purpose work, because such function would need to have a different signature to pass isolated actor instance. And being explicit about using this method only for deinit allows to use object pointer for comparison with executor identity.
This commit is contained in:
@@ -291,7 +291,7 @@ using ThrowingTaskFutureWaitContinuationFunction =
|
||||
SWIFT_CC(swiftasync)
|
||||
void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT void *);
|
||||
|
||||
using AdHocWorkFunction = SWIFT_CC(swift) void(void *);
|
||||
using DeinitWorkFunction = SWIFT_CC(swift) void(void *);
|
||||
|
||||
template <class AsyncSignature>
|
||||
class AsyncFunctionPointer;
|
||||
|
||||
@@ -2491,7 +2491,7 @@ enum class JobKind : size_t {
|
||||
DefaultActorSeparate,
|
||||
DefaultActorOverride,
|
||||
NullaryContinuation,
|
||||
AdHoc,
|
||||
IsolatedDeinit,
|
||||
};
|
||||
|
||||
/// The priority of a job. Higher priorities are larger values.
|
||||
|
||||
@@ -607,7 +607,7 @@ swift_task_createNullaryContinuationJob(
|
||||
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency)
|
||||
SWIFT_CC(swift)
|
||||
void swift_task_performOnExecutor(void *context, AdHocWorkFunction *work,
|
||||
void swift_task_deinitOnExecutor(void *object, DeinitWorkFunction *work,
|
||||
SerialExecutorRef newExecutor);
|
||||
|
||||
/// Report error about attempting to bind a task-local value from an illegal context.
|
||||
|
||||
@@ -2333,11 +2333,11 @@ FUNCTION(TaskSwitchFunc,
|
||||
EFFECT(Concurrency),
|
||||
UNKNOWN_MEMEFFECTS)
|
||||
|
||||
// void swift_task_performOnExecutor(void *context,
|
||||
// AdHocWorkFunction *work,
|
||||
// void swift_task_deinitOnExecutor(void *object,
|
||||
// DeinitWorkFunction *work,
|
||||
// SerialExecutorRef newExecutor);
|
||||
FUNCTION(PerformOnExecutorFunc,
|
||||
swift_task_performOnExecutor, SwiftCC,
|
||||
FUNCTION(DeinitOnExecutorFunc,
|
||||
swift_task_deinitOnExecutor, SwiftCC,
|
||||
ConcurrencyAvailability,
|
||||
RETURNS(VoidTy),
|
||||
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy),
|
||||
|
||||
@@ -448,8 +448,8 @@ FuncDecl *SILGenModule::getSwiftJobRun() {
|
||||
return lookupConcurrencyIntrinsic(getASTContext(), "_swiftJobRun");
|
||||
}
|
||||
|
||||
FuncDecl *SILGenModule::getPerformOnExecutor() {
|
||||
return lookupConcurrencyIntrinsic(getASTContext(), "_performOnExecutor");
|
||||
FuncDecl *SILGenModule::getDeinitOnExecutor() {
|
||||
return lookupConcurrencyIntrinsic(getASTContext(), "_deinitOnExecutor");
|
||||
}
|
||||
|
||||
FuncDecl *SILGenModule::getExit() {
|
||||
|
||||
@@ -552,8 +552,8 @@ public:
|
||||
FuncDecl *getAsyncMainDrainQueue();
|
||||
/// Retrieve the _Concurrency._swiftJobRun intrinsic.
|
||||
FuncDecl *getSwiftJobRun();
|
||||
/// Retrieve the _Concurrency._performOnExecutor intrinsic.
|
||||
FuncDecl *getPerformOnExecutor();
|
||||
/// Retrieve the _Concurrency._deinitOnExecutor intrinsic.
|
||||
FuncDecl *getDeinitOnExecutor();
|
||||
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.
|
||||
FuncDecl *getExit();
|
||||
|
||||
|
||||
@@ -371,15 +371,15 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
|
||||
executor = B.createExtractExecutor(loc, actor);
|
||||
}
|
||||
|
||||
// Get performOnExecutor
|
||||
FuncDecl *swiftPerformOnExecutorDecl = SGM.getPerformOnExecutor();
|
||||
assert(swiftPerformOnExecutorDecl &&
|
||||
"Failed to find swift_task_performOnExecutor function decl");
|
||||
SILFunction *swiftPerformOnExecutorSILFunc = SGM.getFunction(
|
||||
SILDeclRef(swiftPerformOnExecutorDecl, SILDeclRef::Kind::Func),
|
||||
// Get deinitOnExecutor
|
||||
FuncDecl *swiftDeinitOnExecutorDecl = SGM.getDeinitOnExecutor();
|
||||
assert(swiftDeinitOnExecutorDecl &&
|
||||
"Failed to find swift_task_deinitOnExecutor function decl");
|
||||
SILFunction *swiftDeinitOnExecutorSILFunc = SGM.getFunction(
|
||||
SILDeclRef(swiftDeinitOnExecutorDecl, SILDeclRef::Kind::Func),
|
||||
NotForDefinition);
|
||||
SILValue swiftPerformOnExecutorFunc =
|
||||
B.createFunctionRefFor(loc, swiftPerformOnExecutorSILFunc);
|
||||
SILValue swiftDeinitOnExecutorFunc =
|
||||
B.createFunctionRefFor(loc, swiftDeinitOnExecutorSILFunc);
|
||||
|
||||
// Cast self to AnyObject preserving owned ownership
|
||||
CanType selfType = selfValue->getType().getASTType();
|
||||
@@ -408,7 +408,7 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
|
||||
B.createConvertFunction(loc, dtx, workFuncType, false);
|
||||
|
||||
// Schedule isolated execution
|
||||
B.createApply(loc, swiftPerformOnExecutorFunc, {},
|
||||
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
|
||||
{castedSelf, castedDeallocator, executor});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,10 +142,10 @@ OVERRIDE_ACTOR(task_switch, void,
|
||||
TaskContinuationFunction *resumeFunction, SerialExecutorRef newExecutor),
|
||||
(resumeToContext, resumeFunction, newExecutor))
|
||||
|
||||
OVERRIDE_ACTOR(task_performOnExecutor, void,
|
||||
OVERRIDE_ACTOR(task_deinitOnExecutor, void,
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
|
||||
(void *context, AdHocWorkFunction *work, SerialExecutorRef newExecutor),
|
||||
(context, work, newExecutor))
|
||||
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor),
|
||||
(object, work, newExecutor))
|
||||
|
||||
OVERRIDE_TASK(task_create_common, AsyncTaskAndContext,
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
|
||||
|
||||
@@ -2143,34 +2143,35 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
|
||||
namespace {
|
||||
/// Job that allows to use executor API to schedule a block of task-less
|
||||
/// synchronous code.
|
||||
class AdHocJob : public Job {
|
||||
class IsolatedDeinitJob : public Job {
|
||||
private:
|
||||
void *Context;
|
||||
AdHocWorkFunction *Work;
|
||||
void *Object;
|
||||
DeinitWorkFunction *Work;
|
||||
|
||||
public:
|
||||
AdHocJob(JobPriority priority, void *context, AdHocWorkFunction *work)
|
||||
: Job({JobKind::AdHoc, priority}, &process), Context(context),
|
||||
IsolatedDeinitJob(JobPriority priority, void *object,
|
||||
DeinitWorkFunction *work)
|
||||
: Job({JobKind::IsolatedDeinit, priority}, &process), Object(object),
|
||||
Work(work) {}
|
||||
|
||||
SWIFT_CC(swiftasync)
|
||||
static void process(Job *_job) {
|
||||
auto *job = cast<AdHocJob>(_job);
|
||||
void *ctx = job->Context;
|
||||
AdHocWorkFunction *work = job->Work;
|
||||
auto *job = cast<IsolatedDeinitJob>(_job);
|
||||
void *object = job->Object;
|
||||
DeinitWorkFunction *work = job->Work;
|
||||
delete job;
|
||||
return work(ctx);
|
||||
return work(object);
|
||||
}
|
||||
|
||||
static bool classof(const Job *job) {
|
||||
return job->Flags.getKind() == JobKind::AdHoc;
|
||||
return job->Flags.getKind() == JobKind::IsolatedDeinit;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
SWIFT_CC(swift)
|
||||
static void swift_task_performOnExecutorImpl(void *context,
|
||||
AdHocWorkFunction *work,
|
||||
static void swift_task_deinitOnExecutorImpl(void *object,
|
||||
DeinitWorkFunction *work,
|
||||
SerialExecutorRef newExecutor) {
|
||||
// If the current executor is compatible with running the new executor,
|
||||
// we can just immediately continue running with the resume function
|
||||
@@ -2179,11 +2180,11 @@ static void swift_task_performOnExecutorImpl(void *context,
|
||||
// Note that swift_task_isCurrentExecutor() returns true for @MainActor
|
||||
// when running on the main thread without any executor
|
||||
if (swift_task_isCurrentExecutor(newExecutor)) {
|
||||
return work(context); // 'return' forces tail call
|
||||
return work(object); // 'return' forces tail call
|
||||
}
|
||||
|
||||
// Optimize deallocation of the default actors
|
||||
if (context == newExecutor.getIdentity() && newExecutor.isDefaultActor()) {
|
||||
if (newExecutor.isDefaultActor() && object == newExecutor.getIdentity()) {
|
||||
// Try to take the lock. This should always succeed, unless someone is
|
||||
// running the actor using unsafe unowned reference.
|
||||
if (asImpl(newExecutor.getDefaultActor())->tryLock(false)) {
|
||||
@@ -2202,7 +2203,7 @@ static void swift_task_performOnExecutorImpl(void *context,
|
||||
trackingInfo.enterAndShadow(newExecutor, TaskExecutorRef::undefined());
|
||||
|
||||
// Run the work.
|
||||
work(context);
|
||||
work(object);
|
||||
|
||||
// `work` is a synchronous function, it cannot call swift_task_switch()
|
||||
// If it calls any synchronous API that may change executor inside
|
||||
@@ -2222,7 +2223,7 @@ static void swift_task_performOnExecutorImpl(void *context,
|
||||
auto priority = currentTask ? swift_task_currentPriority(currentTask)
|
||||
: swift_task_getCurrentThreadPriority();
|
||||
|
||||
auto job = new AdHocJob(priority, context, work);
|
||||
auto job = new IsolatedDeinitJob(priority, object, work);
|
||||
swift_task_enqueue(job, newExecutor);
|
||||
}
|
||||
|
||||
|
||||
@@ -561,8 +561,8 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
|
||||
|
||||
|
||||
@available(SwiftStdlib 5.6, *) // TODO: Clarify version
|
||||
@_silgen_name("swift_task_performOnExecutor")
|
||||
@_silgen_name("swift_task_deinitOnExecutor")
|
||||
@usableFromInline
|
||||
internal func _performOnExecutor(_ ctx: __owned AnyObject,
|
||||
internal func _deinitOnExecutor(_ object: __owned AnyObject,
|
||||
_ work: @convention(thin) (__owned AnyObject) -> Void,
|
||||
_ executor: Builtin.Executor)
|
||||
|
||||
@@ -219,7 +219,7 @@ distributed actor MyDistActorIsolated {
|
||||
// CHECK: [[LOCAL_ACTOR_DEINIT_BB]]:
|
||||
// CHECK: [[ISOLATED_REF:%[0-9]+]] = function_ref @$s14default_deinit19MyDistActorIsolatedCfZ : $@convention(thin) (@owned MyDistActorIsolated) -> ()
|
||||
// CHECK: [[EXECUTOR:%[0-9]+]] = extract_executor [[SELF]] : $MyDistActorIsolated
|
||||
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_performOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_deinitOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
// CHECK: [[SELF_AS_ANY_OBJECT:%[0-9]+]] = unchecked_bitwise_cast [[SELF]] : $MyDistActorIsolated to $AnyObject
|
||||
// CHECK: [[ISOLATED_CASTED:%[0-9]+]] = convert_function [[ISOLATED_REF]] : $@convention(thin) (@owned MyDistActorIsolated) -> () to $@convention(thin) (@owned AnyObject) -> ()
|
||||
// CHECK: [[DROP:%[0-9]+]] = apply [[PERFORM_REF]]([[SELF_AS_ANY_OBJECT]], [[ISOLATED_CASTED]], [[EXECUTOR]]) : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
@@ -355,7 +355,7 @@ actor SimpleActorIsolated {
|
||||
// CHECK: bb0([[SELF:%[0-9]+]] : $SimpleActorIsolated):
|
||||
// CHECK: [[ISOLATED_REF:%[0-9]+]] = function_ref @$s14default_deinit19SimpleActorIsolatedCfZ : $@convention(thin) (@owned SimpleActorIsolated) -> ()
|
||||
// CHECK: [[EXECUTOR:%[0-9]+]] = extract_executor [[SELF]] : $SimpleActorIsolated
|
||||
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_performOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_deinitOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
// CHECK: [[SELF_AS_ANY_OBJECT:%[0-9]+]] = unchecked_bitwise_cast [[SELF]] : $SimpleActorIsolated to $AnyObject
|
||||
// CHECK: [[ISOLATED_CASTED:%[0-9]+]] = convert_function [[ISOLATED_REF]] : $@convention(thin) (@owned SimpleActorIsolated) -> () to $@convention(thin) (@owned AnyObject) -> ()
|
||||
// CHECK: [[DROP:%[0-9]+]] = apply [[PERFORM_REF]]([[SELF_AS_ANY_OBJECT]], [[ISOLATED_CASTED]], [[EXECUTOR]]) : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
|
||||
|
||||
@@ -321,4 +321,4 @@ Added: _$ss9TaskLocalC9withValue_9operation9isolation4file4lineqd__x_qd__yYaKXES
|
||||
Added: _$ss9TaskLocalC9withValue_9operation9isolation4file4lineqd__x_qd__yYaKXEScA_pSgYiSSSutYaKlFTu
|
||||
|
||||
// isolated deinit
|
||||
Added: _swift_task_performOnExecutor
|
||||
Added: _swift_task_deinitOnExecutor
|
||||
|
||||
@@ -321,4 +321,4 @@ Added: _$ss9TaskLocalC9withValue_9operation9isolation4file4lineqd__x_qd__yYaKXES
|
||||
Added: _$ss9TaskLocalC9withValue_9operation9isolation4file4lineqd__x_qd__yYaKXEScA_pSgYiSSSutYaKlFTu
|
||||
|
||||
// isolated deinit
|
||||
Added: _swift_task_performOnExecutor
|
||||
Added: _swift_task_deinitOnExecutor
|
||||
|
||||
Reference in New Issue
Block a user