Skip to content

Commit a263bca

Browse files
authored
Merge pull request #72772 from kubamracek/embedded-concurrency-deps
[embedded] Add a test checking the dependencies of Embedded Concurrency runtime
2 parents 19dd44b + 27f7a55 commit a263bca

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

stdlib/public/Concurrency/TaskAlloc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ static TaskAllocator &allocator(AsyncTask *task) {
4040
if (task)
4141
return task->Private.get().Allocator;
4242

43+
#if !SWIFT_CONCURRENCY_EMBEDDED
4344
// FIXME: this fall-back shouldn't be necessary, but it's useful
4445
// for now, since the current execution tests aren't setting up a task
4546
// properly.
4647
static GlobalAllocator global;
4748
return global.allocator;
49+
#else
50+
fprintf(stderr, "global allocator fallback not available\n");
51+
abort();
52+
#endif
4853
}
4954

5055
void *swift::swift_task_alloc(size_t size) {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 %t/a.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
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: __ZNSt3__111this_thread9sleep_forERKNS_6chrono8durationIxNS_5ratioILl1ELl1000000000EEEEE
13+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
14+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcm
15+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEmPKc
16+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
17+
// DEP: __ZNSt3__16chrono12steady_clock3nowEv
18+
// DEP: __ZNSt3__19to_stringEj
19+
// DEP: __ZNSt3__19to_stringEy
20+
// DEP: __ZdlPv
21+
// DEP: __Znwm
22+
// DEP: ___assert_rtn
23+
// DEP: ___stack_chk_fail
24+
// DEP: ___stack_chk_guard
25+
// DEP: ___stderrp
26+
// DEP: __availability_version_check
27+
// DEP: _abort
28+
// DEP: _asl_log
29+
// DEP: _dispatch_once_f
30+
// DEP: _dlsym
31+
// DEP: _exit
32+
// DEP: _fclose
33+
// DEP: _fopen
34+
// DEP: _fprintf
35+
// DEP: _fread
36+
// DEP: _free
37+
// DEP: _fseek
38+
// DEP: _ftell
39+
// DEP: _malloc
40+
// DEP: _memcpy
41+
// DEP: _memset_s
42+
// DEP: _os_unfair_lock_lock
43+
// DEP: _os_unfair_lock_unlock
44+
// DEP: _posix_memalign
45+
// DEP: _pthread_equal
46+
// DEP: _pthread_getspecific
47+
// DEP: _pthread_self
48+
// DEP: _pthread_setspecific
49+
// DEP: _putchar
50+
// DEP: _rewind
51+
// DEP: _sscanf
52+
// DEP: _strlen
53+
// DEP: _vfprintf
54+
// DEP: _vsnprintf
55+
// DEP: _write
56+
// DEP: dyld_stub_binder
57+
58+
// RUN: %target-run %t/a.out | %FileCheck %s
59+
60+
// REQUIRES: swift_in_compiler
61+
// REQUIRES: executable_test
62+
// REQUIRES: optimized_stdlib
63+
// REQUIRES: OS=macosx
64+
65+
import _Concurrency
66+
67+
public func test() async -> Int {
68+
print("test")
69+
let t = Task {
70+
print("return 42")
71+
return 42
72+
}
73+
print("await")
74+
let v = await t.value
75+
print("return")
76+
return v
77+
}
78+
79+
@main
80+
struct Main {
81+
static func main() async {
82+
print("main")
83+
// CHECK: main
84+
let t = Task {
85+
print("task")
86+
let x = await test()
87+
print(x == 42 ? "42" : "???")
88+
}
89+
print("after task")
90+
await t.value
91+
// CHECK-NEXT: after task
92+
// CHECK-NEXT: task
93+
// CHECK-NEXT: test
94+
// CHECK-NEXT: await
95+
// CHECK-NEXT: return 42
96+
// CHECK-NEXT: return
97+
// CHECK-NEXT: 42
98+
}
99+
}

0 commit comments

Comments
 (0)