|
11 | 11 | This proposal removes four customization points from protocols in the
|
12 | 12 | standard library:
|
13 | 13 |
|
14 |
| -- `map` and `forEach` from `Sequence` |
15 |
| -- `first` from `Collection` |
| 14 | +- `map`, `filter`, and `forEach` from `Sequence` |
| 15 | +- `first`, `prefix(upTo:)`, `prefix(through:)`, and `suffix(from:)` from `Collection` |
16 | 16 | - `last` on `BidirectionalCollection`
|
17 | 17 |
|
18 | 18 | The default implementations of these symbols will remain, so sequences and
|
@@ -47,15 +47,18 @@ Customization points aren't free – they add a small cost at both compile time
|
47 | 47 | and run time. So they should only be added if there is a realistic possibility
|
48 | 48 | that either of the two reasons above apply.
|
49 | 49 |
|
50 |
| -In the case of the 4 customization points in this proposal, reason 1 does not |
| 50 | +In the case of the customization points in this proposal, reason 1 does not |
51 | 51 | apply. In fact it could be considered a serious bug if any type implemented
|
52 |
| -these 4 features with anything other than the default observable behavior. |
| 52 | +these features with anything other than the default observable behavior. |
53 | 53 |
|
54 | 54 | It is also hard to find a good use case for reason 2 – whereas slight slowdowns
|
55 |
| -from the presence of the customization points have been observed. While it is |
56 |
| -possible that a resilient type's `forEach` implementation might be able to eke |
57 |
| -out a small performance benefit (for example, to avoid the reference count bump |
58 |
| -of putting `self` into an iterator), it is generally harmful to encourage this |
| 55 | +and code size bloatfrom the presence of the customization points have been observed. |
| 56 | +In some cases (for example `suffix(from:)`), the implementation is so simple that |
| 57 | +there is no reasonable alternative implementation. |
| 58 | + |
| 59 | +While it is possible that a resilient type's `forEach` implementation might be able |
| 60 | +to eke out a small performance benefit (for example, to avoid the reference count |
| 61 | +bump of putting `self` into an iterator), it is generally harmful to encourage this |
59 | 62 | kind of "maybe forEach could be faster" micro-optimization. For example, see
|
60 | 63 | [here](https://github.com/apple/swift/pull/17387), where error control flow was
|
61 | 64 | used in order to break out of the `forEach` early, causing unpleasant
|
@@ -92,7 +95,7 @@ the protocol.
|
92 | 95 |
|
93 | 96 | ## Proposed solution
|
94 | 97 |
|
95 |
| -Remove these 4 customization points from the `Collection` protocols. The |
| 98 | +Remove these customization points from the `Collection` protocols. The |
96 | 99 | default implementations will remain.
|
97 | 100 |
|
98 | 101 | ## Source compatibility
|
|
0 commit comments