Commit Graph

3606 Commits

Author SHA1 Message Date
Maxim Moiseev
e868ca7035 [stdlib] Better BinaryInteger.signum and tests 2017-05-11 14:02:59 -07:00
Max Moiseev
a797b29c1c [stdlib] A more efficient implementation of signum for integer types 2017-05-11 14:02:59 -07:00
Ben Cohen
d95704128d revert changes to stdlib 2017-05-11 12:05:47 -07:00
Ben Cohen
c03b14e93f Revert "Merge pull request #9379 from airspeedswift/redundant-where"
95e9681d10
2017-05-11 11:43:54 -07:00
Michael Ilseman
f0abff5539 Revert "Merge pull request #9265 from milseman/tls_ftw"
This reverts commit 26f7659efe, reversing
changes made to 7b927e55e8.
2017-05-11 10:39:58 -07:00
practicalswift
b99c62b459 [gardening] Add missing copyright notice 2017-05-11 15:54:36 +02:00
Maxim Moiseev
31f7dfe475 [stdlib] Backward compatibility fix for a flatMap on [String] (#9466)
* [stdlib] Backward compatibility fix for a flatMap on [String]

Since String started to conform to Collection, the flatMap with a
sequence returning closure is now a better match that the one that
relies on the optional promotion in this code:

[""].flatMap { $0 }

which results in the default type of this expression changing from
[String] to [Character].

Restoring the old behavior in Swift 3 mode by adding a very explicit
overload.

Fixes: <rdar://problem/32024978>

* [stdlib] Fixing another compatibility issue with [String].flatMap
2017-05-11 04:05:54 -07:00
Michael Ilseman
26f7659efe Merge pull request #9265 from milseman/tls_ftw
[stdlib] Unicode 9 and Thread Local Storage
2017-05-10 20:29:49 -07:00
Max Moiseev
109c213358 [stdlib] Prioritizing non-failing String.init_:String) 2017-05-10 15:58:00 -07:00
Max Moiseev
cce957ba98 [stdlib] Removing the StringProtocol.init<T: StringProtocol> 2017-05-10 15:58:00 -07:00
Michael Ilseman
75741a9dde [stdlib stubs] Fix up Linux build to know about pthread types.
Adds in Linux platform support for our pthread TLS. Replace usage of
PTHREAD_KEYS_MAX with a sentinel value, as it's tricky to define
cross-platform and was only lightly used inside sanity checks.
2017-05-10 15:23:12 -07:00
Michael Ilseman
18104c616c [stdlib] Unicode 9 here we come: use ICU for grapheme breaking
Use UBreakIterators to perform grapheme breaking. This gives Unicode 9
grapheme breaking (e.g. family emoji) and provides a means to upgrade
to future versions. It also serves as a model for how to serve up
other advanced functionality in ICU to users.

This has tricky performance implications. Some things are faster and a
number of cases are slower. But, careful use of ICU can help mitigate
and amortize these costs. In conjunction with more early detection of
fast paths, overall grapheme breaking for the average user should be
much faster than in Swift 3.

NOTE: This is incomplete. It currently falls back on the legacy tries
for some bridged strings. There are many potential directions for a
general solution, but for now we'll be interatively adding support for
more and more special cases.
2017-05-10 15:21:08 -07:00
Michael Ilseman
0c0d08369d [stdlib] Introduce Thread Local Storage
Introduces a _ThreadLocalStorage struct to hold thread-local, but
global resources. Set it up to host a UBreakIterator and a cache key
for resetting text.

UBreakIterators are extremely expensive to create on the fly, so we
store one for each thread. UBreakIterators are also expensive to bind
to new text, so we cache the text it's currently bound to in order to
help avoid it.

The struct can be expanded with more functionality in the future, but
the standard library should only ever use a single key, and thus
everything should go on this struct. The _ThreadLocalStorage struct is
not meant to be copyable, creatable (by anyone else except the
once-per-thread initialize routine), and should accessed through the
pointers it provides.

Future immediate directions could include cashing multiple
UBreakIterators (e.g. avoid a text reset for mutual character
iteration patterns, etc).

Test added in test/stdlib/ThreadLocalStorage.swift.
2017-05-10 15:21:08 -07:00
Michael Ilseman
50beaedf7d [stdlib] Add ICU.swift, to host ICU helper functionality 2017-05-10 15:21:07 -07:00
Michael Ilseman
4a17449d02 [stdlib] Shims for UBreakIterator and thread local storage.
Introduce shims for using UBreakIterators from ICU. Also introduce
shims for using thread local storage via pthreads.

We will be relying on ICU and UBreakIterators for grapheme
breaking. But, UBreakIterators are very expensive to create,
especially for the way we do grapheme breaking, which is relatively
stateless. Thus, we will stash one or more into thread local storage
and reset it as needed.

Note: Currently, pthread_key_t is hard coded for a single platform
(Darwin), but I have a static_assert alongside directions on how to
adapt it to any future platforms who differ in key type.
2017-05-10 15:21:07 -07:00
Nate Cook
f030652cc9 Merge pull request #9462 from natecook1000/nc-dict-keys-compat
[stdlib] Provide Swift 3 compatible Dict.keys/values
2017-05-10 15:37:39 -05:00
Nate Cook
822fec7b2b [stdlib] Make new Dict filter closure type match sequence 2017-05-10 11:24:37 -05:00
Nate Cook
44b12db536 [stdlib] Maintain old keys and values types in Swift 3 mode 2017-05-10 10:45:05 -05:00
swift-ci
d2c8d9c58b Merge pull request #9423 from apple/direct-transcoding 2017-05-09 21:27:10 -07:00
Dave Abrahams
c616b180ce [stdlib] Revise comments per proposed revisions to SE-0163 2017-05-09 18:37:20 -07:00
practicalswift
8c40c65c80 [gardening] Fix typos. 2017-05-09 21:50:04 +02:00
Dave Abrahams
c64534a873 [stdlib] API adjustments in preparation for proposal update 2017-05-09 11:19:24 -07:00
Dave Abrahams
e7b32f9dc9 [stdlib] UnicodeEncoding: hide/internalize APIs we're not sure about
The best high-level APIs for decoding/transcoding are still under active
investigation.  It's likely we want more views.  Therefore, leave
de-underscored/public only the lowest-level APIs for now.
2017-05-09 10:20:29 -07:00
swift-ci
e04e7cea9c Merge pull request #9412 from apple/direct-transcoding 2017-05-09 07:43:13 -07:00
Dave Abrahams
fd8cfea3ac [stdlib] String initialization with encoding and CString interop 2017-05-08 19:50:38 -07:00
swift-ci
40c05b3624 Merge pull request #9378 from airspeedswift/lazy-constraints 2017-05-08 18:21:09 -07:00
Max Moiseev
e6b0e3c7fb [stdlib] Removing the deprecated flatMap overload
The following code behaves incorrectly due to the presence of this
overload.

let a: Int = 1
let b: Int? = 2
let c: Int? = nil
let result: [Any] = [a, b, c].flatMap { $0 }

Fixes: <rdar://problem/31910642>
2017-05-08 11:26:31 -07:00
Dave Abrahams
cb5b5bad7c [stdlib] Clean up anti-idiomatic generic 2017-05-08 07:59:16 -07:00
Dave Abrahams
38b902d461 [stdlib] add Unsafe[Mutable]Pointer._max, unbounded buffer pointers 2017-05-08 07:58:18 -07:00
Dave Abrahams
9363b482db [stdlib] add _SentinelCollection/_SentinelIterator 2017-05-08 07:57:42 -07:00
ben-cohen
b6250eee15 fix indentation error 2017-05-08 07:47:47 -07:00
Dave Abrahams
c5d6880053 [stdlib] Add ASCII UnicodeEncoding, drop uses of legacy codecs
Preparation for new C-string interop.
2017-05-07 20:43:44 -07:00
Dave Abrahams
ca576bb9bc [stdlib] Add unconditional encode/transcode 2017-05-07 20:43:44 -07:00
Dave Abrahams
f4610e1638 [stdlib] encode/transcode => [encode/transcode]IfRepresentable...
...to make room for a more useful encode/transcode that inject replacement
characters when encoding fails.
2017-05-07 20:43:44 -07:00
ben-cohen
e4af80d39c Remove redudant constraints to supress warnings 2017-05-07 11:30:01 -07:00
ben-cohen
faba513f9e Constrain Lazy.Elements.Element == Element 2017-05-07 10:18:58 -07:00
Ben Cohen
f6f3ed0fe7 Add Collection constraints via protocol where clauses (#9374) 2017-05-07 08:55:48 -07:00
Dave Abrahams
8d888b5403 Merge pull request #9375 from apple/direct-transcoding
Direct transcoding
2017-05-07 06:39:18 -07:00
Dave Abrahams
776e0a632a [stdlib] Make a generic more idiomatic
NFC
2017-05-06 19:29:29 -07:00
Dave Abrahams
fc35acaac7 [stdlib] Every UnicodeCodec is a UnicodeEncoding 2017-05-06 19:26:58 -07:00
swift-ci
79258866a2 Merge pull request #9354 from apple/failable-unicode-encoding 2017-05-06 17:31:14 -07:00
Dave Abrahams
e08fd9af46 [stdlib] Direct unicode transcoding
without passing through decoded UnicodeScalars.
2017-05-06 16:58:08 -07:00
Dave Abrahams
796d004fd0 [stdlib] Allow Unicode Encoding to fail
This is needed for encodings such as Latin-1
2017-05-06 16:53:35 -07:00
swift-ci
4b69240301 Merge pull request #9372 from airspeedswift/drop-nuffing 2017-05-06 14:11:13 -07:00
ben-cohen
02562c3eb0 Substring.index(_:offsetBy:) is allowed offset of 0 2017-05-06 13:34:27 -07:00
Max Moiseev
178b9f0b44 [stdlib] Adding bounds check in a.subscript(Index) fast path
UnsafeBufferPoiunter subscript used in the fast path only checks bounds
in Debug mode, therefore extra checks are needed.

Addresses: <rdar://problem/31992473>
2017-05-05 15:26:24 -07:00
Dave Abrahams
5f21813ea1 Merge pull request #9340 from apple/integrate-utf32
[stdlib] Implement New UTF32 transcoding
2017-05-05 15:08:49 -07:00
Max Moiseev
2d49d17a75 [stdlib] Addressing the benchmark regression 2017-05-05 10:51:32 -07:00
Max Moiseev
47875fc4e0 [stdlib] Removing a few harmful overloads of <
At some point during the implementation of integer protocols these
overloads were necessary to make expressions like `i32 < 0` be faster
and unambiguous.
Now they are no longer necessary, and also cause problems for
expressions like `(u64 - u64) < u64`, where they cause the deprecated
`func - (Strideable, Strideable) -> Stride` be used, which is wrong, as
it will trap in many cases, where `func - (UInt64, UInt64) -> UInt64`
would not.

Fixes: <rdar://problem/31909031>
2017-05-05 10:51:32 -07:00
Dave Abrahams
dfd9eb34cf [stdlib] Implement New UTF32 transcoding 2017-05-05 09:53:44 -07:00