Skip to content

Commit 2358cc9

Browse files
committed
[Concurrency] Split out the default cooperative executor into a separate opt-in library
1 parent c31ed73 commit 2358cc9

10 files changed

+112
-17
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
256256
set(SWIFT_SDK_embedded_LIB_SUBDIR "embedded")
257257
set(SWIFT_SDK_embedded_ARCH_${mod}_TRIPLE "${triple}")
258258

259+
# lib/swift/embedded/_Concurrency.swiftmodule
260+
# lib/swift/embedded/<triple>/libswift_Concurrency.a
259261
add_swift_target_library_single(
260262
embedded-concurrency-${mod}
261263
swift_Concurrency
@@ -264,7 +266,6 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
264266

265267
${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES}
266268
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES}
267-
CooperativeGlobalExecutor.cpp
268269

269270
SWIFT_COMPILE_FLAGS
270271
${extra_swift_compile_flags} -enable-experimental-feature Embedded
@@ -291,8 +292,37 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
291292
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
292293
)
293294
set_property(TARGET embedded-concurrency-${mod} PROPERTY OSX_ARCHITECTURES "${arch}")
294-
295295
add_dependencies(embedded-concurrency embedded-concurrency-${mod})
296+
297+
# lib/swift/embedded/<triple>/libswift_ConcurrencyDefaultExecutor.a
298+
add_swift_target_library_single(
299+
embedded-concurrency-default-executor-${mod}
300+
swift_ConcurrencyDefaultExecutor
301+
STATIC
302+
IS_FRAGILE
303+
304+
CooperativeGlobalExecutor.cpp
305+
306+
C_COMPILE_FLAGS ${extra_c_compile_flags}
307+
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
308+
SDK "embedded"
309+
ARCHITECTURE "${mod}"
310+
DEPENDS embedded-stdlib-${mod}
311+
INSTALL_IN_COMPONENT stdlib
312+
)
313+
swift_install_in_component(
314+
TARGETS embedded-concurrency-default-executor-${mod}
315+
DESTINATION "lib/swift/embedded/${mod}"
316+
COMPONENT "stdlib"
317+
)
318+
swift_install_in_component(
319+
FILES "${SWIFTLIB_DIR}/embedded/${mod}/libswift_ConcurrencyDefaultExecutor.a"
320+
DESTINATION "lib/swift/embedded/${mod}/"
321+
COMPONENT "stdlib"
322+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
323+
)
324+
set_property(TARGET embedded-concurrency-default-executor-${mod} PROPERTY OSX_ARCHITECTURES "${arch}")
325+
add_dependencies(embedded-concurrency embedded-concurrency-default-executor-${mod})
296326
endforeach()
297327

298328
# Copy the ExecutorImpl.h header into the local include directory

test/embedded/concurrency-actors.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-async-let.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-continuations.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-simple.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-stream.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -target %target-cpu-apple-macos14 -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-taskgroup.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -target %target-cpu-apple-macos14 -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/concurrency-taskgroup2.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -target %target-cpu-apple-macos14 -parse-as-library %s -c -o %t/a.o
3-
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
4-
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
54
// RUN: %target-run %t/a.out | %FileCheck %s
65

76
// REQUIRES: executable_test

test/embedded/dependencies-concurrency.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -target %target-cpu-apple-macos14 -disable-availability-checking -parse-as-library -enable-experimental-feature Embedded %s -c -o %t/a.o
3-
// RUN: %target-clang %t/a.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
44

55
// RUN: grep DEP\: %s | sed 's#// DEP\: ##' | sort > %t/allowed-dependencies.txt
66

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -target %target-cpu-apple-macos14 -disable-availability-checking -parse-as-library -enable-experimental-feature Embedded %s -c -o %t/a.o
3+
// RUN: %target-clang -nostdlib -lSystem %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -dead_strip -Wl,-undefined,dynamic_lookup
4+
5+
// RUN: grep DEP\: %s | sed 's#// DEP\: ##' | sort > %t/allowed-dependencies.txt
6+
7+
// RUN: %llvm-nm --undefined-only --format=just-symbols %t/a.out | sort | tee %t/actual-dependencies.txt
8+
9+
// Fail if there is any entry in actual-dependencies.txt that's not in allowed-dependencies.txt
10+
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"
11+
12+
// DEP: ___assert_rtn
13+
// DEP: ___stack_chk_fail
14+
// DEP: ___stack_chk_guard
15+
// DEP: _abort
16+
// DEP: _exit
17+
// DEP: _free
18+
// DEP: _malloc
19+
// DEP: _memmove
20+
// DEP: _memset
21+
// DEP: _memset_s
22+
// DEP: _posix_memalign
23+
// DEP: _putchar
24+
// DEP: _puts
25+
// DEP: _strlen
26+
// DEP: _swift_task_asyncMainDrainQueueImpl
27+
// DEP: _swift_task_enqueueGlobalImpl
28+
// DEP: _swift_task_getMainExecutorImpl
29+
// DEP: _swift_task_asyncMainDrainQueueImpl
30+
// DEP: _swift_task_checkIsolatedImpl
31+
// DEP: _swift_task_donateThreadToGlobalExecutorUntilImpl
32+
// DEP: _swift_task_enqueueGlobalImpl
33+
// DEP: _swift_task_enqueueGlobalWithDeadlineImpl
34+
// DEP: _swift_task_enqueueGlobalWithDelayImpl
35+
// DEP: _swift_task_enqueueMainExecutorImpl
36+
// DEP: _swift_task_getMainExecutorImpl
37+
// DEP: _swift_task_isMainExecutorImpl
38+
// DEP: _vprintf
39+
// DEP: _vsnprintf
40+
// DEP: dyld_stub_binder
41+
42+
// REQUIRES: swift_in_compiler
43+
// REQUIRES: optimized_stdlib
44+
// REQUIRES: OS=macosx
45+
46+
import _Concurrency
47+
48+
public func test() async -> Int {
49+
print("test")
50+
let t = Task {
51+
print("return 42")
52+
return 42
53+
}
54+
print("await")
55+
let v = await t.value
56+
print("return")
57+
return v
58+
}
59+
60+
@main
61+
struct Main {
62+
static func main() async {
63+
print("main")
64+
let t = Task {
65+
print("task")
66+
let x = await test()
67+
print(x == 42 ? "42" : "???")
68+
}
69+
print("after task")
70+
await t.value
71+
}
72+
}

0 commit comments

Comments
 (0)