Skip to content

Commit 624b92f

Browse files
Add further customization points based per review (#938)
1 parent 5713476 commit 624b92f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

proposals/0232-remove-customization-points.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
This proposal removes four customization points from protocols in the
1212
standard library:
1313

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`
1616
- `last` on `BidirectionalCollection`
1717

1818
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
4747
and run time. So they should only be added if there is a realistic possibility
4848
that either of the two reasons above apply.
4949

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
5151
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.
5353

5454
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
5962
kind of "maybe forEach could be faster" micro-optimization. For example, see
6063
[here](https://github.com/apple/swift/pull/17387), where error control flow was
6164
used in order to break out of the `forEach` early, causing unpleasant
@@ -92,7 +95,7 @@ the protocol.
9295

9396
## Proposed solution
9497

95-
Remove these 4 customization points from the `Collection` protocols. The
98+
Remove these customization points from the `Collection` protocols. The
9699
default implementations will remain.
97100

98101
## Source compatibility

0 commit comments

Comments
 (0)