Skip to content

Commit 081f107

Browse files
committed
wip
1 parent dd518e9 commit 081f107

File tree

7 files changed

+1208
-1204
lines changed

7 files changed

+1208
-1204
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
144144
Task+TaskExecutor.swift
145145
TaskCancellation.swift
146146
TaskGroup.swift
147-
ThrowingTaskGroup.swift
148147
TaskGroup+TaskExecutor.swift
149148
DiscardingTaskGroup.swift
150149
TaskLocal.swift

stdlib/public/Concurrency/SourceCompatibilityShims.swift

Lines changed: 3 additions & 274 deletions
Original file line numberDiff line numberDiff line change
@@ -298,280 +298,9 @@ extension Task where Failure == Never {
298298
}
299299
}
300300

301-
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
302-
@available(SwiftStdlib 5.1, *)
303-
extension TaskGroup {
304-
@available(SwiftStdlib 5.1, *)
305-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(priority:operation:)")
306-
@_alwaysEmitIntoClient
307-
public mutating func add(
308-
priority: TaskPriority? = nil,
309-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
310-
) async -> Bool {
311-
return self.addTaskUnlessCancelled(priority: priority) {
312-
await operation()
313-
}
314-
}
315-
316-
@available(*, deprecated, renamed: "addTask(priority:operation:)")
317-
@_alwaysEmitIntoClient
318-
public mutating func spawn(
319-
priority: TaskPriority? = nil,
320-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
321-
) {
322-
self.addTask(priority: priority, operation: operation)
323-
}
324-
325-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(priority:operation:)")
326-
@_alwaysEmitIntoClient
327-
public mutating func spawnUnlessCancelled(
328-
priority: TaskPriority? = nil,
329-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
330-
) -> Bool {
331-
addTaskUnlessCancelled(priority: priority, operation: operation)
332-
}
333-
334-
@available(*, deprecated, renamed: "addTask(priority:operation:)")
335-
@_alwaysEmitIntoClient
336-
public mutating func async(
337-
priority: TaskPriority? = nil,
338-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
339-
) {
340-
addTask(priority: priority, operation: operation)
341-
}
342-
343-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(priority:operation:)")
344-
@_alwaysEmitIntoClient
345-
public mutating func asyncUnlessCancelled(
346-
priority: TaskPriority? = nil,
347-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
348-
) -> Bool {
349-
addTaskUnlessCancelled(priority: priority, operation: operation)
350-
}
351-
}
352-
#else
353-
@available(SwiftStdlib 5.1, *)
354-
extension TaskGroup {
355-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
356-
public mutating func add(
357-
priority: TaskPriority? = nil,
358-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
359-
) async -> Bool {
360-
fatalError("Unavailable in task-to-thread concurrency model")
361-
}
362-
363-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
364-
@_alwaysEmitIntoClient
365-
public mutating func add(
366-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
367-
) async -> Bool {
368-
return self.addTaskUnlessCancelled {
369-
await operation()
370-
}
371-
}
372-
373-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
374-
public mutating func spawn(
375-
priority: TaskPriority? = nil,
376-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
377-
) {
378-
fatalError("Unavailable in task-to-thread concurrency model")
379-
}
380-
381-
@available(*, deprecated, renamed: "addTask(operation:)")
382-
@_alwaysEmitIntoClient
383-
public mutating func spawn(
384-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
385-
) {
386-
addTask(operation: operation)
387-
}
388-
389-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
390-
public mutating func spawnUnlessCancelled(
391-
priority: TaskPriority? = nil,
392-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
393-
) -> Bool {
394-
fatalError("Unavailable in task-to-thread concurrency model")
395-
}
396-
397-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
398-
@_alwaysEmitIntoClient
399-
public mutating func spawnUnlessCancelled(
400-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
401-
) -> Bool {
402-
addTaskUnlessCancelled(operation: operation)
403-
}
404-
405-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
406-
public mutating func async(
407-
priority: TaskPriority? = nil,
408-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
409-
) {
410-
fatalError("Unavailable in task-to-thread concurrency model")
411-
}
412-
413-
@available(*, deprecated, renamed: "addTask(operation:)")
414-
@_alwaysEmitIntoClient
415-
public mutating func async(
416-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
417-
) {
418-
addTask(operation: operation)
419-
}
420-
421-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
422-
public mutating func asyncUnlessCancelled(
423-
priority: TaskPriority? = nil,
424-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
425-
) -> Bool {
426-
fatalError("Unavailable in task-to-thread concurrency model")
427-
}
428-
429-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
430-
@_alwaysEmitIntoClient
431-
public mutating func asyncUnlessCancelled(
432-
operation: __owned @Sendable @escaping () async -> ChildTaskResult
433-
) -> Bool {
434-
addTaskUnlessCancelled(operation: operation)
435-
}
436-
}
437-
#endif
438-
439-
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
440-
@available(SwiftStdlib 5.1, *)
441-
extension ThrowingTaskGroup {
442-
@available(*, deprecated, renamed: "addTask(priority:operation:)")
443-
@_alwaysEmitIntoClient
444-
public mutating func add(
445-
priority: TaskPriority? = nil,
446-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
447-
) async -> Bool {
448-
return self.addTaskUnlessCancelled(priority: priority) {
449-
try await operation()
450-
}
451-
}
452-
453-
@available(*, deprecated, renamed: "addTask(priority:operation:)")
454-
@_alwaysEmitIntoClient
455-
public mutating func spawn(
456-
priority: TaskPriority? = nil,
457-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
458-
) {
459-
addTask(priority: priority, operation: operation)
460-
}
461-
462-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(priority:operation:)")
463-
@_alwaysEmitIntoClient
464-
public mutating func spawnUnlessCancelled(
465-
priority: TaskPriority? = nil,
466-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
467-
) -> Bool {
468-
addTaskUnlessCancelled(priority: priority, operation: operation)
469-
}
470-
471-
@available(*, deprecated, renamed: "addTask(priority:operation:)")
472-
@_alwaysEmitIntoClient
473-
public mutating func async(
474-
priority: TaskPriority? = nil,
475-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
476-
) {
477-
addTask(priority: priority, operation: operation)
478-
}
479-
480-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(priority:operation:)")
481-
@_alwaysEmitIntoClient
482-
public mutating func asyncUnlessCancelled(
483-
priority: TaskPriority? = nil,
484-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
485-
) -> Bool {
486-
addTaskUnlessCancelled(priority: priority, operation: operation)
487-
}
488-
}
489-
#else
490-
@available(SwiftStdlib 5.1, *)
491-
extension ThrowingTaskGroup {
492-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
493-
public mutating func add(
494-
priority: TaskPriority? = nil,
495-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
496-
) async -> Bool {
497-
fatalError("Unavailable in task-to-thread concurrency model")
498-
}
499-
500-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
501-
@_alwaysEmitIntoClient
502-
public mutating func add(
503-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
504-
) async -> Bool {
505-
return self.addTaskUnlessCancelled {
506-
try await operation()
507-
}
508-
}
509-
510-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
511-
public mutating func spawn(
512-
priority: TaskPriority? = nil,
513-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
514-
) {
515-
fatalError("Unavailable in task-to-thread concurrency model")
516-
}
517-
518-
@available(*, deprecated, renamed: "addTask(operation:)")
519-
@_alwaysEmitIntoClient
520-
public mutating func spawn(
521-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
522-
) {
523-
addTask(operation: operation)
524-
}
525-
526-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
527-
public mutating func spawnUnlessCancelled(
528-
priority: TaskPriority? = nil,
529-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
530-
) -> Bool {
531-
fatalError("Unavailable in task-to-thread concurrency model")
532-
}
533-
534-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
535-
@_alwaysEmitIntoClient
536-
public mutating func spawnUnlessCancelled(
537-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
538-
) -> Bool {
539-
addTaskUnlessCancelled(operation: operation)
540-
}
541-
542-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTask(operation:)")
543-
public mutating func async(
544-
priority: TaskPriority? = nil,
545-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
546-
) {
547-
fatalError("Unavailable in task-to-thread concurrency model")
548-
}
549-
550-
@available(*, deprecated, renamed: "addTask(operation:)")
551-
@_alwaysEmitIntoClient
552-
public mutating func async(
553-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
554-
) {
555-
addTask(operation: operation)
556-
}
557-
558-
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model", renamed: "addTaskUnlessCancelled(operation:)")
559-
public mutating func asyncUnlessCancelled(
560-
priority: TaskPriority? = nil,
561-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
562-
) -> Bool {
563-
fatalError("Unavailable in task-to-thread concurrency model")
564-
}
565-
566-
@available(*, deprecated, renamed: "addTaskUnlessCancelled(operation:)")
567-
@_alwaysEmitIntoClient
568-
public mutating func asyncUnlessCancelled(
569-
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
570-
) -> Bool {
571-
addTaskUnlessCancelled(operation: operation)
572-
}
573-
}
574-
#endif
301+
// NOTE: We had to move sources touching TaskGroup addTask APIs into TaskGroup+addTask.swift.gyb
302+
// due to the build having trouble with using the generated source in the same module
303+
// rdar://145171772
575304

576305
@available(SwiftStdlib 5.1, *)
577306
@available(*, deprecated, message: "please use UnsafeContinuation<..., Error>")

stdlib/public/Concurrency/Task.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ TaskExecutorRef _task_taskExecutor_getTaskExecutorRef(
208208

209209
TaskExecutorRef
210210
InitialTaskExecutorOwnedPreferenceTaskOptionRecord::getExecutorRefFromUnownedTaskExecutor() const {
211-
assert(Identity && WitnessTable && "task executor cannot be null");
211+
if (!Identity) return TaskExecutorRef::undefined();
212+
212213
TaskExecutorRef executorRef = _task_taskExecutor_getTaskExecutorRef(
213214
Identity,
214215
/*selfType=*/swift_getObjectType(Identity),
@@ -738,19 +739,22 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
738739
case TaskOptionRecordKind::InitialTaskExecutorUnowned:
739740
taskExecutor = cast<InitialTaskExecutorRefPreferenceTaskOptionRecord>(option)
740741
->getExecutorRef();
741-
jobFlags.task_setHasInitialTaskExecutorPreference(true);
742-
taskExecutorIsOwned = false;
742+
if (taskExecutor.isDefined()) {
743+
jobFlags.task_setHasInitialTaskExecutorPreference(true);
744+
taskExecutorIsOwned = false;
745+
}
743746
break;
744747

745748
case TaskOptionRecordKind::InitialTaskExecutorOwned:
746749
#if SWIFT_CONCURRENCY_EMBEDDED
747750
swift_unreachable("owned TaskExecutor cannot be used in embedded Swift");
748751
#else
749-
fprintf(stderr, "[%s:%d](%s) task executor option = %p\n", __FILE_NAME__, __LINE__, __FUNCTION__, option);
750752
taskExecutor = cast<InitialTaskExecutorOwnedPreferenceTaskOptionRecord>(option)
751753
->getExecutorRefFromUnownedTaskExecutor();
752-
taskExecutorIsOwned = true;
753-
jobFlags.task_setHasInitialTaskExecutorPreference(true);
754+
if (taskExecutor.isDefined()) {
755+
taskExecutorIsOwned = true;
756+
jobFlags.task_setHasInitialTaskExecutorPreference(true);
757+
}
754758
#endif
755759
break;
756760

0 commit comments

Comments
 (0)