[swift-evolution] Separating the finite-vs-infinite distinction from single-vs-multi-pass
dabrahams at apple.com
Tue Jul 5 20:56:57 CDT 2016
This post describes the standard library team's analysis of the
finite/infinite sequence issue raised by Matthew Johnson and others in
[Dmitri is going to write a separate post detailing our proposed
direction with respect to the original topic raised by David Waite in
confusion resulting from the refinement relationship between Sequence
and Collection that introduces non-destructive consumption. As you
will see below, the resolution of this post's issue will depend
somewhat on that].
It seems to us that there are four possible approaches here:
1. Do nothing. Infinite loops are not usually security problems and
might not be worth complicating APIs for.
2. Formally lift the constraint on Collection that forces it to be
finite. That would allow us to model multi-pass traversal over
(portions of) infinite sequences.
3. #2, plus add to Collection an `isKnownToBeInfinite` property,
defaulting to `false`, that can be used to trigger a trap when a call
would otherwise loop infinitely.
4. Go all the way to separate protocols for finite and infinite
Collections as detailed in
As far as we can tell, the only real point in distinguishing finiteness
is to prevent infinite loops. Since inifinite loops are equally
(non-)problematic for both single- and multi-pass sequences, we can find
little justification for treating single-pass and multi-pass sequences
differently where finiteness is concerned. Therefore, whatever we end
up with for Collection should apply to single-pass sequences as well.
Lastly, it looks like nobody on the standard library team is going to
have the time to drive this forward for Swift 3. While the standard
library team can provide some guidance, if it is to happen, someone else
needs to take the reins. That's not supposed to be discouraging:
several smart and capable people have expressed their interest in this
topic. That said, if you care about it, you'll need to do as much work
as possible independently. That includes putting the proposal through
evolution and creating a pull request containing the implementation.
More information about the swift-evolution