-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow TaskGroup's ChildTaskResult Type To Be Inferred #2494
Allow TaskGroup's ChildTaskResult Type To Be Inferred #2494
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Minor ideas to improve proposal and we can ask the core team for a review 👍
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
proposals/NNNN-allow-taskgroup-childtaskresult-type-to-be-inferred.md
Outdated
Show resolved
Hide resolved
Thank you for looking over everything. I have implemented the suggestions and updated a spots of grammar. Should I go ahead and tag this as |
Yeap, please mark as ready to review! :) |
…the first sentence of the Design Details section.
|
||
## Detailed design | ||
|
||
Because type inference is top-down, it relies on the first statement that uses `group` to infer determine the generic for `ChildTaskResult`. Therefore, it is possible to get a compiler error by creating a task group where the first use of `group` does not use `addTask(...)`, like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because type inference is top-down, it relies on the first statement that uses `group` to infer determine the generic for `ChildTaskResult`. Therefore, it is possible to get a compiler error by creating a task group where the first use of `group` does not use `addTask(...)`, like so: | |
Because type inference is top-down, it relies on the first statement that uses `group` to infer the generic arguments for `ChildTaskResult`. Therefore, it is possible to get a compiler error by creating a task group where the first use of `group` does not use `addTask(...)`, like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'll kick the review off shortly.
// Expect `ChildTaskResult` to be `Int`... | ||
withTaskGroup(of: Int.self) { group in | ||
group.cancelAll() | ||
group.addTask { 42 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be beneficial to have some more realistic examples. For example, there are small-but-realistic examples at https://www.avanderlee.com/concurrency/task-groups-in-swift/ and https://www.kodeco.com/books/modern-concurrency-in-swift/v1.0/chapters/7-concurrent-code-with-taskgroup that you could reference (with attribution!) and will give reviewers a better feel for how this impacts use of the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the examples to use more real-world scenarios. Thank you for the suggestion. 👍
Original discussion here: https://forums.swift.org/t/allow-taskgroups-childtaskresult-type-to-be-inferred/72175
See: swiftlang/swift#74517