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
Describe how variadic generic functions interact with overload resolu…
…tion.
  • Loading branch information
hborla committed Mar 15, 2023
commit ab18ee4d1932f614bd00d51a1a5675b0f117376c
21 changes: 21 additions & 0 deletions proposals/NNNN-parameter-packs.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This proposal adds _type parameter packs_ and _value parameter packs_ to enable
- [Same-shape requirements](#same-shape-requirements)
- [Restrictions on same-shape requirements](#restrictions-on-same-shape-requirements)
- [Value parameter packs](#value-parameter-packs)
- [Overload resolution](#overload-resolution)
- [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 Down Expand Up @@ -551,6 +552,26 @@ func forward<each U>(u: repeat each U) {
}
```

### Overload resolution

Generic functions can be overloaded by the "pack-ness" of their type parameters. For example, a function can have two overloads where one accepts a scalar type parameter and the other accepts a type parameter pack:

```swift
func overload<T>(_: T) {}
func overload<each T>(_: repeat each T) {}
```

If both overloads match a given call, e.g. `overload(1)`, the call is ambiguous. Similarly, two generic functions where one accepts a non-pack variadic parameter and the other accepts a type parameter pack:

```swift
func overload<T>(_: T...) {}
func overload<each T>(_: repeat each T) {}

overload() // ambiguity error
```

In other words, variadic generic functions have the same ranking as other generic functions.

## 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