Commit Graph

5783 Commits

Author SHA1 Message Date
Valeriy Van
0e5d18654e Fixes comment for binaryString example snippet in FixedWidthInteger 2018-12-10 17:12:31 +01:00
Mike Ash
6b9480252e [Stdlib] Change AnyKeyPath to use @_objcRuntimeName attribute for its rename.
rdar://problem/46546165
2018-12-10 10:35:37 -05:00
Mike Ash
a49e2ddde7 [Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs.
rdar://problem/46546165
2018-12-10 10:17:52 -05:00
Jon Shier
c739498c9b Remove usage lines from docs. 2018-12-09 19:20:49 -05:00
Jon Shier
e4a700c32d Update inline documentation. 2018-12-09 19:08:41 -05:00
Ben Cohen
11769d2494 Add tests for withContiguousStorageIfAvailable 2018-12-07 17:30:13 -08:00
Max Moiseev
290e9025fa Merge pull request #21118 from benrimmington/remove-interval-group-info
[stdlib] Remove Interval.swift from GroupInfo.json
2018-12-07 11:16:55 -08:00
Ben Cohen
ad50a39b12 [stdlib] Add withContiguous{Mutable}StorageIfAvailable (#21092)
* Add MutableCollection.withContiguousMutableStorageIfAvailable

* Add withContiguousMutableStorageIfAvailable impls

* Add tests on concrete types

* Add Sequence.withContiguousStorageIfAvailable

* Implement withContiguousStorageIfAvailable in concrete types
2018-12-07 10:01:18 -08:00
Karoy Lorentey
b77351548a Merge pull request #21045 from lorentey/modify-vs-throw
[stdlib] Dictionary: Support throwing yields in _modify accessors
2018-12-07 17:08:42 +00:00
Ben Rimmington
4e667cb97b [stdlib] Remove Interval.swift from GroupInfo.json 2018-12-07 12:39:36 +00:00
Michael Ilseman
8863a5514c Merge pull request #21024 from milseman/fass_and_smol
[String] In-register comparison of small ASCII strings
2018-12-06 09:01:37 -08:00
Michael Ilseman
4394ce1a23 Merge pull request #21072 from milseman/i_dem_potent
[String] String-from-whole-Substring fast-path.
2018-12-06 09:01:12 -08:00
Doug Gregor
00d2acd809 Merge pull request #21037 from DougGregor/flatten-abs
[ABI] [stdlib] Remove magnitude-based overload of abs(_:).
2018-12-06 08:36:24 -08:00
Karoy Lorentey
549926337c Merge pull request #20967 from lorentey/aump-read
[stdlib] AutoreleasingUnsafeMutablePointer: Switch subscripts to _read accessors
2018-12-06 15:13:09 +00:00
Doug Gregor
ab75577079 [stdlib] Teach abs(_:) to use magnitude when it can.
Within the (single) implementation of abs(_:), dynamically check whether
the numeric type and its `Magnitude` are of the same type and, if so,
return the result of `magnitude`. This ensures that we do the right thing
with respect to (e.g.) floating point values like -0.0, without resorting
to overloading of abs(_:).
2018-12-05 21:05:52 -08:00
Jon Shier
2bc4cbbfdd Update for revised proposal. 2018-12-05 23:17:35 -05:00
Michael Ilseman
255c17aeb6 [String] String-from-whole-Substring fast-path.
Add in a fast-path for Strings created from Substring which covers the
entire String. Put String-from-Substring behind a non-inlinable
resilience barrier for future flexibility.
2018-12-05 18:22:47 -08:00
Michael Ilseman
b08d94d6ba [String] In-register smol ASCII string compare
Compare small strings in-register when they store ASCII (and thus NFC)
contents.
2018-12-05 18:16:46 -08:00
Karoy Lorentey
1485404532 [stdlib] Document that hashValue is deprecated 2018-12-05 19:00:35 +00:00
Karoy Lorentey
ce96f1e528 [stdlib] _modify: Use defer to ensure invariants are restored when yield throws
_modify mustn’t leave Collection storage in an inconsistent state when the code to which we’re yielding happens to throw. In practice this means that any cleanup code must happen in defer blocks before the yield.

Fix Dictionary to do just that and add tests to cover this functionality (as well as some other aspects of _modify).
2018-12-05 17:35:24 +00:00
Doug Gregor
85d488d461 [stdlib] Remove magnitude-based overload of abs(_:).
The standard library has two versions of the `abs(_:)` function:

```
func abs<T : SignedNumeric>(_ x: T) -> T where T.Magnitude == T
func abs<T : SignedNumeric & Comparable>(_ x: T) -> T
```

The first is more specialized than the second because `T.Magnitude` is
known to conform to `Comparable`. Indeed, it’s a more specialized
implementation that returns `magnitude`.

However, this overload behaves oddly: in the expression `abs(-8)`, the type
checker will pick the first overload because it is more specialized. That’s
a general guiding principle for overloading: pick the most specialized
overload that works.

However, to select that overload, it needs to pick a type for the literal
“8” for which that overload works, and it chooses `Double`. The “obvious”
answer, `Int`, doesn’t work because `Int.Magnitude == UInt`.

There is a conflict between the two rules, here: we prefer more-specialized
overloads (but we’ll fall back to less-specialized if those don’t work) and we prefer to use `Int` for integer literals (but we’ll fall back to `Double` if it doesn’t work). We have a few options from a type-checker
perspective:

1. Consider the more-specialized-function rule to be more important
2. Consider the integer-literals-prefer-`Int` rule to be more important
3. Call the result ambiguous and make the user annotate it

The type checker currently does #1, although at some point in the past it
did #2. Moving forward, #1 is a better choice because it prunes the number
of overloads that need to be considered: if the more-specialized overload
succeeds its type-check, the others need not be considered. It’s also
easier to reason about than the literal-scoring approach, because there can
be a direct definition for “more specialized than” that can be reasoned
about.

I think we should dodge the issue by removing the more-specialized version
of `abs(_:)`. Its use of `magnitude` seems unlikely to provide a
significant performance benefit, and the presence of overloading either
forces us to consider both overloads always (which is bad for type checker
performance) or accept the regression that `abs(-8)` is `Double`. Better
to eliminate the overloading and, if needed in the future, find a better
way to introduce the more-specialized implementation without it being a
separate signature.

Fixes rdar://problem/42345366.
2018-12-04 23:10:04 -08:00
Ben Cohen
fc7830a4ed Remove Swift 3-only Compatibility Shims (#21019) 2018-12-04 18:22:27 -08:00
Bob Wilson
8e38173884 Merge pull request #21008 from mikeash/keypath-allocation-overflow-fix
[Stdlib] Ensure key paths allocate space for the terminating NUL.
2018-12-04 15:01:37 -08:00
Michael Ilseman
3e8b015afe Merge pull request #20983 from milseman/comparison_reform
[String] Comparison Speedups
2018-12-04 14:53:45 -08:00
Mike Ash
01b840a488 [Stdlib] Ensure key paths allocate space for the terminating NUL.
rdar://problem/46457346 SR-9404
2018-12-04 14:53:03 -05:00
Michael Ilseman
8530a2c940 [String] Hand-increment loop variable for perf.
Hand-incrementing the loop variable allows us to skip overflow
detection, and will permit more vectorization improvements in the
future. For now, it gives us perf improvements in nano-benchmarks.
2018-12-04 11:51:21 -08:00
Jon Shier
7fb5905f5f Updates for review comments. 2018-12-03 21:52:21 -05:00
Slava Pestov
f871b0e661 Merge pull request #20948 from Azoy/remove-_getBool
[SILGen][stdlib] Remove _getBool
2018-12-03 21:00:31 -05:00
Michael Ilseman
c0c530aef8 [String] Speed up constant factors on comparison.
Include some tuning and tweaking to reduce the constant factors
involved in string comparison. This yields considerable improvement on
our micro-benchmarks, and allows us to make less inlinable code and
have a smaller ABI surface area.

Adds more extensive testing of corner cases in our existing
fast-paths.
2018-12-03 15:49:38 -08:00
Michael Ilseman
1706d4c02d [String] Refactor and fast-path normalization
Refactor some normalization queries into StringNormalization.swift,
and add more latiny (<0x300) fast-paths.
2018-12-03 13:22:57 -08:00
Michael Ilseman
8d2af454e4 [String] Normalization-boundary-before UTF-8 fast path.
All latiny (<0x300) scalars have normalization boundaries before them,
so when asking if memory containing a scalar encoded in valid UTF-8
has a boundary before it, check if the leading byte definitely encodes
a scalar less than 0x300.
2018-12-03 13:20:39 -08:00
Karoy Lorentey
bb81b24248 Merge pull request #20918 from lorentey/dictionary-modify-layering
[stdlib] Refactor Dictionary.subscript._modify for better layering
2018-12-03 20:57:55 +00:00
Michael Ilseman
94942c5b3b [String] Fix corner case in comparison fast-path. (#20937)
When in a post-binary-prefix-scan fast-path, we need to make sure we
are comparing a full-segment scalar, otherwise we miss situations
where a combining end-of-segment scalar would be reordered with a
prior combining scalar in the same segment under normalization in one
string but not the other.

This was hidden by the fact that many combining scalars are not
NFC_QC=maybe, but those which are not present in any precomposed form
have NFC_QC=yes. Added tests.
2018-12-03 10:41:45 -08:00
Karoy Lorentey
04586e3916 [stdlib] AutoreleasingUnsafeMutablePointer: Switch subscripts to _read accessors 2018-12-03 16:22:33 +00:00
Dale Buckley
6ef7cca298 Added decodable error handling and changed from operator constructors to uncheckedBounds constructor 2018-12-03 08:44:04 +00:00
Jon Shier
33dcfc462f Add update Result type to standard library. 2018-12-02 22:15:02 -05:00
Xiaodi Wu
f9e8b6363e [gardening] Make edits for stdlib style [NFC] 2018-12-02 15:26:35 -05:00
Azoy
a2dafc3d26 Remove _getBool 2018-12-01 18:51:25 -06:00
Michael Ilseman
b01ee7267a [String] Custom iterator for UTF16View (#20929)
Defining a custom iterator for the UTF16View avoid some redundant
computation over the indexing model. This speeds up iteration by
around 40% on non-ASCII strings.
2018-12-01 09:35:27 -08:00
Harlan Haskins
615b8be990 [stdlib] Silence warnings related to uninhabited types
PR #20528 was merged yesterday, which inserts an `unreachable` in
functions with uninhabited parameters. Unfortunately this means any
statement in the function body, even ones that themselves are
never-returning or don't have any executable code, cause the warning.

Silence the warnings by deleting the bodies of these functions.
2018-11-30 13:50:16 -08:00
Stephen Canon
28962b5754 Move most of the simd operators into an optional module (#20914)
* Move most of the simd operators into an optional module

Adding simd to the stdlib caused some typechecker regressions. We can resolve them in the near-term by making the types universally available, but moving the arithmetic operators into a separate module that must be explicitly imported.

* Move two fuzzing tests back to fixed.

* Add SIMDOperators as a dependency for MediaPlayer.

* Move the .-prefixed operator declarations back into the stdlib.
2018-11-30 16:30:15 -05:00
David Smith
ce82e80ec2 Merge pull request #20911 from Catfish-Man/dictionary-cast-builder
Use _DictionaryBuilder instead of Dictionary for casts
2018-11-30 10:18:46 -08:00
Karoy Lorentey
d32fd283b0 [stdlib] Refactor Dictionary.subscript._modify for better layering
This may also reduce ARC traffic by a little bit.
2018-11-30 17:47:08 +00:00
Karoy Lorentey
e94361e642 Merge pull request #20705 from lorentey/rawrepresentable-hashing
Add default Hashable implementations for RawRepresentable types
2018-11-30 14:21:37 +00:00
David Smith
17e7c5ff5f Use _DictionaryBuilder instead of Dictionary for casting 2018-11-30 02:15:29 -08:00
Michael Ilseman
c3c6fdc77f [String] ASCII fast-path for UTF16View (#20848)
Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.
2018-11-29 18:19:32 -08:00
Ted Kremenek
deb0f1f884 Merge pull request #20862 from futurejones/master-aarch64-VarArgs
[stdlib][SR-2239]: add support for AArch64 variadics
2018-11-29 15:05:35 -08:00
Stephen Canon
fb8b9e143d SIMD into stdlib
Implements SE-0229.

Also updates simd module types in the Apple SDKs to use the new types, and updates a couple tests to work with the new types and protocols.
2018-11-29 17:09:01 -05:00
futurejones
4a03b3c304 add support for AArch64 variadics 2018-11-29 22:30:28 +09:00
Doug Gregor
1cc67dc6a8 Merge pull request #20856 from Catfish-Man/master
Fix mis-merge
2018-11-28 21:44:35 -08:00