Skip to content

Concurrency: Move code between Executor{Bridge,Impl}.cpp #80601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
PlatformExecutorWindows.swift
)

set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES
ExecutorImpl.cpp
)

set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES)
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES)

if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES
DispatchGlobalExecutor.cpp
Expand Down Expand Up @@ -202,6 +207,7 @@ set(LLVM_OPTIONAL_SOURCES
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES}
${SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES}
${SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES}
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
${SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES}

Expand Down
72 changes: 0 additions & 72 deletions stdlib/public/Concurrency/ExecutorBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,83 +34,11 @@ SerialExecutorRef swift_getMainExecutor() {
}
#endif

extern "C" SWIFT_CC(swift)
void _swift_task_checkIsolatedSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);

extern "C" SWIFT_CC(swift)
void _swift_task_checkIsolatedSwift(HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable);

extern "C" SWIFT_CC(swift)
bool _swift_task_isIsolatingCurrentContextSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);

extern "C" SWIFT_CC(swift)
bool _swift_task_isMainExecutorSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);

extern "C" SWIFT_CC(swift)
void swift_task_checkIsolatedImpl(SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();

// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
_swift_task_checkIsolatedSwift(identity,
swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);

swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}

extern "C" SWIFT_CC(swift)
bool swift_task_isIsolatingCurrentContextImpl(SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();

// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
return _swift_task_isIsolatingCurrentContextSwift(identity,
swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);

swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}

extern "C" SWIFT_CC(swift)
bool swift_task_isMainExecutorImpl(SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();
return executor.hasSerialExecutorWitnessTable()
&& _swift_task_isMainExecutorSwift(identity,
swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
}

extern "C" SWIFT_CC(swift)
uint8_t swift_job_getPriority(Job *job) {
return (uint8_t)(job->getPriority());
Expand Down
93 changes: 93 additions & 0 deletions stdlib/public/Concurrency/ExecutorImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//===--- ExecutorImpl.cpp - C++ side of executor impl ---------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#if SWIFT_CONCURRENCY_USES_DISPATCH
#include <dispatch/dispatch.h>
#endif

#include "Error.h"
#include "ExecutorBridge.h"

using namespace swift;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"


extern "C" SWIFT_CC(swift)
void _swift_task_checkIsolatedSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);

extern "C" SWIFT_CC(swift) bool _swift_task_isMainExecutorSwift(
HeapObject *executor, const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable);

extern "C" SWIFT_CC(swift) void swift_task_checkIsolatedImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();

// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
_swift_task_checkIsolatedSwift(identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);

swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}


extern "C" SWIFT_CC(swift)
bool _swift_task_isIsolatingCurrentContextSwift(
HeapObject *executor,
const Metadata *executorType,
const SerialExecutorWitnessTable *witnessTable
);

extern "C" SWIFT_CC(swift) bool swift_task_isIsolatingCurrentContextImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();

// We might be being called with an actor rather than a "proper"
// SerialExecutor; in that case, we won't have a SerialExecutor witness
// table.
if (executor.hasSerialExecutorWitnessTable()) {
return _swift_task_isIsolatingCurrentContextSwift(
identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
} else {
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
auto typeName = swift_getTypeName(objectType, true);

swift_Concurrency_fatalError(
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
(int)typeName.length, typeName.data);
}
}

extern "C" SWIFT_CC(swift) bool swift_task_isMainExecutorImpl(
SerialExecutorRef executor) {
HeapObject *identity = executor.getIdentity();
return executor.hasSerialExecutorWitnessTable() &&
_swift_task_isMainExecutorSwift(
identity, swift_getObjectType(identity),
executor.getSerialExecutorWitnessTable());
}