Commit Graph

5263 Commits

Author SHA1 Message Date
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
David Smith
ee02182c28 Fix mis-merge 2018-11-28 21:34:42 -08:00
swift-ci
c2a6021630 Merge pull request #20839 from airspeedswift/reduce-into-owned 2018-11-28 20:57:35 -08:00
John McCall
91a7c7635e Merge pull request #20415 from rjmccall/stdlib-borrowed-storage
Use @_borrowed on a few declarations in the stdlib and overlays
2018-11-28 21:29:27 -05:00
Ben Cohen
da614764ed Make reduce(inout:) take its initial value owned 2018-11-28 17:19:39 -08:00
David Smith
8b57921905 Assorted bridging changes:
• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it
2018-11-28 16:04:34 -08:00
swift-ci
d3bd4c5817 Merge pull request #20812 from milseman/sliced_guts 2018-11-27 17:45:23 -08:00
Michael Ilseman
e44972dcea [String] Expunge _StringGutsSlice from ABI
_StringGutsSlice is an implementation helper that's no longer needed
from inlinable code. Internalize it.
2018-11-27 15:07:27 -08:00
Arnold Schwaighofer
e57ba9954c Merge pull request #20763 from aschwaighofer/inlinable_arraybufferprotocol_init
stdlib: Make ArrayBufferProtocol.init inlinable to facilitate specialization
2018-11-27 08:45:46 -08:00
Ben Rimmington
c5997491da [stdlib] Remove Strideable closed range operator 2018-11-27 12:58:22 +00:00
Slava Pestov
86b5411a5a stdlib: __SwiftNativeNSString does not need to be public 2018-11-27 00:16:34 -05:00
swift-ci
68884b286c Merge pull request #20768 from milseman/empty_range 2018-11-26 14:59:06 -08:00
swift-ci
8ce2a36e6b Merge pull request #20653 from milseman/fastwidth 2018-11-26 14:34:54 -08:00
Karoy Lorentey
c1a7b71f46 Merge pull request #20762 from apple/sr-9348
[stdlib] _HashTable.copyContents: Fix out of bounds access
2018-11-26 21:04:17 +00:00
Michael Ilseman
4111b21cb0 [String] Bug fix for empty-range getCharacters 2018-11-26 12:13:23 -08:00
Arnold Schwaighofer
baae7ee10b Fix spelling of inlinable 2018-11-26 11:27:58 -08:00
Arnold Schwaighofer
e582a45a48 stdlib: Make ArrayBufferProtocol.init inlinable to facilitate specialization
SR-9284
2018-11-26 11:10:21 -08:00