Added flags to be able to control task-locals behaviour in the future

This commit is contained in:
Mykola Pokhylets
2023-04-24 12:24:51 +02:00
parent 40c7c6b028
commit ab4d338f6a
6 changed files with 16 additions and 8 deletions

View File

@@ -608,7 +608,7 @@ swift_task_createNullaryContinuationJob(
SWIFT_EXPORT_FROM(swift_Concurrency)
SWIFT_CC(swift)
void swift_task_deinitOnExecutor(void *object, DeinitWorkFunction *work,
SerialExecutorRef newExecutor);
SerialExecutorRef newExecutor, size_t flags);
/// Report error about attempting to bind a task-local value from an illegal context.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)

View File

@@ -2335,12 +2335,13 @@ FUNCTION(TaskSwitchFunc,
// void swift_task_deinitOnExecutor(void *object,
// DeinitWorkFunction *work,
// SerialExecutorRef newExecutor);
// SerialExecutorRef newExecutor,
// size_t flags);
FUNCTION(DeinitOnExecutorFunc,
swift_task_deinitOnExecutor, SwiftCC,
ConcurrencyAvailability,
RETURNS(VoidTy),
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy),
ARGS(Int8PtrTy, Int8PtrTy, ExecutorFirstTy, ExecutorSecondTy, SizeTy),
ATTRS(NoUnwind),
EFFECT(Concurrency),
UNKNOWN_MEMEFFECTS)

View File

@@ -18,6 +18,7 @@
#include "swift/AST/Decl.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/Runtime/Concurrency.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/SIL/SILLinkage.h"
#include "swift/SIL/SILMoveOnlyDeinit.h"
@@ -407,9 +408,13 @@ void SILGenFunction::emitIsolatingDestructor(DestructorDecl *dd) {
auto castedDeallocator =
B.createConvertFunction(loc, dtx, workFuncType, false);
auto wordTy = SILType::getBuiltinWordType(getASTContext());
auto *flagsInst =
B.createIntegerLiteral(loc, wordTy, 0);
// Schedule isolated execution
B.createApply(loc, swiftDeinitOnExecutorFunc, {},
{castedSelf, castedDeallocator, executor});
{castedSelf, castedDeallocator, executor, flagsInst});
});
}

View File

@@ -144,8 +144,8 @@ OVERRIDE_ACTOR(task_switch, void,
OVERRIDE_ACTOR(task_deinitOnExecutor, void,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor),
(object, work, newExecutor))
(void *object, DeinitWorkFunction *work, SerialExecutorRef newExecutor, size_t flags),
(object, work, newExecutor, flags))
OVERRIDE_TASK(task_create_common, AsyncTaskAndContext,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,

View File

@@ -2172,7 +2172,8 @@ public:
SWIFT_CC(swift)
static void swift_task_deinitOnExecutorImpl(void *object,
DeinitWorkFunction *work,
SerialExecutorRef newExecutor) {
SerialExecutorRef newExecutor,
size_t rawFlags) {
// If the current executor is compatible with running the new executor,
// we can just immediately continue running with the resume function
// we were passed in.

View File

@@ -565,4 +565,5 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
@usableFromInline
internal func _deinitOnExecutor(_ object: __owned AnyObject,
_ work: @convention(thin) (__owned AnyObject) -> Void,
_ executor: Builtin.Executor)
_ executor: Builtin.Executor,
_ flags: Builtin.Word)