Commit Graph

1324 Commits

Author SHA1 Message Date
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
eec59477ae stdlib: Factor _copy*ToNativeArrayBuffer into a general-purpose "builder" for ContiguousArrayBuffer.
This makes the code for efficiently initializing array buffers in-place more accessible to the rest of the standard library, and should also provide a performance boost for _copySequenceToNativeArrayBuffer, which had been implemented as a naive append loop, by handling reallocating the buffer when necessary when initializing from a sequence that underestimates its count.

Swift SVN r30793
2015-07-30 05:28:30 +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
ce94497a57 stdlib: Mark short-circuit operators as 'rethrows'.
Swift SVN r30791
2015-07-30 05:28:23 +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
Dave Abrahams
1a01fee74a [stdlib] Strip comments and other distractions from unavailable APIs
Swift SVN r30777
2015-07-29 20:30:34 +00:00
Dave Abrahams
b698a088c7 [stdlib] Add new print functions (underscored)
Getting these ready for API review.

Swift SVN r30776
2015-07-29 20:30:32 +00:00
Dave Abrahams
0711371641 [stdlib] Update FIXMEs to place the blame correctly
Swift SVN r30752
2015-07-29 03:30:16 +00:00
Dave Abrahams
b6d4007b55 [stdlib] Fix incorrect comment
Swift SVN r30750
2015-07-29 02:04:10 +00:00
Dmitri Hrybenko
21b7dcf61e stdlib: mark one of the global sort() functions unavailable
Others were already unavailable, this is the last one.

rdar://22022419

Swift SVN r30711
2015-07-28 03:19:08 +00:00
Jordan Rose
b378a5043f [stdlib] Dictionary and Set's removeAtIndex should return the element.
For Dictionary, that's a (KeyType, ValueType) pair. For Set, that's just
the set element type. This is more consistent with the removeAtIndex on
RangeReplaceableCollectionType (which Dictionary and Set don't conform to).

rdar://problem/20299881

Swift SVN r30696
2015-07-27 20:32:55 +00:00
Dave Abrahams
f37d607a13 Revert "stdlib: remove FlattenCollection -- it does not model CollectionType properly."
Actually we hadn't nailed down the indexing model sufficiently; now we
have.

This reverts r30617.

Swift SVN r30694
2015-07-27 19:33:15 +00:00
Dmitri Hrybenko
a112e54b5c stdlib: Underscore global functions that operate on
_SwiftNSOperatingSystemVersion

rdar://20919984

Swift SVN r30693
2015-07-27 19:31:30 +00:00
Dmitri Hrybenko
6ec144738e stdlib: Add more APIs to _stdlib_AtomicInt
Requested in rdar://17171396

Swift SVN r30687
2015-07-27 04:18:13 +00:00
Dmitri Hrybenko
c6de78bc53 stdlib: add fixit-based migrations for appendContentsOf and insertContentsOf
Swift SVN r30618
2015-07-25 02:47:20 +00:00
Dmitri Hrybenko
78222237e0 stdlib: remove FlattenCollection -- it does not model CollectionType properly.
An index of a FlattenCollection is composed of two: an index to the
current chunk and an index within that chunk.  So you take the
startIndex, and advance it to the second chunk; call the result idx1.
You take startIndex again, and advance it the same number of steps; call
the result idx2:

let idx1 = flatMapCollection.startIndex.advancedBy(10)
let idx2 = flatMapCollection.startIndex.advancedBy(10)

idx1 and idx2 have to compare equal according to collection and index
axioms.  But this can't be cheaply implemented.  Every index contains an
index into the inner collection.  So indices into two collections with
the same elements have to compare equal even though the collections
don't have any common history, they were merely created using the same
sequence of steps.

What currently happens is that you get random results depending on the
underlying collection kind.

rdar://21989896

Swift SVN r30617
2015-07-25 02:18:13 +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
Jordan Rose
e77e0587c7 Enforce maximum allowed access for extensions with 'where' clauses.
Otherwise, we end up with declarations with public access that do not
have public 'self' types. These declarations can then be used by other
modules, which may end up trying to access non-external symbols.

This closes a loophole currently in use by the standard library, so
the '_prext_ReverseIndexType' and '_ReverseCollectionType' protocols
become public for now. In order to keep the API impact minimized,
extensions involving these protocols now extend them directly, so that
all of the "private" stuff shows up in one place in the generated
interface. This is not a long-term solution, but it's no worse than
the rest of the underscore rules in the standard library.

rdar://problem/21380336 tracks relaxing access restrictions for protocol
conformances when the witnesses come from a different type, like a
protocol extension. This requires some SILGen work to do correctly.

Finishes rdar://problem/21559986

Swift SVN r30612
2015-07-25 01:06:50 +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
Joe Groff
b0ec0d6da4 Revert "stdlib: Mark many higher-order function interfaces as 'rethrows'."
This reverts commit r30597, to help detangle it from other potentially-breaking changes that landed
on the bots simultaneously.

Swift SVN r30602
2015-07-24 23:31:59 +00:00
Joe Groff
4be02cab5b 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.

Swift SVN r30597
2015-07-24 22:52:23 +00:00
Dave Abrahams
897c34aec9 [stldib] Add missing comments for new reverse collections
Also re-order some decls

Swift SVN r30596
2015-07-24 22:50:50 +00:00
Dave Abrahams
c46b80d6f4 [stdlib] _prext_reverse -> method
Swift SVN r30593
2015-07-24 22:14:38 +00:00
Dmitri Hrybenko
5d22239652 stdlib: fix warnings
Swift SVN r30566
2015-07-24 05:27:56 +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
Dave Abrahams
76c6cf59ab [stdlib] Add missing public inits to LazyMapXXX
Swift SVN r30562
2015-07-24 04:29:07 +00:00
Dave Abrahams
ea8c410509 [stdlib] Use new lazy collections in implementations
They pass various operations through to the base
collection (e.g. LazyMapCollection's .count) and thereby avoid taking
the potentially-slower path through the default implementation.

Swift SVN r30554
2015-07-23 21:02:45 +00:00
Dave Abrahams
55b049500a [stdlib] Eliminate redundant eager "filter" implementation
Because we're only allowed a single pass with the closure, the one in
SequenceType is just as good as the one in CollectionType.

Swift SVN r30553
2015-07-23 21:02:44 +00:00
Dave Abrahams
fde48e0b57 [stdlib] "count" property passthrough for LazyMapCollection
Swift SVN r30552
2015-07-23 21:02:43 +00:00
Dave Abrahams
878445a72a [stdlib] Use a nicer generic parameter name...
...with no trailing "_"

Swift SVN r30551
2015-07-23 21:02:42 +00:00
Dave Abrahams
9421aa8db7 [stdlib] Expose base of the new reverse indices
Swift SVN r30550
2015-07-23 21:02:41 +00:00
Dmitri Hrybenko
ce71984eb8 stdlib: add the missing initializer to NonObjectiveCBase
rdar://20321708

Swift SVN r30527
2015-07-23 05:21:43 +00:00
David Farler
9aa5ff1743 Clarify SequenceType.forEach's doc comment
- Add notes for the differences between forEach and for-in loops
- Use TSPL terminology

Swift SVN r30511
2015-07-22 22:56:14 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Slava Pestov
05d695f192 stdlib: Fix Linux build breakage from r30493
Swift SVN r30502
2015-07-22 20:38:02 +00:00
Dave Abrahams
7578e2d568 [stdlib] underscore names that were prematurely not underscored
They need to go through API review first.

Swift SVN r30497
2015-07-22 15:43:39 +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
Slava Pestov
56cde6c8ec stdlib: Another simplification in HashedCollections.swift.gyb
Review feedback from Dmitri.

Swift SVN r30495
2015-07-22 07:01:48 +00:00
Slava Pestov
3175c90eac stdlib: Clean up HashedCollection FIXMEs now that generic subclasses of @objc classes work
Fixes <rdar://problem/16824792>.

Swift SVN r30493
2015-07-22 06:34:13 +00:00
Dmitri Hrybenko
0525573de7 stdlib: use syntax sugar for Array
Swift SVN r30489
2015-07-22 04:16:22 +00:00
Joe Groff
eaa1ef8e35 stdlib: Fix sign bug in Float*(integerLiteral:).
Int is signed, not unsigned, so should be converted using sitofp. Fixes rdar://problem/20467684.

Swift SVN r30487
2015-07-22 02:44:37 +00:00
Dave Abrahams
524810f579 [stdlib] Documentation touch-ups for LazyCollection
Swift SVN r30472
2015-07-21 22:35:40 +00:00
Dave Abrahams
6be395d638 [stdlib] Documentation touch-ups for flatten
Swift SVN r30471
2015-07-21 22:35:39 +00:00
Dave Abrahams
b184e6df59 [stdlib] Document complexity of flatMaps
Swift SVN r30470
2015-07-21 22:35:38 +00:00
Ted Kremenek
771761f9f6 Re-apply "stdlib: eliminate unused typealias and tidy up the doc comment""
This reverts commit r30468.

It's not clear if the original commit caused a build regression, but it appears to be resolved now.

Swift SVN r30469
2015-07-21 22:30:59 +00:00
Ted Kremenek
3f41e175b3 Revert "stdlib: eliminate unused typealias and tidy up the doc comment"
This reverts commit r30458.

This is breaking test 'Swift :: stdlib/Algorithm.swift.gyb'

Swift SVN r30468
2015-07-21 22:10:21 +00:00
Dave Abrahams
2088a71259 [stdlib] Document the lazy flatMaps
Swift SVN r30467
2015-07-21 22:01:24 +00:00
Dave Abrahams
a10ef17759 [stdlib] Document flatMap in terms of map + flatten
Swift SVN r30466
2015-07-21 22:01:23 +00:00
Dave Abrahams
e52fb0694d [stdlib] Unbalanced braces in gyb'd source makes my indentation unhappy.
Swift SVN r30465
2015-07-21 22:01:23 +00:00