Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c9574be
Add a draft proposal for parameter packs.
hborla Sep 28, 2022
5c536d6
Fix the type of postfix ... operator in the ambiguity example.
hborla Sep 29, 2022
5c05e76
update pitch (#1)
slavapestov Oct 25, 2022
1b7259e
Add missing SE proposal information.
hborla Oct 26, 2022
3fc7be5
Replace the '...' syntax with 'repeat each'.
hborla Feb 20, 2023
09e11cf
Add more introductory explanation to the proposed solution.
hborla Feb 20, 2023
b2ea985
Update proposals/NNNN-parameter-packs.md
hborla Feb 24, 2023
7825076
Address editorial feedback
hborla Mar 8, 2023
5940dc2
Add pack iteration and pack element projection to the future directions.
hborla Mar 8, 2023
d3043f8
Move local value packs and add explicit pack syntax to future directi…
hborla Mar 8, 2023
38c3871
Describe single-element tuple unwrapping under pack substitution.
hborla Mar 14, 2023
80b0888
Simplify the description of same-type requirements involving paramete…
hborla Mar 14, 2023
fcc02ba
Update proposals/NNNN-parameter-packs.md
hborla Mar 14, 2023
f974506
Move the introduction above the table of contents.
hborla Mar 15, 2023
247284d
Specify trailing closure matching rules for parameter packs.
hborla Mar 15, 2023
fe936ab
Replace the term "type sequence" with "type list" to avoid confusion …
hborla Mar 15, 2023
32b13db
Add more commentary on the `repeat each` syntax design.
hborla Mar 15, 2023
944432a
Minor editorial changes
hborla Mar 15, 2023
ab18ee4
Describe how variadic generic functions interact with overload resolu…
hborla Mar 15, 2023
0aeb480
Update pitch links.
hborla Mar 15, 2023
1c1b51c
Update 0393-parameter-packs.md
xwu Mar 21, 2023
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
Prev Previous commit
Next Next commit
Move local value packs and add explicit pack syntax to future directi…
…ons.
  • Loading branch information
hborla committed Mar 8, 2023
commit d3043f8d515bbd0901211701017bd3b35ebd24ef
37 changes: 24 additions & 13 deletions proposals/NNNN-parameter-packs.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
- [Same-shape requirements](#same-shape-requirements)
- [Restrictions on same-shape requirements](#restrictions-on-same-shape-requirements)
- [Value parameter packs](#value-parameter-packs)
- [Local value packs](#local-value-packs)
- [Effect on ABI stability](#effect-on-abi-stability)
- [Alternatives considered](#alternatives-considered)
- [Modeling packs as tuples with abstract elements](#modeling-packs-as-tuples-with-abstract-elements)
Expand All @@ -37,6 +36,8 @@
- [Magic builtin `map` method](#magic-builtin-map-method)
- [Future directions](#future-directions)
- [Variadic generic types](#variadic-generic-types)
- [Local value packs](#local-value-packs)
- [Explicit type pack syntax](#explicit-type-pack-syntax)
- [Pack iteration](#pack-iteration)
- [Pack element projection](#pack-element-projection)
- [Dynamic pack indexing with `Int`](#dynamic-pack-indexing-with-int)
Expand Down Expand Up @@ -553,18 +554,6 @@ func forward<each U>(u: repeat each U) {
}
```

### Local value packs

The notion of a value parameter pack readily generalizes to a local variable of pack expansion type, for example:

```swift
func variadic<each T>(t: repeat each T) {
let tt: repeat each T = repeat each t
}
```

References to `tt` have the same semantics as references to `t`, and must only appear inside other pack expansion expressions.

## Effect on ABI stability

This is still an area of open discussion, but we anticipate that generic functions with type parameter packs will not require runtime support, and thus will backward deploy. As work proceeds on the implementation, the above is subject to change.
Copy link
Contributor

Choose a reason for hiding this comment

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

As implementation matures, it'd be great to ensure that this information is as up-to-date as possible as users will be keenly interested.

Expand Down Expand Up @@ -670,6 +659,28 @@ The downsides of a magic `map` method are:

This proposal only supports type parameter packs on functions. A complementary proposal will describe type parameter packs on generic structs, enums and classes.

### Local value packs

This proposal only supports value packs for function parameters. The notion of a value parameter pack readily generalizes to a local variable of pack expansion type, for example:

```swift
func variadic<each T>(t: repeat each T) {
let tt: repeat each T = repeat each t
}
```

References to `tt` have the same semantics as references to `t`, and must only appear inside other pack expansion expressions.

### Explicit type pack syntax

In this proposal, type packs do not have an explicit syntax, and a type pack is always inferred through the type matching rules. However, we could explore adding an explicit pack syntax in the future:

```swift
struct Variadic<each T> {}

extension Variadic where each T == {Int, String} {} // {Int, String} is a concrete pack
```

### Pack iteration

All list operations can be expressed using pack expansion expressions by factoring code involving statements into a function or closure. However, this approach does not allow for short-circuiting, because the pattern expression will always be evaluated once for every element in the pack. Further, requiring a function or closure for code involving statements is unnatural. Allowing `for-in` loops to iterate over packs solves both of these problems.
Expand Down