Skip to content

Commit df58797

Browse files
committed
[embedded] Use async main in the test
1 parent afa1427 commit df58797

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
210210
# TODO: Only a handful of Swift Concurrency .swift sources, for now.
211211
Task.swift
212212
AsyncLet.swift
213+
Executor.swift
213214
Errors.swift
215+
PartialAsyncTask.swift
214216

215217
SWIFT_COMPILE_FLAGS
216218
-Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public struct UnownedJob: Sendable {
9797
}
9898

9999
@available(SwiftStdlib 5.9, *)
100+
@_unavailableInEmbedded
100101
extension UnownedJob: CustomStringConvertible {
101102
@available(SwiftStdlib 5.9, *)
102103
public var description: String {
@@ -147,6 +148,7 @@ public struct Job: Sendable {
147148

148149
// TODO: move only types cannot conform to protocols, so we can't conform to CustomStringConvertible;
149150
// we can still offer a description to be called explicitly though.
151+
@_unavailableInEmbedded
150152
public var description: String {
151153
let id = _getJobTaskId(UnownedJob(context: self.context))
152154
/// Tasks are always assigned an unique ID, however some jobs may not have it set,
@@ -215,6 +217,7 @@ public struct ExecutorJob: Sendable {
215217

216218
// TODO: move only types cannot conform to protocols, so we can't conform to CustomStringConvertible;
217219
// we can still offer a description to be called explicitly though.
220+
@_unavailableInEmbedded
218221
public var description: String {
219222
let id = _getJobTaskId(UnownedJob(context: self.context))
220223
/// Tasks are always assigned an unique ID, however some jobs may not have it set,

stdlib/public/Concurrency/Task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,6 @@ static void swift_task_asyncMainDrainQueueImpl() {
16011601
swift_task_donateThreadToGlobalExecutorUntil([](void *context) {
16021602
return *reinterpret_cast<bool*>(context);
16031603
}, &Finished);
1604-
exit(0);
16051604
#elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
16061605
// FIXME: consider implementing a concurrent global main queue for
16071606
// these environments?

test/embedded/concurrency-simple.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,24 @@ public func test() async -> Int {
2323
return v
2424
}
2525

26-
@_silgen_name("swift_task_asyncMainDrainQueue")
27-
func _asyncMainDrainQueue() -> Never
28-
2926
@main
3027
struct Main {
31-
static func main() {
28+
static func main() async {
3229
print("main")
3330
// CHECK: main
34-
35-
Task {
31+
let t = Task {
3632
print("task")
3733
let x = await test()
3834
print(x == 42 ? "42" : "???")
3935
}
40-
print("drain")
41-
// CHECK-NEXT: drain
42-
43-
_asyncMainDrainQueue()
36+
print("after task")
37+
await t.value
38+
// CHECK-NEXT: after task
4439
// CHECK-NEXT: task
4540
// CHECK-NEXT: test
4641
// CHECK-NEXT: await
4742
// CHECK-NEXT: return 42
4843
// CHECK-NEXT: return
4944
// CHECK-NEXT: 42
50-
51-
print("done")
52-
// CHECK-NOT: done
5345
}
5446
}

0 commit comments

Comments
 (0)