Skip to content

Commit ab4d338

Browse files
Added flags to be able to control task-locals behaviour in the future
1 parent 40c7c6b commit ab4d338

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ swift_task_createNullaryContinuationJob(
608608
SWIFT_EXPORT_FROM(swift_Concurrency)
609609
SWIFT_CC(swift)
610610
void swift_task_deinitOnExecutor(void *object, DeinitWorkFunction *work,
611-
SerialExecutorRef newExecutor);
611+
SerialExecutorRef newExecutor, size_t flags);
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,12 +2335,13 @@ FUNCTION(TaskSwitchFunc,
23352335

23362336
// void swift_task_deinitOnExecutor(void *object,
23372337
// DeinitWorkFunction *work,
2338-
// SerialExecutorRef newExecutor);
2338+
// SerialExecutorRef newExecutor,
2339+
// size_t flags);
23392340
FUNCTION(DeinitOnExecutorFunc,
23402341
swift_task_deinitOnExecutor, SwiftCC,
23412342
ConcurrencyAvailability,
23422343
RETURNS(VoidTy),
2343-
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy),
2344+
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy, SizeTy),
23442345
ATTRS(NoUnwind),
23452346
EFFECT(Concurrency),
23462347
UNKNOWN_MEMEFFECTS)

lib/SILGen/SILGenDestructor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/Decl.h"
1919
#include "swift/AST/GenericSignature.h"
2020
#include "swift/AST/SubstitutionMap.h"
21+
#include "swift/Runtime/Concurrency.h"
2122
#include "swift/SIL/SILBuilder.h"
2223
#include "swift/SIL/SILLinkage.h"
2324
#include "swift/SIL/SILMoveOnlyDeinit.h"
@@ -407,9 +408,13 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
407408
auto castedDeallocator =
408409
B.createConvertFunction(loc, dtx, workFuncType, false);
409410

411+
auto wordTy = SILType::getBuiltinWordType(getASTContext());
412+
auto *flagsInst =
413+
B.createIntegerLiteral(loc, wordTy, 0);
414+
410415
// Schedule isolated execution
411416
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
412-
{castedSelf, castedDeallocator, executor});
417+
{castedSelf, castedDeallocator, executor, flagsInst});
413418
});
414419
}
415420

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ OVERRIDE_ACTOR(task_switch, void,
144144

145145
OVERRIDE_ACTOR(task_deinitOnExecutor, void,
146146
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
147-
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor),
148-
(object, work, newExecutor))
147+
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor, size_t flags),
148+
(object, work, newExecutor, flags))
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,8 @@ class IsolatedDeinitJob : public Job {
21722172
SWIFT_CC(swift)
21732173
static void swift_task_deinitOnExecutorImpl(void *object,
21742174
DeinitWorkFunction *work,
2175-
SerialExecutorRef newExecutor) {
2175+
SerialExecutorRef newExecutor,
2176+
size_t rawFlags) {
21762177
// If the current executor is compatible with running the new executor,
21772178
// we can just immediately continue running with the resume function
21782179
// we were passed in.

stdlib/public/Concurrency/Executor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,5 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
565565
@usableFromInline
566566
internal func _deinitOnExecutor(_ object: __owned AnyObject,
567567
_ work: @convention(thin) (__owned AnyObject) -> Void,
568-
_ executor: Builtin.Executor)
568+
_ executor: Builtin.Executor,
569+
_ flags: Builtin.Word)

0 commit comments

Comments
 (0)