Commit Graph

362 Commits

Author SHA1 Message Date
Dmitri Hrybenko
3f7d64c532 Diagnose invalid arguments for '#if _runtime()'
rdar://problem/20117677

Swift SVN r31336
2015-08-19 16:55:39 +00:00
David Farler
9e4d52c9cb Reinstate watchOS and other SDK overlays to build against the public SDKs.
Un-revert the below commits with the following addition:
add declarations for posix_spawn related APIs to SwiftPrivateDarwinExtras.
posix_spawn-related APIs aren't available in the public SDKs, so force past
the availability by creating our own stubs in the internal DarwinExtras
library.

r31244, r31245

CMake: build all platforms except watchOS using the public SDK

Covers rdar://problem/21145996.
A step towards rdar://problem/21099318.

Switch SDK overlays to use the public SDK

I had to cut the dependency on CrashReporterClient.h and reimplement
some of that code inline in the Swift runtime.  This shoud be OK (even
though not very clean), since the layout of CrashReporter sections is
ABI.

rdar://21099318

Swift SVN r31252
2015-08-14 22:09:49 +00:00
Dmitri Hrybenko
8311c05461 stdlib: add a default implementation for MutableCollection.subscript().set
rdar://20722366

Swift SVN r31241
2015-08-14 03:12:23 +00:00
Dave Abrahams
146d2daa9d [stdlib] Add missing nullability to reflected NSString API
getBytes still lacks the ability to take an optional buffer, but Ali
agrees that we can leave that off for this release in light of the fact
that we have lengthOfBytesUsingEncoding.

Swift SVN r31223
2015-08-13 20:11:40 +00:00
Dmitri Hrybenko
33631ca9c4 stdlib: Fix a bug in split()
split() used to drop the tail of the sequence under certain
circumstances.

rdar://22200821

Swift SVN r31207
2015-08-13 05:31:07 +00:00
Dmitri Hrybenko
8a435da63b Un-XFAIL tests for partition()
The underlying bug is fixed now.

rdar://21780567

Swift SVN r31196
2015-08-13 01:21:25 +00:00
Dmitri Hrybenko
ee20926b20 stdlib: rename join() to joinWithSeparator()
rdar://22022419, rdar://21474222

Swift SVN r31188
2015-08-12 21:16:38 +00:00
Dmitri Hrybenko
dd3194a18c stdlib: adopt @warn_unused_result
rdar://20957486

Swift SVN r31048
2015-08-06 14:53:18 +00:00
Mish Awadah
61645429a0 [castle] Correct byte transfer logic for large transfers.
This commit addresses:
<rdar://problem/22121657> stdlib/Slice.swift.gyb test failing on swift_tools-RA_stdlib-RDA_test-ios_device since #1325

Swift SVN r30997
2015-08-04 17:57:13 +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
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
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
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