Commit Graph

678 Commits

Author SHA1 Message Date
David Farler
311baf73cf Index protocol extensions
- Remove free Swift functions for advance and distance and replace
  them with protocol extension methods:
  - advancedBy(n)
  - advancedBy(n, limit:)
  - distanceTo(end)
- Modernize the Index tests
  - Use StdlibUnittest
  - Test for custom implementation dispatch

Perf impact: No significant changes reported in the
Swift Performance Measurement Tool.

rdar://problem/22085119

Swift SVN r30958
2015-08-03 20:06:44 +00:00
Dave Abrahams
ad43a596bd [stdlib] Retire the old lazy subsystem...
...replacing it with the new, after passing API review!

* The lazy free function has become a property.

* Before we could extend protocols, we lacked a means for value types to
  share implementations, and each new lazy algorithm had to be added to
  each of up to four types: LazySequence, LazyForwardCollection,
  LazyBidirectionalCollection, and LazyRandomAccessCollection. These
  generic adapters hid the usual algorithms by defining their own
  versions that returned new lazy generic adapters. Now users can extend
  just one of two protocols to do the same thing: LazySequenceType or
  LazyCollectionType.

* To avoid making the code duplication worse than it already was, the
  generic adapters mentioned above were used to add the lazy generic
  algorithms around simpler adapters such as MapSequence that just
  provided the basic requirements of SequenceType by applying a
  transformation to some base sequence, resulting in deeply nested
  generic types as shown here. Now, MapSequence is an instance of
  LazySequenceType (and is renamed LazyMapSequence), and thus transmits
  laziness to its algorithms automatically.

* Documentation comments have been rewritten.

* The .array property was retired

* various renamings

* A bunch of Gyb files were retired.

Swift SVN r30902
2015-08-01 03:52:13 +00:00
Dmitri Hrybenko
d822a90ed4 stdlib: fix warnings
Swift SVN r30900
2015-08-01 02:59:43 +00:00
David Farler
91d182154f Explode Algorithm.swift.gyb into separate test files
- Added CollectionType and SequenceType.swift.gyb
- Added Slice.swift.gyb
- Added a template file for shared lazy flatMap code between sequences
  and collections
- Moved some test structs into the respective Check* files in
  StdlibUnittest.
- Slice.swift.gyb is still too slow for Debug-Assert stdlib builds.
  I've added a requirement to use the optimized standard library but
  we should split this file out even further.

rdar://problem/22095015

Swift SVN r30894
2015-08-01 00:34:58 +00:00
David Farler
7a49dda2c8 Add @warn_unused_result to map, flatMap, and filter
rdar://problem/21971932

Swift SVN r30849
2015-07-31 05:15:10 +00:00
Dmitri Hrybenko
d9088afe4b stdlib: add MutableSlice
See doc comments on MutableSlice for more information about what it is.

MutableSlice was one of the reasons to clarify and tighten index
invalidation rules.  After that change, existing MinimalCollection
test types were performing checks that are too strict according to the
model.  Existing algorithms and collections could provide them, but not
MutableSlice.  This commit updates MinimalCollection types to perform
index invalidation checks that correspond to new rules.

Part of rdar://20722366.  This commit adds the type, but does not wire
it up completely yet.

Swift SVN r30839
2015-07-31 03:21:56 +00:00
Dmitri Hrybenko
61b93564e9 Eliminate UnsafeMutableBufferPointer from _withUnsafeMutableBufferPointerIfSupported
The type checker hits a recursion when checking the conformance to
CollectionType in UnsafeMutableBufferPointer, which requires
_withUnsafeMutableBufferPointerIfSupported, which mentions
UnsafeMutableBufferPointer.  The easiest fix for now is to break the
recursion in the library.

Reverting this change is tracked by: <rdar://problem/21933004> Restore
the signature of _withUnsafeMutableBufferPointerIfSupported() that
mentions UnsafeMutableBufferPointer

Swift SVN r30838
2015-07-31 03:21:54 +00:00
Joe Groff
0c39db22bc stdlib: Implement strict 'map', 'filter', and 'flatMap' as 'rethrows' operations.
Replace the Lazy-based implementations with open-coded implementations based on the _UnsafePartiallyInitializedContiguousArrayBuffer builder from the previous commit, so that we have control over the early-exit flow when an error interrupts the operation.

Swift SVN r30794
2015-07-30 05:28:34 +00:00
Joe Groff
f62d95dbc8 stdlib: Add 'rethrows' to more SequenceType and CollectionType algorithms.
Including:

- forEach
- split
- Optional flatMap
- minElement
- maxElement
- startsWith
- elementsEqual
- lexicographicalCompare
- contains
- reduce

Still not touching 'map', 'filter', 'flatMap', or 'sort', which need various levels of rearchitecting to fix.

Swift SVN r30792
2015-07-30 05:28:26 +00:00
Joe Groff
1d49d927e1 stdlib: Mark many higher-order function interfaces as 'rethrows'.
This covers:

- Lifetime-extending wrappers, like withExtendedLifetime, withCString, and withUnsafe*Pointer
- 'map' and friends on Optional
- 'indexOf'

A few APIs I haven't gotten to yet in this first pass:

- Autoclosure APIs, like assert, &&, etc.
- the 'isOrderedBefore' predicate for sorting APIs. The sorting implementation does some microoptimizations with 'inout' closures that violate rethrows checking.
- Strict 'map', 'filter', and friends on CollectionType. These need some plumbing in Lazy to be able to thread a Result-forming transformation through.

This version of the patch updates some protocol customization implementations that I missed the first time around, and includes the tests I forgot to add in the previous iteration.

Swift SVN r30790
2015-07-30 05:28:17 +00:00
Dmitri Hrybenko
739cceba3d stdlib: lazy FlattenCollection: don't invoke the closure as frequently
FlattenCollection used to evaluate the closure three times per element.
That's acceptable from the technical standpoint, given its lazy
semantics, but not acceptable in practice.  This commit fixes it to only
evaluate it two times when it is converted into an array.

This commit also improves tests.  The new checks used to fail before the
standard library was fixed.

But there are larger issues with FlattenCollection -- it does not model
CollectionType properly.  See next commit.

Swift SVN r30616
2015-07-25 02:18:12 +00:00
Dmitri Hrybenko
4b008e6f31 stdlib: rename RangeReplaceableCollectionType.splice() to insertContentsOf()
rdar://21972324

Swift SVN r30608
2015-07-25 00:36:39 +00:00
Dmitri Hrybenko
d97ac3e64c stdlib: rename RangeReplaceableCollectionType.extend() to appendContentsOf()
rdar://21972324

Swift SVN r30607
2015-07-25 00:36:37 +00:00
Dmitri Hrybenko
f5de8757e4 stdlib: remove Word and UWord
These types are leftovers from the early pre-1.0 times when Int and UInt
were always 64-bit on all platforms.  They serve no useful purpose
today.  Int and UInt are defined to be word-sized and should be used
instead.

rdar://18693488

Swift SVN r30564
2015-07-24 05:01:32 +00:00
David Farler
dac6052cb2 Use RemoveFirstNTest for CollectionType.removeFirst APIs
Move the test examples out to the top level of StdlibUnittest like the
other tests.

Swift SVN r30548
2015-07-23 20:49:09 +00:00
Dmitri Hrybenko
6325cdd395 StdlibUnittest: give unique names to tests
Swift SVN r30536
2015-07-23 08:48:33 +00:00
David Farler
598cf7e282 Add test for SequenceType.split for the separator overload
Swift SVN r30510
2015-07-22 22:51:26 +00:00
Dmitri Hrybenko
bbed5aae68 StdlibUnittest: fix the definition of a 'slice type'
Swift SVN r30508
2015-07-22 22:13:25 +00:00
David Farler
1f2390f1c7 Drop APIs from NSPathUtilities.h on String
rdar://problem/18848175

Swift SVN r30507
2015-07-22 22:12:56 +00:00
David Farler
5eb9f396d6 Default removeFirst for Slice, ArraySlice
Add a default implementation for CollectionTypes where their SubSequence
== Self. That is, mainly, Slice and ArraySlice. This changes the slice's
view of, but not modifying or copying, the underlying collection.

rdar://problem/20302034

Swift SVN r30496
2015-07-22 08:07:37 +00:00
Dmitri Hrybenko
0525573de7 stdlib: use syntax sugar for Array
Swift SVN r30489
2015-07-22 04:16:22 +00:00
Dave Abrahams
417788892f [stdlibunittest] Suppress a warning
Swift SVN r30459
2015-07-21 21:22:23 +00:00
David Farler
ada08bdf2b SequenceType.split enhancements
- De-underscore the API that takes an equatable separator, add doc
  comment, and add a test for it.
- Add a test for the negative maxSplit case.
- Add lifetime tracker for isSeparator closure in the semantic test.

Swift SVN r30413
2015-07-20 21:34:19 +00:00
Dmitri Hrybenko
364176d007 stdlib: make crash tests more strict
Swift SVN r30397
2015-07-20 15:39:14 +00:00
Dmitri Hrybenko
08a84ca5a1 stdlib tests: simplify map() calls with currying
Swift SVN r30379
2015-07-19 01:49:10 +00:00
Dmitri Hrybenko
7fbfe24081 stdlib: Sequence tests: prefix test name with the type name
Swift SVN r30378
2015-07-19 01:22:11 +00:00
Dmitri Hrybenko
3ef09f3352 stdlib: make trap tests more strict
Swift SVN r30377
2015-07-19 01:22:10 +00:00
Dmitri Hrybenko
420337a5bf stdlib: move forEach() test to the SequenceType testsuite
Swift SVN r30376
2015-07-19 01:22:08 +00:00
David Farler
0d1b03086d Add slicing extensions to SequenceType and CollectionType.
rdar://problem/21663830

Add the following new requirements to SequenceType with default implementations:

- dropFirst(n)
- dropLast(n)
- prefix(n)
- suffix(n)
- split(n)

In addition, provide specialized default implementations of these for CollectionTypes with forward, bidirectional, and random-access Index types where possible.

Add the following new requirements to CollectionType with default implementations:

- prefixThrough(n)
- prefixUpTo(n)
- suffixFrom(n)
- split() // isSeparator closure

Add the following convenience APIs:

- dropFirst() -> calls dropFirst(1)
- dropLast() -> calls dropLast(1)

Add a tentative underscored API:

- split() // takes Equatable separator.

Some APIs have undefined behavior when creating slices where the endpoints go beyond the bounds of the underlying collection. This will be fixed later by trapping creation of slices with invalid indices (rdar://problem/21822657).

Swift SVN r30371
2015-07-18 06:51:22 +00:00
Dave Abrahams
e3bcd90d70 [stdlibunittest] Warning suppression
Swift SVN r30360
2015-07-18 02:58:35 +00:00
Joe Groff
6608221a72 stdlib: Remove _UnitTestArray.
rdar://problem/20246497

Swift SVN r30348
2015-07-18 00:14:28 +00:00
Jordan Rose
aac0342e48 [stdlib] More type annotations to reduce compile time.
The big one, though, is the use of 'lazy' in _masterThreadOneTrial.
Removing it takes the function from 62s to 2s on my machine.
That's rdar://problem/20875936.

Swift SVN r30292
2015-07-17 00:22:03 +00:00
Dmitri Hrybenko
e5e4335fad stdlib: Slice: trap on out-of-bounds indices
rdar://21822657

Swift SVN r30269
2015-07-16 18:22:40 +00:00
David Farler
6099e156eb Add RangeReplaceableCollectionType.removeFirst
Add requirements and default implementations for removeFirst() and
removeFirst(n: Int).

rdar://problem/21844880

Swift SVN r30256
2015-07-16 07:47:06 +00:00
David Farler
86f1a7088b Review: Rename SequenceType.forEach parameter to 'body'
No functional change.

Swift SVN r30249
2015-07-16 04:07:17 +00:00
David Farler
91b89b8956 Add SequenceType.forEach requirement and default implementation
rdar://problem/21663830

Swift SVN r30236
2015-07-15 23:36:23 +00:00
Dave Abrahams
34bc4068d6 [stdlibunittest] Suppress some pesky warnings
Swift SVN r30212
2015-07-15 05:45:46 +00:00
Joe Groff
f739f85137 StdlibUnittest: Keep qualified type names in failure output.
The unambiguous qualification is likely desirable to someone figuring out why their tests failed.

Swift SVN r30170
2015-07-13 22:31:37 +00:00
Dave Abrahams
7221cd84df [stdlibunittest] Add expectations to TypeIndexed
Swift SVN r30138
2015-07-13 06:40:44 +00:00
Dmitri Hrybenko
4cfe818c43 StdlibUnittest: extract collection tests into a reusable generic testsuite
Swift SVN r30124
2015-07-12 01:04:38 +00:00
Dmitri Hrybenko
1d38db56da StdlibUnittest: add {Minimal|Default}***MutableCollection types
Swift SVN r30115
2015-07-11 08:48:38 +00:00
Dave Abrahams
069ba3ecf6 [stdlibunittest] Gyb-away code duplication in logging wrappers
Swift SVN r30110
2015-07-11 04:02:11 +00:00
Dave Abrahams
645e62769f [stdlibunittest] LoggingCollection should log *all* SequenceType operations.
Swift SVN r30108
2015-07-11 03:25:40 +00:00
Dave Abrahams
9d07acd368 [stdlib] SequenceType's _initializeTo should return the end position
Otherwise, the length of the sequence is in principle lost.  If you know
you have a sequence of less than 100 elements, you still want to know
exactly how many elements you initialized from it.

Swift SVN r30104
2015-07-11 01:43:27 +00:00
Dave Abrahams
6ab88e2ade [stdlibunittest] Add/use checkRandomAccessIndex
Swift SVN r30077
2015-07-10 18:51:19 +00:00
Dave Abrahams
c1f371a5b8 [stdlibunittest] Add checkStrideable
Also, apply it, in a rudimentary way, to our floating point types.

Swift SVN r30068
2015-07-10 14:27:11 +00:00
Dave Abrahams
c2b3005dba [stdlibunittest] Add/use checkComparable that tests laws
Swift SVN r30042
2015-07-09 21:40:58 +00:00
Dave Abrahams
7a614f76fc [stdlibunittest] Add/Use checkBidirectionalIndex
Swift SVN r30022
2015-07-09 17:10:27 +00:00
Dave Abrahams
76ec395dae [stdlibunittest] WIP Adding axiom checking
Check that the expected laws hold for models of Equatable, Hashable,
Incrementable, and ForwardIndexType.

Swift SVN r29988
2015-07-08 20:04:37 +00:00
Dave Abrahams
ef198daa2b [stdlibunittest] Finish threading new trace facility through
Swift SVN r29955
2015-07-08 02:52:27 +00:00