[swift-dev] SR-122 / CollectionsMoveIndices.swift Prototype

Shawn Erickson shawnce at gmail.com
Mon Mar 14 13:57:53 CDT 2016


On Thu, Mar 10, 2016 at 10:49 PM Dmitri Gribenko <gribozavr at gmail.com>
wrote:

> Hi everyone,
>
> I just wanted to announce that we have sufficient change on the
> swift-3-indexing-model branch so that we can build the core standard
> library and StdlibUnittest.  We achieved this by putting the protocol
> new structure into place, and stubbing out with fatalError() or just
> commenting out parts that didn't compile.  Now we have a baseline that
> we won't regress, and we are starting to work towards improving it,
> making existing tests pass, and then writing new tests, and addressing
> TODOs and FIXMEs that we left in the code as we were doing the first
> pass.
>
> Here's the most recent pull request from Shawn where he starts to fix
> the tests: https://github.com/apple/swift/pull/1632
>
> Now we are in the "massively-parallel" stage of this project and we,
> as always, welcome contributions to this branch!
>

Is their a reason we are suppressing sort in place for MutableCollections?

benchmark/single-source/StaticArray.swift:86:17: error: 'sort()' has been
renamed to 'sorted'
    staticArray.sort()
                ^~~~
                sorted
Swift.MutableCollection:3:17: note: 'sort()' has been explicitly marked
unavailable here
    public func sort() -> [Self.Iterator.Element]
                ^

In CollectionAlgorithms we have `sortInPlace` marked as unavailable renamed
to `sort` and `sort -> [Iterator.Element]` marked as unavailable renamed
`sorted`.

I believe we want `sort()` to be the mutating one (in place) and `sorted()`
to return a sorted version, right? I poke around more on this. It could be
we have an overzealous unavailable?


----------
extension MutableCollection
  where
  Self : RandomAccessCollection,
  Self.Iterator.Element : Comparable {

  @available(*, unavailable, renamed="sort")
  public mutating func sortInPlace() {
    fatalError("unavailable function can't be called")
  }
}

extension MutableCollection where Self.Iterator.Element : Comparable {
  @available(*, unavailable, renamed="sorted")
  public func sort() -> [Iterator.Element] {
    fatalError("unavailable function can't be called")
  }

  @available(*, unavailable, renamed="sorted(isOrderedBefore:)")
  public func sort(
    @noescape isOrderedBefore: (Iterator.Element, Iterator.Element) -> Bool
  ) -> [Iterator.Element] {
    fatalError("unavailable function can't be called")
  }
}
-----------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160314/510b0a08/attachment.html>


More information about the swift-dev mailing list