Skip to content

[Concurrency] Fix the missing builtin guards for DiscardingTaskGroup #70837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ LANGUAGE_FEATURE(BuiltinBuildComplexEqualityExecutor, 0, "Executor-building for
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin")
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "Task create in task group builtin with extra flags")
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroupWithExecutor, 0, "Task create in task group builtin with extra flags")
LANGUAGE_FEATURE(BuiltinCreateAsyncDiscardingTaskInGroup, 0, "Task create in discarding task group builtin, accounting for the Void return type")
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskWithExecutor, 0, "Task create builtin with extra executor preference")
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()")
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc")
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,10 @@ static bool usesFeatureBuiltinCreateAsyncTaskInGroupWithExecutor(Decl *decl) {
return false;
}

static bool usesFeatureBuiltinCreateAsyncDiscardingTaskInGroup(Decl *decl) {
return false;
}

static bool usesFeatureBuiltinCreateAsyncTaskWithExecutor(Decl *decl) {
return false;
}
Expand Down
78 changes: 78 additions & 0 deletions stdlib/public/Concurrency/DiscardingTaskGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,20 @@ public struct DiscardingTaskGroup {
#endif

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

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

// Create the task in this group.
#if $BuiltinCreateAsyncDiscardingTaskInGroup
_ = Builtin.createAsyncDiscardingTaskInGroup(flags, _group, operation)
#else
// This builtin happens to work, but the signature of the operation is
// incorrect, as the discarding group uses Void, and therefore has less
// generic parameters than the operation expected to be passed to
// createAsyncTaskInGroup. While this happened to work on some platforms,
// on others this causes issues, e.g. on wasm;
//
// Keep this branch for compatibility with old compilers, but use the
// correct 'createAsyncDiscardingTaskInGroup' when available (and a recent
// enough compiler is used).
_ = Builtin.createAsyncTaskInGroup(flags, _group, operation)
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the right dance to do here -- the comment attempts to explain what we're doing here -- See the PR which introduced this change here: https://github.com/apple/swift/pull/70537/files#diff-9897ab704fe1b9e57499ec46e8837c683573998d299ea3cbfb64d29c4a34544aL567

So we're using what "used to work" on other platforms and old compilers, and when available, we use the "right thing".

Looks right @slavapestov @kavon ?


return true
}
Expand All @@ -247,7 +273,20 @@ public struct DiscardingTaskGroup {
)

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

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

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

return true
#else
Expand Down Expand Up @@ -564,7 +616,20 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
)

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

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

return true
#else
Expand Down