Commit Graph

3606 Commits

Author SHA1 Message Date
Max Moiseev
fa0904f1e5 [stdlib] Adding operator overloads on concrete integer types
It looks like the compiler is having troubles with the pattern when the
non-mutaing operator is defined on the protocol, and delegates to the
mutating version, that is provided by the concrete type. Adding similar
definitions of non-mutating operators to concrete types significantly
speeds up the typechecking of complex expressions, like the one in
the ByteSwap benchmark.
2017-05-17 15:56:17 -07:00
Maxim Moiseev
8876655f6b [stdlib] Reverting the String.init?(_: String) behavior (#9659) 2017-05-17 13:56:15 -07:00
Nate Cook
c8f8e59b7e Merge pull request #9698 from natecook1000/nc-fixes-75-2
[stdlib] Documentation revisions
2017-05-17 15:00:09 -05:00
Maxim Moiseev
a2a4a52bdf [stdlib] SignedNumber to refine Comparable in Swift 3 mode (#9668)
Fixes: https://bugs.swift.org/browse/SR-4899
2017-05-17 12:43:00 -07:00
Dave Abrahams
4db3509ad6 [stdlib] A Character's buffer should only contain 1 grapheme
This speeds up construction of a String from large Character representations,
and various other operations that would otherwise require additional grapheme
breaking just to interpret the Character.
2017-05-17 10:06:35 -07:00
Nate Cook
817a1efa3b [stdlib] Documentation revisions
- remove additional 'characters' references from String docs
- improved language around escaping pointer arguments
- key path type abstracts
- codable type abstract revisions
- a few more NSString API fixes
2017-05-17 11:58:08 -05:00
Michael Ilseman
ebe391cf5d [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-16 20:30:02 -07:00
Michael Ilseman
97511d65bf [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-16 20:29:21 -07:00
Michael Ilseman
973b5aed54 [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-16 20:29:21 -07:00
Michael Ilseman
dfdcd0f473 [stdlib] Add ICU.swift, to host ICU helper functionality 2017-05-16 20:29:18 -07:00
Michael Ilseman
5eb5e34897 [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-16 20:28:31 -07:00
Dave Abrahams
ef5d37c4fa [stdlib] Character.unicodeScalars 2017-05-16 14:29:55 -07:00
Roman Levenstein
34ad596693 Merge pull request #9627 from swiftix/is-same-metatype-builtin
Add a new builtin called is_same_metatype for checking the equality between metatypes
2017-05-16 09:13:03 -07:00
Joe Groff
e8e4f8b6af Hide the swift_getKeyPath entry point from the standard library API.
It's intended to be used as a runtime entry point only. rdar://problem/32200848
2017-05-15 16:24:41 -07:00
Roman Levenstein
d522618bac Add a new builtin called is_same_metatype for checking the equality between metatypes
Having such a builtin makes it easier for the optimizer to reason about what is actually happening.
I plan to add later some optimizations which can optimize pieces of code dominated by such a check.
2017-05-15 16:21:09 -07:00
swift-ci
a61b981cd9 Merge pull request #9610 from moiseev/no-init 2017-05-15 12:04:22 -07:00
swift-ci
7fffc6036a Merge pull request #9604 from mattrajca/master 2017-05-15 10:52:58 -07:00
practicalswift
aae419ad30 [gardening] Fix word processing artefacts 2017-05-15 11:30:25 +02:00
Matt Rajca
c4736ee44b Update example for Unmanaged.toOpaque so it compiles with Swift 3
We need an explicit cast to `CFString` and assigning a string to a variable of type `CFString` is not sufficient.
2017-05-14 21:07:49 -07:00
ben-cohen
efd4edf486 Restore @inline(__always) on Collection.first 2017-05-14 14:59:48 -07:00
Michael Ilseman
fb5734c24f Merge pull request #9575 from milseman/unihan_fasterhan
[stdlib] String: Walk Chinese/Japanese faster: 2x/4x forwards/backwards
2017-05-14 13:50:15 -07:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
Max Moiseev
0a466e3ca0 Revert "[stdlib] Implementing copy constructors for integer types"
This reverts commit 3f0d1e61aa.

The copy constructors don't really solve any problems, but produce extra
work for the overload resolution.
2017-05-13 12:27:43 -07:00
Max Moiseev
12f8b390c1 [stdlib] Mark String.init?(_: String) obsoleted in Swift 4
It is still possible to get the same behavior by providing an explicit
type context, or in a generic code, but otherwise, `String("")!` will
not compile.
2017-05-13 11:45:26 -07:00
Nate Cook
dafe368220 Address @dabrahams’s feedback 2017-05-13 12:25:42 -05:00
Nate Cook
f650e0a7da [stdlib] String and range expressions
* finish string documentation revisions
* revise examples throughout to use range expressions instead of e.g.
  prefix(upTo: _)
2017-05-13 10:06:12 -05:00
Nate Cook
6dd52c5f20 [stdlib] Documentation for partial ranges and operators 2017-05-13 10:06:09 -05:00
Nate Cook
1b8d982f98 [stdlib] Miscellaneous documentation revisions
* documented swap(_:_:) and MutableCollection.swapAt(_:_:)
* clarifications and fixes elsewhere
2017-05-13 10:06:09 -05:00
Nate Cook
7fa74f590d [stdlib] Documentation revisions for string + ranges
* removing .characters from examples
* beginning new String doc revisions
* improvements to the String Foundation overlay docs
* minor revisions elsewhere
2017-05-13 10:06:05 -05:00
Nate Cook
7ec9e95b49 [stdlib] Documentation revisions for numeric types
* abstracts for integer types
* fixed discussions for floating-point operators
2017-05-13 10:06:00 -05:00
Dave Abrahams
4dee6ead5c [stdlib] Provisional c[...] syntax while we await language features 2017-05-12 22:14:17 -07:00
swift-ci
5d034a2f71 Merge pull request #9568 from apple/stdlib-coding-convention 2017-05-12 21:43:48 -07:00
Dave Abrahams
dfd967281b [stdlib] 80 columns and other coding convention violations 2017-05-12 20:48:35 -07:00
Max Moiseev
f8bb0d88d7 Revert "[stdlib] Removing a String.init?(_: String), non-failable is enough"
This reverts commit 46415e7dbd.
2017-05-12 20:47:34 -07:00
Max Moiseev
6e3ae3aa4e [stdlib] Disambiguating count in Character._SmallUTF's 2017-05-12 17:37:04 -07:00
Max Moiseev
3f0d1e61aa [stdlib] Implementing copy constructors for integer types 2017-05-12 17:37:04 -07:00
swift-ci
00392ecb53 Merge pull request #9553 from moiseev/covariance-ftw 2017-05-12 15:25:49 -07:00
Max Moiseev
46415e7dbd [stdlib] Removing a String.init?(_: String), non-failable is enough 2017-05-12 14:48:30 -07:00
swift-ci
2df2c6218c Merge pull request #9547 from moiseev/remove-files 2017-05-12 13:31:30 -07:00
Dave Abrahams
2cb11675cf Merge pull request #9531 from apple/core-team-resolution-2017-05-10.1
Implementing resolutions of core team meeting 2017-05-10
2017-05-12 13:15:08 -07:00
Michael Ilseman
f08ee0fd93 [stdlib] Walk Chinese/Japanese faster: 2x/4x forwards/backwards
This adds more fast path checks for grapheme breaks between BMP
scalars. Notably the rather vast range of 0x3400–0xA4CF which includes
unified common Han ideographs as well as the first extension to
unified Han ideographs. It also happens to pick up various Yijin and
Yi symbols/radicals. Additionally, the narrow hiragana/katakana ranges
0x3041-0x3096 and 0x30A1-0x30FA (including pre-composed semi-voiced
characters but excluding the combining semi-voice marks) have fast
paths.

The net effect is that the vast majority of modern Chinese and
Japanese text should be fast-pathed. This is especially important, as
adopting Unicode 9 might otherwise pessimize performance here relative
to the tries.
2017-05-12 13:13:33 -07:00
Max Moiseev
f1439b8045 [stdlib] Remoiving old integers 2017-05-12 11:48:32 -07:00
Dave Abrahams
8137d7dbaf [stdlib] Temporarily disable availability annotations
PlaygroundLogger is using Swift 4 mode, thus we have to land this, update that,
and then add the availability annotations later.
2017-05-12 05:11:50 -07:00
Joe Groff
ed2612fe2d Merge pull request #9516 from jckarter/objc-keypath-id
SILGen/IRGen/KeyPaths: Components for ObjC properties need to be identified by selector.
2017-05-11 19:33:21 -07:00
Dave Abrahams
41c244a065 [stdlib] Unicode[Encoding|Parser] => Unicode.[Encoding|Parser] 2017-05-11 17:21:39 -07:00
Mishal Shah
96ea67dc87 Merge pull request #9512 from airspeedswift/come-back-where-clauses-we-miss-you
[stdlib] Revert addition of some recursive where clauses on Collection protocols
2017-05-11 17:11:33 -07:00
Dave Abrahams
01d886fe3d [stdlib] Swift.UTF[8|16|32] availability 2017-05-11 15:23:25 -07:00
Dave Abrahams
ddf7ad517f UnicodeScalar => Unicode.Scalar 2017-05-11 15:23:25 -07:00
Dave Abrahams
97f875ad84 [stdlib] De-underscore Unicode "namespace" 2017-05-11 15:23:25 -07:00
Joe Groff
9830f394c1 SILGen/IRGen/KeyPaths: Components for ObjC properties need to be identified by selector.
A property imported from Objective-C, or marked in Swift with the `dynamic` keyword, doesn't have a vtable slot, so can't be identified that way. Use the ObjC selector as the unique identifier to ascribe equality to such components. Fixes rdar://problem/31768669. (While we're here, throw some more execution tests and a changelog note in.)
2017-05-11 14:28:19 -07:00