Skip to content

Commit a6e7247

Browse files
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.
1 parent 936b330 commit a6e7247

File tree

11 files changed

+47
-47
lines changed

11 files changed

+47
-47
lines changed

include/swift/ABI/Executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ using ThrowingTaskFutureWaitContinuationFunction =
147147
SWIFT_CC(swiftasync)
148148
void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT void *);
149149

150-
using AdHocWorkFunction = SWIFT_CC(swift) void(void *);
150+
using DeinitWorkFunction = SWIFT_CC(swift) void(void *);
151151

152152
template <class AsyncSignature>
153153
class AsyncFunctionPointer;

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ enum class JobKind : size_t {
22102210
DefaultActorSeparate,
22112211
DefaultActorOverride,
22122212
NullaryContinuation,
2213-
AdHoc,
2213+
IsolatedDeinit,
22142214
};
22152215

22162216
/// The priority of a job. Higher priorities are larger values.

include/swift/Runtime/Concurrency.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ swift_task_createNullaryContinuationJob(
546546
AsyncTask *continuation);
547547

548548
SWIFT_EXPORT_FROM(swift_Concurrency)
549-
SWIFT_CC(swift) void swift_task_performOnExecutor(void *context,
550-
AdHocWorkFunction *work,
551-
ExecutorRef newExecutor);
549+
SWIFT_CC(swift) void swift_task_deinitOnExecutor(void *object,
550+
DeinitWorkFunction *work,
551+
ExecutorRef newExecutor);
552552

553553
/// Report error about attempting to bind a task-local value from an illegal context.
554554
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,11 +1870,11 @@ FUNCTION(TaskSwitchFunc,
18701870
ATTRS(NoUnwind),
18711871
EFFECT(Concurrency))
18721872

1873-
// void swift_task_performOnExecutor(void *context,
1874-
// AdHocWorkFunction *work,
1875-
// ExecutorRef newExecutor);
1876-
FUNCTION(PerformOnExecutorFunc,
1877-
swift_task_performOnExecutor, SwiftCC,
1873+
// void swift_task_deinitOnExecutor(void *object,
1874+
// DeinitWorkFunction *work,
1875+
// ExecutorRef newExecutor);
1876+
FUNCTION(DeinitOnExecutorFunc,
1877+
swift_task_deinitOnExecutor, SwiftCC,
18781878
ConcurrencyAvailability,
18791879
RETURNS(VoidTy),
18801880
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy),

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ FuncDecl *SILGenModule::getSwiftJobRun() {
476476
"_swiftJobRun");
477477
}
478478

479-
FuncDecl *SILGenModule::getPerformOnExecutor() {
480-
return lookupConcurrencyIntrinsic(getASTContext(), PerformOnExecutor,
481-
"_performOnExecutor");
479+
FuncDecl *SILGenModule::getDeinitOnExecutor() {
480+
return lookupConcurrencyIntrinsic(getASTContext(), DeinitOnExecutor,
481+
"_deinitOnExecutor");
482482
}
483483

484484
FuncDecl *SILGenModule::getExit() {

lib/SILGen/SILGen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
134134
Optional<FuncDecl *> AsyncMainDrainQueue;
135135
Optional<FuncDecl *> GetMainExecutor;
136136
Optional<FuncDecl *> SwiftJobRun;
137-
Optional<FuncDecl *> PerformOnExecutor;
137+
Optional<FuncDecl *> DeinitOnExecutor;
138138
Optional<FuncDecl *> ExitFunc;
139139

140140
public:
@@ -534,8 +534,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
534534
FuncDecl *getGetMainExecutor();
535535
/// Retrieve the _Concurrency._swiftJobRun intrinsic.
536536
FuncDecl *getSwiftJobRun();
537-
/// Retrieve the _Concurrency._performOnExecutor intrinsic.
538-
FuncDecl *getPerformOnExecutor();
537+
/// Retrieve the _Concurrency._deinitOnExecutor intrinsic.
538+
FuncDecl *getDeinitOnExecutor();
539539
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.
540540
FuncDecl *getExit();
541541

lib/SILGen/SILGenDestructor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
297297
executor = B.createExtractExecutor(loc, actor);
298298
}
299299

300-
// Get performOnExecutor
301-
FuncDecl *swiftPerformOnExecutorDecl = SGM.getPerformOnExecutor();
302-
assert(swiftPerformOnExecutorDecl &&
303-
"Failed to find swift_task_performOnExecutor function decl");
304-
SILFunction *swiftPerformOnExecutorSILFunc = SGM.getFunction(
305-
SILDeclRef(swiftPerformOnExecutorDecl, SILDeclRef::Kind::Func),
300+
// Get deinitOnExecutor
301+
FuncDecl *swiftDeinitOnExecutorDecl = SGM.getDeinitOnExecutor();
302+
assert(swiftDeinitOnExecutorDecl &&
303+
"Failed to find swift_task_deinitOnExecutor function decl");
304+
SILFunction *swiftDeinitOnExecutorSILFunc = SGM.getFunction(
305+
SILDeclRef(swiftDeinitOnExecutorDecl, SILDeclRef::Kind::Func),
306306
NotForDefinition);
307-
SILValue swiftPerformOnExecutorFunc =
308-
B.createFunctionRefFor(loc, swiftPerformOnExecutorSILFunc);
307+
SILValue swiftDeinitOnExecutorFunc =
308+
B.createFunctionRefFor(loc, swiftDeinitOnExecutorSILFunc);
309309

310310
// Cast self to AnyObject preserving owned ownership
311311
// CanType selfType = selfValue->getType().getASTType();
@@ -332,7 +332,7 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
332332
B.createConvertFunction(loc, dtx, workFuncType, false);
333333

334334
// Schedule isolated execution
335-
B.createApply(loc, swiftPerformOnExecutorFunc, {},
335+
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
336336
{castedSelf, castedDeallocator, executor});
337337
});
338338
}

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ OVERRIDE_ACTOR(task_switch, void,
9292
TaskContinuationFunction *resumeFunction, ExecutorRef newExecutor),
9393
(resumeToContext, resumeFunction, newExecutor))
9494

95-
OVERRIDE_ACTOR(task_performOnExecutor, void,
95+
OVERRIDE_ACTOR(task_deinitOnExecutor, void,
9696
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
97-
(void *context, AdHocWorkFunction *work, ExecutorRef newExecutor),
97+
(void *object, DeinitWorkFunction *work, ExecutorRef newExecutor),
9898
(context, work, newExecutor))
9999

100100
OVERRIDE_TASK(task_create_common, AsyncTaskAndContext,

stdlib/public/Concurrency/Actor.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,56 +1698,56 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
16981698
namespace {
16991699
/// Job that allows to use executor API to schedule a block of task-less
17001700
/// synchronous code.
1701-
class AdHocJob : public Job {
1701+
class IsolatedDeinitJob : public Job {
17021702

17031703
private:
1704-
void *Context;
1705-
AdHocWorkFunction *Work;
1704+
void *Object;
1705+
DeinitWorkFunction *Work;
17061706
TaskLocal::Storage Local;
17071707
public:
1708-
AdHocJob(JobPriority priority, void *context, AdHocWorkFunction *work)
1709-
: Job({JobKind::AdHoc, priority}, &process), Context(context),
1708+
IsolatedDeinitJob(JobPriority priority, void *object, DeinitWorkFunction *work)
1709+
: Job({JobKind::IsolatedDeinit, priority}, &process), Object(object),
17101710
Work(work)
17111711
{
17121712
TaskLocal::copyTo(&Local, nullptr);
17131713
}
17141714

1715-
~AdHocJob() { Local.destroy(nullptr); }
1715+
~IsolatedDeinitJob() { Local.destroy(nullptr); }
17161716

17171717
SWIFT_CC(swiftasync)
17181718
static void process(Job *_job) {
1719-
auto *job = cast<AdHocJob>(_job);
1719+
auto *job = cast<IsolatedDeinitJob>(_job);
17201720
job->runWork();
17211721
delete job;
17221722
}
17231723

17241724
inline void runWork() {
17251725
TaskLocal::AdHocScope taskLocalScope(&Local);
1726-
Work(Context);
1726+
Work(Object);
17271727
}
17281728

17291729
static bool classof(const Job *job) {
1730-
return job->Flags.getKind() == JobKind::AdHoc;
1730+
return job->Flags.getKind() == JobKind::IsolatedDeinit;
17311731
}
17321732
};
17331733
} // namespace
17341734

17351735
SWIFT_CC(swift)
1736-
static void swift_task_performOnExecutorImpl(void *context,
1737-
AdHocWorkFunction *work,
1738-
ExecutorRef newExecutor) {
1736+
static void swift_task_deinitOnExecutorImpl(void *object,
1737+
DeinitWorkFunction *work,
1738+
ExecutorRef newExecutor) {
17391739
// If the current executor is compatible with running the new executor,
17401740
// we can just immediately continue running with the resume function
17411741
// we were passed in.
17421742
//
17431743
// Note that swift_task_isCurrentExecutor() returns true for @MainActor
17441744
// when running on the main thread without any executor
17451745
if (swift_task_isCurrentExecutor(newExecutor)) {
1746-
return work(context); // 'return' forces tail call
1746+
return work(object); // 'return' forces tail call
17471747
}
17481748

17491749
// Optimize deallocation of the default actors
1750-
if (context == newExecutor.getIdentity() && newExecutor.isDefaultActor()) {
1750+
if (newExecutor.isDefaultActor() && object == newExecutor.getIdentity()) {
17511751
// Try to take the lock. This should always succeed, unless someone is running
17521752
// the actor using unsafe unowned reference.
17531753
if (asImpl(newExecutor.getDefaultActor())->tryLock(false)) {
@@ -1765,7 +1765,7 @@ static void swift_task_performOnExecutorImpl(void *context,
17651765
trackingInfo.enterAndShadow(newExecutor);
17661766

17671767
// Run the work.
1768-
work(context);
1768+
work(object);
17691769

17701770
// `work` is a synchronous function, it cannot call swift_task_switch()
17711771
// If it calls any synchronous API that may change executor inside tracking info,
@@ -1785,7 +1785,7 @@ static void swift_task_performOnExecutorImpl(void *context,
17851785
auto priority = currentTask ? swift_task_currentPriority(currentTask)
17861786
: swift_task_getCurrentThreadPriority();
17871787

1788-
auto job = new AdHocJob(priority, context, work);
1788+
auto job = new IsolatedDeinitJob(priority, object, work);
17891789
swift_task_enqueue(job, newExecutor);
17901790
}
17911791

stdlib/public/Concurrency/Executor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
124124

125125

126126
@available(SwiftStdlib 5.6, *) // TODO: Clarify version
127-
@_silgen_name("swift_task_performOnExecutor")
127+
@_silgen_name("swift_task_deinitOnExecutor")
128128
@usableFromInline
129-
internal func _performOnExecutor(_ ctx: __owned AnyObject,
129+
internal func _deinitOnExecutor(_ ctx: __owned AnyObject,
130130
_ work: @convention(thin) (__owned AnyObject) -> Void,
131131
_ executor: Builtin.Executor)

test/Distributed/SIL/distributed_actor_default_deinit_sil.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ distributed actor MyDistActorIsolated {
219219
// CHECK: [[LOCAL_ACTOR_DEINIT_BB]]:
220220
// CHECK: [[ISOLATED_REF:%[0-9]+]] = function_ref @$s14default_deinit19MyDistActorIsolatedCfZ : $@convention(thin) (@owned MyDistActorIsolated) -> ()
221221
// CHECK: [[EXECUTOR:%[0-9]+]] = extract_executor [[SELF]] : $MyDistActorIsolated
222-
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_performOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
222+
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_deinitOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
223223
// CHECK: [[SELF_AS_ANY_OBJECT:%[0-9]+]] = unchecked_bitwise_cast [[SELF]] : $MyDistActorIsolated to $AnyObject
224224
// CHECK: [[ISOLATED_CASTED:%[0-9]+]] = convert_function [[ISOLATED_REF]] : $@convention(thin) (@owned MyDistActorIsolated) -> () to $@convention(thin) (@owned AnyObject) -> ()
225225
// 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 {
355355
// CHECK: bb0([[SELF:%[0-9]+]] : $SimpleActorIsolated):
356356
// CHECK: [[ISOLATED_REF:%[0-9]+]] = function_ref @$s14default_deinit19SimpleActorIsolatedCfZ : $@convention(thin) (@owned SimpleActorIsolated) -> ()
357357
// CHECK: [[EXECUTOR:%[0-9]+]] = extract_executor [[SELF]] : $SimpleActorIsolated
358-
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_performOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
358+
// CHECK: [[PERFORM_REF:%[0-9]+]] = function_ref @swift_task_deinitOnExecutor : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()
359359
// CHECK: [[SELF_AS_ANY_OBJECT:%[0-9]+]] = unchecked_bitwise_cast [[SELF]] : $SimpleActorIsolated to $AnyObject
360360
// CHECK: [[ISOLATED_CASTED:%[0-9]+]] = convert_function [[ISOLATED_REF]] : $@convention(thin) (@owned SimpleActorIsolated) -> () to $@convention(thin) (@owned AnyObject) -> ()
361361
// CHECK: [[DROP:%[0-9]+]] = apply [[PERFORM_REF]]([[SELF_AS_ANY_OBJECT]], [[ISOLATED_CASTED]], [[EXECUTOR]]) : $@convention(thin) (@owned AnyObject, @convention(thin) (@owned AnyObject) -> (), Builtin.Executor) -> ()

0 commit comments

Comments
 (0)