Skip to content

Value and type parameter packs. #1956

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
merged 21 commits into from
Mar 21, 2023
Merged

Value and type parameter packs. #1956

merged 21 commits into from
Mar 21, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Feb 20, 2023

Forum pitches:

With a dedicated syntax discussion at:

I originally wrote a prospective vision for variadic generics, but it turned out to be more like an extended future directions writeup, and much of the content has been folded into this pitch.

Copy link
Contributor

@xwu xwu left a comment

Choose a reason for hiding this comment

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

Tried to give it a good go of pre-review. Hopefully the comments are helpful although the main things you've already flagged as to-dos.

* There are two very different models for working with packs; the same conceptual expansion has very different spellings at the type and value level, `repeat Wrapped<each T>` vs `values.map { Wrapped($0) }`.
* Magic map can only be applied to one pack at a time, leaving no clear way to zip packs without adding other builtins. A `zip` builtin would also be misleading, because expanding two packs in parallel does not need to iterate over the packs twice, but using `zip(t, u).map { ... }` looks that way.
* The closure-like syntax is misleading because it’s not a normal closure that you can write in the language. This operation is also very complex over packs with any structure, including concrete types, because the compiler either needs to infer a common generic signature for the closure that works for all elements, or it needs to separately type check the closure once for each element type.
* `map` would still need to be resolved via overload resolution amongst the existing overloads, so this approach doesn't help much with the type checking issues that `...` has.
Copy link
Contributor

@xwu xwu Mar 6, 2023

Choose a reason for hiding this comment

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

Possibly slot the alternatives to the decisions made for the "open questions" mentioned above down here.

@hborla hborla force-pushed the parameter-packs branch 3 times, most recently from 0bc5694 to 5a6c08e Compare March 8, 2023 06:34
@hborla hborla force-pushed the parameter-packs branch from 2f32dc7 to 5940dc2 Compare March 8, 2023 07:02
Copy link
Contributor

@beccadax beccadax left a comment

Choose a reason for hiding this comment

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

Drive-by review with some apparent typos and other drafting suggestions.

@hborla hborla marked this pull request as ready for review March 15, 2023 04:36
- Substituting `each T := {Int}` into `(repeat each T)`.
- Substituting `each T := {}` into `(Int, repeat each T)`.

Though unwrapping single-element tuples complicates type matching, surfacing single-element tuples in the programming model would icnrease the surface area of the language. One-element tuples would need to be manually unrwapped with `.0` or pattern matching in order to make use of their contents. This unwrapping would clutter up code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: icnrease

@xwu xwu merged commit ef26a79 into swiftlang:main Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants