Skip to content

Commit cb0e1da

Browse files
authored
Revert "Revert "Concurrency: Move code between Executor{Bridge,Impl}.cpp"" (#80692)
* Revert "Revert "Concurrency: Move code between `Executor{Bridge,Impl}.cpp`"" * Update CMakeLists.txt
1 parent 8220838 commit cb0e1da

File tree

4 files changed

+100
-72
lines changed

4 files changed

+100
-72
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_library(swift_Concurrency
1212
EmbeddedSupport.cpp
1313
Error.cpp
1414
ExecutorBridge.cpp
15+
ExecutorImpl.cpp
1516
ExecutorChecks.cpp
1617
GlobalExecutor.cpp
1718
Setup.cpp

stdlib/public/Concurrency/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
166166
PlatformExecutorWindows.swift
167167
)
168168

169+
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES
170+
ExecutorImpl.cpp
171+
)
172+
169173
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES)
170174
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES)
175+
171176
if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
172177
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES
173178
DispatchGlobalExecutor.cpp
@@ -202,6 +207,7 @@ set(LLVM_OPTIONAL_SOURCES
202207
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
203208
${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES}
204209
${SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES}
210+
${SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES}
205211
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
206212
${SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES}
207213

stdlib/public/Concurrency/ExecutorBridge.cpp

-72
Original file line numberDiff line numberDiff line change
@@ -34,83 +34,11 @@ SerialExecutorRef swift_getMainExecutor() {
3434
}
3535
#endif
3636

37-
extern "C" SWIFT_CC(swift)
38-
void _swift_task_checkIsolatedSwift(
39-
HeapObject *executor,
40-
const Metadata *executorType,
41-
const SerialExecutorWitnessTable *witnessTable
42-
);
43-
4437
extern "C" SWIFT_CC(swift)
4538
void _swift_task_checkIsolatedSwift(HeapObject *executor,
4639
const Metadata *executorType,
4740
const SerialExecutorWitnessTable *witnessTable);
4841

49-
extern "C" SWIFT_CC(swift)
50-
bool _swift_task_isIsolatingCurrentContextSwift(
51-
HeapObject *executor,
52-
const Metadata *executorType,
53-
const SerialExecutorWitnessTable *witnessTable
54-
);
55-
56-
extern "C" SWIFT_CC(swift)
57-
bool _swift_task_isMainExecutorSwift(
58-
HeapObject *executor,
59-
const Metadata *executorType,
60-
const SerialExecutorWitnessTable *witnessTable
61-
);
62-
63-
extern "C" SWIFT_CC(swift)
64-
void swift_task_checkIsolatedImpl(SerialExecutorRef executor) {
65-
HeapObject *identity = executor.getIdentity();
66-
67-
// We might be being called with an actor rather than a "proper"
68-
// SerialExecutor; in that case, we won't have a SerialExecutor witness
69-
// table.
70-
if (executor.hasSerialExecutorWitnessTable()) {
71-
_swift_task_checkIsolatedSwift(identity,
72-
swift_getObjectType(identity),
73-
executor.getSerialExecutorWitnessTable());
74-
} else {
75-
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
76-
auto typeName = swift_getTypeName(objectType, true);
77-
78-
swift_Concurrency_fatalError(
79-
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
80-
(int)typeName.length, typeName.data);
81-
}
82-
}
83-
84-
extern "C" SWIFT_CC(swift)
85-
bool swift_task_isIsolatingCurrentContextImpl(SerialExecutorRef executor) {
86-
HeapObject *identity = executor.getIdentity();
87-
88-
// We might be being called with an actor rather than a "proper"
89-
// SerialExecutor; in that case, we won't have a SerialExecutor witness
90-
// table.
91-
if (executor.hasSerialExecutorWitnessTable()) {
92-
return _swift_task_isIsolatingCurrentContextSwift(identity,
93-
swift_getObjectType(identity),
94-
executor.getSerialExecutorWitnessTable());
95-
} else {
96-
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
97-
auto typeName = swift_getTypeName(objectType, true);
98-
99-
swift_Concurrency_fatalError(
100-
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
101-
(int)typeName.length, typeName.data);
102-
}
103-
}
104-
105-
extern "C" SWIFT_CC(swift)
106-
bool swift_task_isMainExecutorImpl(SerialExecutorRef executor) {
107-
HeapObject *identity = executor.getIdentity();
108-
return executor.hasSerialExecutorWitnessTable()
109-
&& _swift_task_isMainExecutorSwift(identity,
110-
swift_getObjectType(identity),
111-
executor.getSerialExecutorWitnessTable());
112-
}
113-
11442
extern "C" SWIFT_CC(swift)
11543
uint8_t swift_job_getPriority(Job *job) {
11644
return (uint8_t)(job->getPriority());
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//===--- ExecutorImpl.cpp - C++ side of executor impl ---------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#if SWIFT_CONCURRENCY_USES_DISPATCH
14+
#include <dispatch/dispatch.h>
15+
#endif
16+
17+
#include "Error.h"
18+
#include "ExecutorBridge.h"
19+
20+
using namespace swift;
21+
22+
#pragma clang diagnostic push
23+
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
24+
25+
26+
extern "C" SWIFT_CC(swift)
27+
void _swift_task_checkIsolatedSwift(
28+
HeapObject *executor,
29+
const Metadata *executorType,
30+
const SerialExecutorWitnessTable *witnessTable
31+
);
32+
33+
extern "C" SWIFT_CC(swift) bool _swift_task_isMainExecutorSwift(
34+
HeapObject *executor, const Metadata *executorType,
35+
const SerialExecutorWitnessTable *witnessTable);
36+
37+
extern "C" SWIFT_CC(swift) void swift_task_checkIsolatedImpl(
38+
SerialExecutorRef executor) {
39+
HeapObject *identity = executor.getIdentity();
40+
41+
// We might be being called with an actor rather than a "proper"
42+
// SerialExecutor; in that case, we won't have a SerialExecutor witness
43+
// table.
44+
if (executor.hasSerialExecutorWitnessTable()) {
45+
_swift_task_checkIsolatedSwift(identity, swift_getObjectType(identity),
46+
executor.getSerialExecutorWitnessTable());
47+
} else {
48+
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
49+
auto typeName = swift_getTypeName(objectType, true);
50+
51+
swift_Concurrency_fatalError(
52+
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
53+
(int)typeName.length, typeName.data);
54+
}
55+
}
56+
57+
58+
extern "C" SWIFT_CC(swift)
59+
bool _swift_task_isIsolatingCurrentContextSwift(
60+
HeapObject *executor,
61+
const Metadata *executorType,
62+
const SerialExecutorWitnessTable *witnessTable
63+
);
64+
65+
extern "C" SWIFT_CC(swift) bool swift_task_isIsolatingCurrentContextImpl(
66+
SerialExecutorRef executor) {
67+
HeapObject *identity = executor.getIdentity();
68+
69+
// We might be being called with an actor rather than a "proper"
70+
// SerialExecutor; in that case, we won't have a SerialExecutor witness
71+
// table.
72+
if (executor.hasSerialExecutorWitnessTable()) {
73+
return _swift_task_isIsolatingCurrentContextSwift(
74+
identity, swift_getObjectType(identity),
75+
executor.getSerialExecutorWitnessTable());
76+
} else {
77+
const Metadata *objectType = swift_getObjectType(executor.getIdentity());
78+
auto typeName = swift_getTypeName(objectType, true);
79+
80+
swift_Concurrency_fatalError(
81+
0, "Incorrect actor executor assumption; expected '%.*s' executor.\n",
82+
(int)typeName.length, typeName.data);
83+
}
84+
}
85+
86+
extern "C" SWIFT_CC(swift) bool swift_task_isMainExecutorImpl(
87+
SerialExecutorRef executor) {
88+
HeapObject *identity = executor.getIdentity();
89+
return executor.hasSerialExecutorWitnessTable() &&
90+
_swift_task_isMainExecutorSwift(
91+
identity, swift_getObjectType(identity),
92+
executor.getSerialExecutorWitnessTable());
93+
}

0 commit comments

Comments
 (0)