Commit Graph

3590 Commits

Author SHA1 Message Date
Maxim Moiseev
96b5b77081 Merge pull request #9888 from moiseev/unambiguous-array-filter
[stdlib] Moving the Array.filter to _ArrayProtocol
2017-05-23 20:59:28 -07:00
Xiaodi Wu
afa4e12fa6 Refine wording in doc comment 2017-05-23 21:10:04 -05:00
Xiaodi Wu
e30a003bca Update BinaryInteger default initializer documentation
Some time ago, it was pointed out that "truncating" would be used only for bit pattern operations. As pointed out on Swift Evolution, this is the only spot where the same term is used for dropping the fractional part of a floating point value; elsewhere, it is always spelled--even in documentation--as "rounded toward zero." This PR updates the usage here to align with existing convention.
2017-05-23 21:07:16 -05:00
Max Moiseev
5590872b35 [stdlib] Moving the Array.filter to _ArrayProtocol
Resolves ambiguity in the following expression

  _ = Array(0..<10).lazy.flatMap { .some($0) }.filter { _ in false }

Fixes: <rdar://problem/32316948>
2017-05-23 17:32:23 -07:00
Dave Abrahams
399193ff30 Merge pull request #9847 from apple/eliminate-_Element
[stdlib] Eliminate _Element
2017-05-23 16:44:55 -07:00
Dave Abrahams
b3a3b52783 Merge pull request #9798 from apple/inline-stable-grapheme-fastpaths
Inline stable grapheme fastpaths
2017-05-23 15:18:32 -07:00
Michael Ilseman
527f2c4dd7 Merge pull request #9858 from milseman/got_no_cache
[stdlib] String: drop TLS setText cache.
2017-05-23 12:24:13 -07:00
Dave Abrahams
3d789cff2d Inlineable character fast paths 2017-05-23 01:42:28 -07:00
swift-ci
1c390bc578 Merge pull request #9846 from apple/remove-redundant-slicing 2017-05-23 00:52:56 -07:00
Ted Kremenek
dbe77601f3 Merge pull request #9791 from itaiferber/swift-archival-serialization-updates
Enhancements to Codable API
2017-05-22 23:53:49 -07:00
Dave Abrahams
0016379d82 Merge branch 'master' into remove-redundant-slicing 2017-05-22 20:48:23 -07:00
Michael Ilseman
1bc1011e31 [stdlib] String: drop TLS setText cache.
The overhead of the weak reference overwhelms the savings from
avoiding the setText, when there's a fair amount of reference counting
involved. The real solution will be to use an unowned reference. For
now, drop the cache and introduce it once we have more runtime
functionality.
2017-05-22 18:59:06 -07:00
Dave Abrahams
b677e1d6e4 [stdlib] Remove now-redundant slicing operations 2017-05-22 16:34:05 -07:00
Dave Abrahams
72f5e7c0c2 [stdlib] Eliminate _Element 2017-05-22 16:17:58 -07:00
Dave Abrahams
4f5e14845b [stdlib] Eliminate optionals from specialization code
Apparently this makes the optimizer happier.  Still waiting on #9792 for truly
efficient specialization.

https://github.com/apple/swift/pull/9792
2017-05-22 15:59:43 -07:00
Itai Ferber
d16297dad5 Introduces changes to Codable stdlib API
* Adds conformance of Optional to Codable
* encode(...) arguments are no longer Optional; Optional values go
  through generic version
* encodeIfPresent added to KeyedEncodingContainerProtocol to mirror
  decodeIfPresent
* JSONEncoder and PropertyListEncoder updated to reflect these changes
2017-05-22 09:29:36 -07:00
Ben Cohen
02e2bd5380 Re-gyb sorting (#9818) 2017-05-21 16:59:46 -07:00
Dave Abrahams
70a437c846 [stdlib] Remove invalid _sanityCheck
A `Character` _should_ contain only a single grapheme, but we can't formally require it because of grapheme cluster literals and the shifting sands of Unicode.  Fixes https://bugs.swift.org/browse/SR-4955
2017-05-21 08:00:43 -07:00
Pavol Vaskovic
b57aa7c057 Sequence internals with struct instead of class.
_DropFirstSequence, _PrefixSequence and _DropWhileSequence as structs.

I turns out we DON’T require reference semantics to keep track of how many elements we've already taken from the underlying sequence.

… that’s taken care of by the underlying sequence, which has to have reference semantics if it needs them.
2017-05-21 08:02:37 +02:00
Maxim Moiseev
4ec2838e8d Merge pull request #9757 from moiseev/renamed-intmax
[stdlib] Providing fixits for IntMax and UIntMax
2017-05-19 07:31:54 -07:00
swift-ci
32b4e56ca5 Merge pull request #7183 from apple/rdar-25398370 2017-05-18 18:29:02 -07:00
Max Moiseev
368847b5c7 [stdlib] Providing fixits for IntMax and UIntMax 2017-05-18 18:00:45 -07:00
Dave Abrahams
fe76f6b147 [stdlib] Add and use _identityCast 2017-05-18 17:41:15 -07:00
Dave Abrahams
fd30b72ee1 [stdlib] Fix a race
Lock-free programming is almost always a bug.
Fixes <rdar://25398370> Data Race in StringBuffer.append (found by TSan)
2017-05-18 16:29:59 -07:00
swift-ci
2a5d7a13f1 Merge pull request #9745 from eeckstein/disable-gen-inline 2017-05-18 16:14:49 -07:00
Erik Eckstein
74fa0bcc87 Disable generic inlining and partial specialization, except in libswiftCore
This avoids code size regressions in programs while still getting the performance improvements in generic code in the stdlib.

rdar://problem/32277313
2017-05-18 15:38:54 -07:00
Max Moiseev
fd2ac31c6e [stdlib] Adding RangeReplaceable.filter returning Self
This overload allows `String.filter` to return a `String`, and not
`[Character]`.

In the other hand, introduction of this overload makes `[123].filter`
somewhat ambiguous in a sence, that the compiler will now prefer an
implementatin from a more concrete protocol, which is less efficient for
arrays, therefore extra work is needed to make sure Array types fallback
to the `Sequence.filter`.

Implements: <rdar://problem/32209927>
2017-05-18 12:24:13 -07:00
Dave Abrahams
c67977a881 [stdlib] Replace Integer Parsing Code 2017-05-18 07:00:34 -07:00
Nate Cook
ca5c65f93c [stdlib] Nest some additional operators (#9646) 2017-05-17 19:44:08 -07:00
swift-ci
c0623c42ce Merge pull request #9722 from apple/stringprotocol-interchange 2017-05-17 19:13:25 -07:00
Michael Ilseman
948ba4d4e3 Merge pull request #9684 from milseman/tls_ftw
[stdlib] Unicode 9 and Thread Local Storage (again)
2017-05-17 18:32:25 -07:00
Maxim Moiseev
130231456b Merge pull request #9714 from moiseev/int-perf
[stdlib] Speeding up typechecking for complex expressions with integers
2017-05-17 17:33:47 -07:00
Dave Abrahams
d6fee05375 [stdlib] Enable interchange among StringProtocol models 2017-05-17 17:21:43 -07:00
Dave Abrahams
2f5a327f82 Merge pull request #9561 from apple/string-init-from-character-speedup
[stdlib] Speed up String(largeCharacter)
2017-05-17 17:14:12 -07:00
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