Commit Graph

7762 Commits

Author SHA1 Message Date
David Farler
5091dc244d Really fix the Optional map/flatMap mismerge
Swift SVN r31070
2015-08-07 08:20:27 +00:00
David Farler
697d0dbd4f Build fix: mismerge in Optional.swift
Swift SVN r31069
2015-08-07 07:10:45 +00:00
David Farler
4848235c7f Rename Optional type parameter from 'T' to 'Wrapped'.
rdar://problem/21970065

Swift SVN r31068
2015-08-07 06:17:20 +00:00
David Farler
9aa7663ad3 Always debugPrint containers' elements
rdar://problem/19312992

Swift SVN r31067
2015-08-07 06:14:19 +00:00
Dmitri Hrybenko
255d2229c7 stdlib: remove erroneous @warn_unused_result annotations
Swift SVN r31050
2015-08-06 15:54:47 +00:00
Dmitri Hrybenko
dd3194a18c stdlib: adopt @warn_unused_result
rdar://20957486

Swift SVN r31048
2015-08-06 14:53:18 +00:00
Dave Abrahams
f59279dc31 [stdlib] Fix a couple of availability message
Swift SVN r31025
2015-08-05 20:02:34 +00:00
Dmitri Hrybenko
827224f146 stdlib: clarify the behavior of sequences and for loops
This is not a new rule, this is just a consequence (although a
non-trivial one) of existing rules.

Swift SVN r31024
2015-08-05 19:06:10 +00:00
Arnold Schwaighofer
e0d069a0e0 stdlib: Call _print_unlocked directly in String.init
Then we can get rid of the specialized print function.

Swift SVN r31022
2015-08-05 14:44:13 +00:00
Jordan Rose
54cca1a2fa Restore fully-general signature for IntervalType.overlaps.
rdar://problem/22085137

Swift SVN r31010
2015-08-04 21:57:03 +00:00
David Farler
8eec4b6e13 RangeReplaceable: document and enforce count >= n for removeFirst(n)
Swift SVN r31001
2015-08-04 19:41:14 +00:00
Arnold Schwaighofer
9c77c05696 stdlib: Call a private specialized version in String.init
The print abi changed so that there is no longer a way to print one item to a
stream without going through a vararg array. We call the print function in a
String initializer (e.g for string interpolation) incurring unnecessary
overhead. Use an internal specialized version of print instead.

rdar://22133281

Swift SVN r31000
2015-08-04 19:19:50 +00:00
Arnold Schwaighofer
8c112d1fea stdlib: Always inline the _UnsafePartiallyInitializedContiguousArrayBuffer builder functions
For performance reasons.

This should now truly have recovered PrimeNum's performance at -O.

rdar://22126579

Swift SVN r30988
2015-08-04 07:49:40 +00:00
David Farler
313a4c93c6 Review: Index protocol extensions
- Add Strict/Defaulted Index types to StdlibUnittest
- Test whether a random access index calls its more efficient
  customization by tracking successor calls.
- Fix the RandomAccessIndex.advancedBy(n, limit:) API by de-underscoring
  the limit parameter
- Inline some internal transparent default implementations to their only
  call site
- Attach _RandomAccessAmbiguity type to RandomAccessIndex

rdar://problem/22085119

Swift SVN r30979
2015-08-04 03:13:14 +00:00
Jordan Rose
03e3dc2e2d stdlib: Workaround for IntervalType.overlaps to avoid a SIL parser error.
The parse_stdlib tests choke on the constraints that were there previously,
so weaken the API to only work on intervals of the same type for now.

rdar://problem/22126470

Swift SVN r30977
2015-08-04 02:10:49 +00:00
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00
Jordan Rose
c5bc10a597 stdlib: Update a comment I missed on Strideable.
Swift SVN r30975
2015-08-04 01:34:38 +00:00
Jordan Rose
83e2e0bbb2 Move the 'stride' family into methods on Strideable.
Part of the Protocol Extensions TLF.

rdar://problem/22085144

Swift SVN r30974
2015-08-04 01:32:41 +00:00
Jordan Rose
1ee08fe92a stdlib: Move 'overlaps' into a method on IntervalType.
Part of the Protocol Extensions TLF.

rdar://problem/22085137

Swift SVN r30973
2015-08-04 01:32:36 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
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
Jordan Rose
a41c1fe7cb [stdlib] Don't try to swap an element with itself in 'partition'.
(or in 'randomShuffle')

This violates our inout aliasing rules, and can cause a crash in certain
situations.

To try to prevent this in the future I've added a debugPrecondition check
to 'swap' that checks addresses. This will only catch inout violations
where neither argument uses writeback, and might some day be optimized
away. Right now, though, it does seem to catch some simple violations
(though not the one in the Radar), so hopefully it will at least help keep
us from introducing new problems.

rdar://problem/21780567

Swift SVN r30956
2015-08-03 19:51:29 +00:00
Dmitri Hrybenko
9a77d843da stdlib: update references to 'isEmpty' in comments
Swift SVN r30954
2015-08-03 19:22:57 +00:00
Michael Gottesman
3fe541625c Do not copy a SliceBuffer when we have the full native buffer. Just return it.
Fixes the RangeAssignment regression. Reviewed by Dmitri.

<rdar://problem/22078500> RangeAssignment regressions in r30794

Swift SVN r30925
2015-08-02 04:42:53 +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
d7caf06551 stdlib: rename generic parameter of _SliceBuffer from T to Element
Swift SVN r30901
2015-08-01 03:27:07 +00:00
Dmitri Hrybenko
d822a90ed4 stdlib: fix warnings
Swift SVN r30900
2015-08-01 02:59:43 +00:00
Dave Abrahams
7d5bb5f080 [stdlib] new print: move "toStream" argument to end
It reads more naturally to keep all the text arguments together.
One day maybe this will be a method on OutputStream, but probably not as
long as String conforms to it :-)

Swift SVN r30864
2015-07-31 20:19:49 +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
David Farler
034d0cfbf0 Fix three-way mid-air collision around Array buffers and RangeReplaceable tests
Swift SVN r30843
2015-07-31 04:43:03 +00:00
David Farler
f924e8e007 ArraySlice indexes no longer zero-based
ArraySlice indices now map directly onto the collection it is slicing
and maintains that mapping even after mutations.

Before:

var a = Array(0..<10)
var s = a[5..<10]
s.indices        // 0..<5
s[0] = 111
s                // [111, 6, 7, 8, 9]
s.removeFirst()
s.indices        // 1..<5

After:

var a = Array(0..<10)
var s = a[5..<10]
s.indices        // 5..<10
s[5] = 99
s                // [99, 6, 7, 8, 9]
s.removeFirst()
s.indices        // 6..<10

- Refactor some of the internals of the buffer types to make it easier
  to read and understand.
- Add Array, ArraySlice, and ContiguousArray to the test suite at the
  RangeReplaceable test entry points, subjecting them to the same tests
  as all of our collections.
- Update existing test expectations for the indexing changes.

rdar://problem/21866825

Swift SVN r30840
2015-07-31 03:25:29 +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
Dave Abrahams
d06a07897f [stdlib] Move _playgroundPrintHook into OutputStream
Makes for a simpler patch for the LLDB folk to apply

Swift SVN r30824
2015-07-30 23:39:47 +00:00
Dave Abrahams
b428dc8a6a [stdlib] wire _playgroundPrintHook into legacy print
Those LLDB peeps need it for testing

Swift SVN r30823
2015-07-30 23:39:46 +00:00
Dave Abrahams
c2ec35e168 [stdlib] Add _playgroundPrintHook
This hook gets all of the output for each print or debugPrint invocation
as a single blob.

Swift SVN r30818
2015-07-30 23:08:03 +00:00
Dave Abrahams
931fed01eb [stdlib] "end:" => "terminator:" in new print
API review seems to agree that's a better name choice.

Swift SVN r30809
2015-07-30 18:56:40 +00:00
Joe Groff
4cb34410fc stdlib: Don't reserve capacity for filter result array.
Swift SVN r30802
2015-07-30 17:07:37 +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
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