Skip to content

Commit 49066b6

Browse files
ktosoCatfish-Man
authored andcommitted
[Concurrency] Fix the missing builtin guards for DiscardingTaskGroup (swiftlang#70837)
1 parent 924d245 commit 49066b6

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ LANGUAGE_FEATURE(BuiltinBuildComplexEqualityExecutor, 0, "Executor-building for
8383
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin")
8484
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "Task create in task group builtin with extra flags")
8585
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroupWithExecutor, 0, "Task create in task group builtin with extra flags")
86+
LANGUAGE_FEATURE(BuiltinCreateAsyncDiscardingTaskInGroup, 0, "Task create in discarding task group builtin, accounting for the Void return type")
8687
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskWithExecutor, 0, "Task create builtin with extra executor preference")
8788
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()")
8889
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc")

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,6 +3284,10 @@ static bool usesFeatureBuiltinCreateAsyncTaskInGroupWithExecutor(Decl *decl) {
32843284
return false;
32853285
}
32863286

3287+
static bool usesFeatureBuiltinCreateAsyncDiscardingTaskInGroup(Decl *decl) {
3288+
return false;
3289+
}
3290+
32873291
static bool usesFeatureBuiltinCreateAsyncTaskWithExecutor(Decl *decl) {
32883292
return false;
32893293
}

stdlib/public/Concurrency/DiscardingTaskGroup.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,20 @@ public struct DiscardingTaskGroup {
190190
#endif
191191

192192
// Create the task in this group.
193+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
193194
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
195+
#else
196+
// This builtin happens to work, but the signature of the operation is
197+
// incorrect, as the discarding group uses Void, and therefore has less
198+
// generic parameters than the operation expected to be passed to
199+
// createAsyncTaskInGroup. While this happened to work on some platforms,
200+
// on others this causes issues, e.g. on wasm;
201+
//
202+
// Keep this branch for compatibility with old compilers, but use the
203+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
204+
// enough compiler is used).
205+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
206+
#endif
194207
}
195208

196209
/// Adds a child task to the group, unless the group has been canceled.
@@ -231,7 +244,20 @@ public struct DiscardingTaskGroup {
231244
#endif
232245

233246
// Create the task in this group.
247+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
234248
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
249+
#else
250+
// This builtin happens to work, but the signature of the operation is
251+
// incorrect, as the discarding group uses Void, and therefore has less
252+
// generic parameters than the operation expected to be passed to
253+
// createAsyncTaskInGroup. While this happened to work on some platforms,
254+
// on others this causes issues, e.g. on wasm;
255+
//
256+
// Keep this branch for compatibility with old compilers, but use the
257+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
258+
// enough compiler is used).
259+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
260+
#endif
235261

236262
return true
237263
}
@@ -247,7 +273,20 @@ public struct DiscardingTaskGroup {
247273
)
248274

249275
// Create the task in this group.
276+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
250277
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
278+
#else
279+
// This builtin happens to work, but the signature of the operation is
280+
// incorrect, as the discarding group uses Void, and therefore has less
281+
// generic parameters than the operation expected to be passed to
282+
// createAsyncTaskInGroup. While this happened to work on some platforms,
283+
// on others this causes issues, e.g. on wasm;
284+
//
285+
// Keep this branch for compatibility with old compilers, but use the
286+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
287+
// enough compiler is used).
288+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
289+
#endif
251290
}
252291

253292
/// Adds a child task to the group, unless the group has been canceled.
@@ -278,7 +317,20 @@ public struct DiscardingTaskGroup {
278317
)
279318

280319
// Create the task in this group.
320+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
281321
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
322+
#else
323+
// This builtin happens to work, but the signature of the operation is
324+
// incorrect, as the discarding group uses Void, and therefore has less
325+
// generic parameters than the operation expected to be passed to
326+
// createAsyncTaskInGroup. While this happened to work on some platforms,
327+
// on others this causes issues, e.g. on wasm;
328+
//
329+
// Keep this branch for compatibility with old compilers, but use the
330+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
331+
// enough compiler is used).
332+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
333+
#endif
282334

283335
return true
284336
#else
@@ -564,7 +616,20 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
564616
)
565617

566618
// Create the task in this group.
619+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
567620
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
621+
#else
622+
// This builtin happens to work, but the signature of the operation is
623+
// incorrect, as the discarding group uses Void, and therefore has less
624+
// generic parameters than the operation expected to be passed to
625+
// createAsyncTaskInGroup. While this happened to work on some platforms,
626+
// on others this causes issues, e.g. on wasm;
627+
//
628+
// Keep this branch for compatibility with old compilers, but use the
629+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
630+
// enough compiler is used).
631+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
632+
#endif
568633
#else
569634
fatalError("Unsupported Swift compiler")
570635
#endif
@@ -593,7 +658,20 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
593658
)
594659

595660
// Create the task in this group.
661+
#if $BuiltinCreateAsyncDiscardingTaskInGroup
596662
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
663+
#else
664+
// This builtin happens to work, but the signature of the operation is
665+
// incorrect, as the discarding group uses Void, and therefore has less
666+
// generic parameters than the operation expected to be passed to
667+
// createAsyncTaskInGroup. While this happened to work on some platforms,
668+
// on others this causes issues, e.g. on wasm;
669+
//
670+
// Keep this branch for compatibility with old compilers, but use the
671+
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
672+
// enough compiler is used).
673+
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
674+
#endif
597675

598676
return true
599677
#else

0 commit comments

Comments
 (0)