Skip to content

Commit 35f0334

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 a043ebf commit 35f0334

File tree

13 files changed

+51
-50
lines changed

13 files changed

+51
-50
lines changed

include/swift/ABI/Executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ using ThrowingTaskFutureWaitContinuationFunction =
291291
SWIFT_CC(swiftasync)
292292
void (SWIFT_ASYNC_CONTEXT AsyncContext *, SWIFT_CONTEXT void *);
293293

294-
using AdHocWorkFunction = SWIFT_CC(swift) void(void *);
294+
using DeinitWorkFunction = SWIFT_CC(swift) void(void *);
295295

296296
template <class AsyncSignature>
297297
class AsyncFunctionPointer;

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ enum class JobKind : size_t {
24912491
DefaultActorSeparate,
24922492
DefaultActorOverride,
24932493
NullaryContinuation,
2494-
AdHoc,
2494+
IsolatedDeinit,
24952495
};
24962496

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

include/swift/Runtime/Concurrency.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ swift_task_createNullaryContinuationJob(
607607

608608
SWIFT_EXPORT_FROM(swift_Concurrency)
609609
SWIFT_CC(swift)
610-
void swift_task_performOnExecutor(void *context, AdHocWorkFunction *work,
611-
SerialExecutorRef newExecutor);
610+
void swift_task_deinitOnExecutor(void *object, DeinitWorkFunction *work,
611+
SerialExecutorRef newExecutor);
612612

613613
/// Report error about attempting to bind a task-local value from an illegal context.
614614
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
@@ -2333,11 +2333,11 @@ FUNCTION(TaskSwitchFunc,
23332333
EFFECT(Concurrency),
23342334
UNKNOWN_MEMEFFECTS)
23352335

2336-
// void swift_task_performOnExecutor(void *context,
2337-
// AdHocWorkFunction *work,
2338-
// SerialExecutorRef newExecutor);
2339-
FUNCTION(PerformOnExecutorFunc,
2340-
swift_task_performOnExecutor, SwiftCC,
2336+
// void swift_task_deinitOnExecutor(void *object,
2337+
// DeinitWorkFunction *work,
2338+
// SerialExecutorRef newExecutor);
2339+
FUNCTION(DeinitOnExecutorFunc,
2340+
swift_task_deinitOnExecutor, SwiftCC,
23412341
ConcurrencyAvailability,
23422342
RETURNS(VoidTy),
23432343
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy),

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ FuncDecl *SILGenModule::getSwiftJobRun() {
448448
return lookupConcurrencyIntrinsic(getASTContext(), "_swiftJobRun");
449449
}
450450

451-
FuncDecl *SILGenModule::getPerformOnExecutor() {
452-
return lookupConcurrencyIntrinsic(getASTContext(), "_performOnExecutor");
451+
FuncDecl *SILGenModule::getDeinitOnExecutor() {
452+
return lookupConcurrencyIntrinsic(getASTContext(), "_deinitOnExecutor");
453453
}
454454

455455
FuncDecl *SILGenModule::getExit() {

lib/SILGen/SILGen.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
552552
FuncDecl *getAsyncMainDrainQueue();
553553
/// Retrieve the _Concurrency._swiftJobRun intrinsic.
554554
FuncDecl *getSwiftJobRun();
555-
/// Retrieve the _Concurrency._performOnExecutor intrinsic.
556-
FuncDecl *getPerformOnExecutor();
555+
/// Retrieve the _Concurrency._deinitOnExecutor intrinsic.
556+
FuncDecl *getDeinitOnExecutor();
557557
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.
558558
FuncDecl *getExit();
559559

lib/SILGen/SILGenDestructor.cpp

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

374-
// Get performOnExecutor
375-
FuncDecl *swiftPerformOnExecutorDecl = SGM.getPerformOnExecutor();
376-
assert(swiftPerformOnExecutorDecl &&
377-
"Failed to find swift_task_performOnExecutor function decl");
378-
SILFunction *swiftPerformOnExecutorSILFunc = SGM.getFunction(
379-
SILDeclRef(swiftPerformOnExecutorDecl, SILDeclRef::Kind::Func),
374+
// Get deinitOnExecutor
375+
FuncDecl *swiftDeinitOnExecutorDecl = SGM.getDeinitOnExecutor();
376+
assert(swiftDeinitOnExecutorDecl &&
377+
"Failed to find swift_task_deinitOnExecutor function decl");
378+
SILFunction *swiftDeinitOnExecutorSILFunc = SGM.getFunction(
379+
SILDeclRef(swiftDeinitOnExecutorDecl, SILDeclRef::Kind::Func),
380380
NotForDefinition);
381-
SILValue swiftPerformOnExecutorFunc =
382-
B.createFunctionRefFor(loc, swiftPerformOnExecutorSILFunc);
381+
SILValue swiftDeinitOnExecutorFunc =
382+
B.createFunctionRefFor(loc, swiftDeinitOnExecutorSILFunc);
383383

384384
// Cast self to AnyObject preserving owned ownership
385385
CanType selfType = selfValue->getType().getASTType();
@@ -408,7 +408,7 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
408408
B.createConvertFunction(loc, dtx, workFuncType, false);
409409

410410
// Schedule isolated execution
411-
B.createApply(loc, swiftPerformOnExecutorFunc, {},
411+
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
412412
{castedSelf, castedDeallocator, executor});
413413
});
414414
}

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ OVERRIDE_ACTOR(task_switch, void,
142142
TaskContinuationFunction *resumeFunction, SerialExecutorRef newExecutor),
143143
(resumeToContext, resumeFunction, newExecutor))
144144

145-
OVERRIDE_ACTOR(task_performOnExecutor, void,
145+
OVERRIDE_ACTOR(task_deinitOnExecutor, void,
146146
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
147-
(void *context, AdHocWorkFunction *work, SerialExecutorRef newExecutor),
148-
(context, work, newExecutor))
147+
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor),
148+
(object, work, newExecutor))
149149

150150
OVERRIDE_TASK(task_create_common, AsyncTaskAndContext,
151151
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,

stdlib/public/Concurrency/Actor.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,47 +2143,48 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
21432143
namespace {
21442144
/// Job that allows to use executor API to schedule a block of task-less
21452145
/// synchronous code.
2146-
class AdHocJob : public Job {
2146+
class IsolatedDeinitJob : public Job {
21472147
private:
2148-
void *Context;
2149-
AdHocWorkFunction *Work;
2148+
void *Object;
2149+
DeinitWorkFunction *Work;
21502150

21512151
public:
2152-
AdHocJob(JobPriority priority, void *context, AdHocWorkFunction *work)
2153-
: Job({JobKind::AdHoc, priority}, &process), Context(context),
2152+
IsolatedDeinitJob(JobPriority priority, void *object,
2153+
DeinitWorkFunction *work)
2154+
: Job({JobKind::IsolatedDeinit, priority}, &process), Object(object),
21542155
Work(work) {}
21552156

21562157
SWIFT_CC(swiftasync)
21572158
static void process(Job *_job) {
2158-
auto *job = cast<AdHocJob>(_job);
2159-
void *ctx = job->Context;
2160-
AdHocWorkFunction *work = job->Work;
2159+
auto *job = cast<IsolatedDeinitJob>(_job);
2160+
void *object = job->Object;
2161+
DeinitWorkFunction *work = job->Work;
21612162
delete job;
2162-
return work(ctx);
2163+
return work(object);
21632164
}
21642165

21652166
static bool classof(const Job *job) {
2166-
return job->Flags.getKind() == JobKind::AdHoc;
2167+
return job->Flags.getKind() == JobKind::IsolatedDeinit;
21672168
}
21682169
};
21692170
} // namespace
21702171

21712172
SWIFT_CC(swift)
2172-
static void swift_task_performOnExecutorImpl(void *context,
2173-
AdHocWorkFunction *work,
2174-
SerialExecutorRef newExecutor) {
2173+
static void swift_task_deinitOnExecutorImpl(void *object,
2174+
DeinitWorkFunction *work,
2175+
SerialExecutorRef newExecutor) {
21752176
// If the current executor is compatible with running the new executor,
21762177
// we can just immediately continue running with the resume function
21772178
// we were passed in.
21782179
//
21792180
// Note that swift_task_isCurrentExecutor() returns true for @MainActor
21802181
// when running on the main thread without any executor
21812182
if (swift_task_isCurrentExecutor(newExecutor)) {
2182-
return work(context); // 'return' forces tail call
2183+
return work(object); // 'return' forces tail call
21832184
}
21842185

21852186
// Optimize deallocation of the default actors
2186-
if (context == newExecutor.getIdentity() && newExecutor.isDefaultActor()) {
2187+
if (newExecutor.isDefaultActor() && object == newExecutor.getIdentity()) {
21872188
// Try to take the lock. This should always succeed, unless someone is
21882189
// running the actor using unsafe unowned reference.
21892190
if (asImpl(newExecutor.getDefaultActor())->tryLock(false)) {
@@ -2202,7 +2203,7 @@ static void swift_task_performOnExecutorImpl(void *context,
22022203
trackingInfo.enterAndShadow(newExecutor, TaskExecutorRef::undefined());
22032204

22042205
// Run the work.
2205-
work(context);
2206+
work(object);
22062207

22072208
// `work` is a synchronous function, it cannot call swift_task_switch()
22082209
// If it calls any synchronous API that may change executor inside
@@ -2222,7 +2223,7 @@ static void swift_task_performOnExecutorImpl(void *context,
22222223
auto priority = currentTask ? swift_task_currentPriority(currentTask)
22232224
: swift_task_getCurrentThreadPriority();
22242225

2225-
auto job = new AdHocJob(priority, context, work);
2226+
auto job = new IsolatedDeinitJob(priority, object, work);
22262227
swift_task_enqueue(job, newExecutor);
22272228
}
22282229

stdlib/public/Concurrency/Executor.swift

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

562562

563563
@available(SwiftStdlib 5.6, *) // TODO: Clarify version
564-
@_silgen_name("swift_task_performOnExecutor")
564+
@_silgen_name("swift_task_deinitOnExecutor")
565565
@usableFromInline
566-
internal func _performOnExecutor(_ ctx: __owned AnyObject,
567-
_ work: @convention(thin) (__owned AnyObject) -> Void,
568-
_ executor: Builtin.Executor)
566+
internal func _deinitOnExecutor(_ object: __owned AnyObject,
567+
_ work: @convention(thin) (__owned AnyObject) -> Void,
568+
_ executor: Builtin.Executor)

0 commit comments

Comments
 (0)