Commit Graph

7762 Commits

Author SHA1 Message Date
Matthew Johnson
0a8f154ab2 Add Identifiable protocol to the standard library 2019-07-09 14:17:20 -05:00
Dad @ GeekAndDad
749a9726ef Update example code to compile with Swift 5.0/5.1 (#25995)
* Update example code to compile with Swift 5.0/5.1

Took inspiration from Filter.swift as to modern syntax to use, though didn't convert `private` properties to `internal`.

* simplify example code as requested

Removed private scope on properties to enable synthesized initializers; removed previously added explicit initializers; add necessary parameter label.

* Update stdlib/public/core/LazySequence.swift

remove ill advised usability change

Co-Authored-By: Xiaodi Wu <xiaodi.wu@gmail.com>

* Update stdlib/public/core/LazySequence.swift

Co-Authored-By: Xiaodi Wu <xiaodi.wu@gmail.com>
2019-07-09 07:43:48 -05:00
Richard Wei
259571a7f7 Add default implementations for AdditiveArithmetic.{+=, -=}. (#25321)
This patch defines a default implementation for `+=` and `-=` in `extension AdditiveArithmetic` implemented in terms of `+` and `-`.
2019-07-04 22:57:27 -07:00
Ravi Kandhadai
7a3c6d58f5 [stdlib][oslog] Create an SPI _globalStringTablePointer that exposes
the builtin.globalStringTablePointer to the new OSLog overlay.

Modify the new OSLog implementation to use this SPI instead of
`withCString` to pass the (compiler-generated) format string to
the C os_log_impl ABI.

Move the OSLogOptimization pass before constant propagation in
the pass pipeline so that the SPI and the builtin it uses can be
folded to a string_literal instruction.

Update OSLogTests to work with the changes in the implementation.
2019-07-03 17:25:37 -07:00
David Smith
0ae4b0ab64 Merge pull request #25866 from Catfish-Man/someone-set-up-us-the-bom
Bridge non-ASCII SmallStrings as native Swift Strings rather than by creating CFStrings
2019-07-02 23:59:29 -07:00
David Smith
27359bdec6 Bridge non-ASCII SmallStrings as native Swift Strings rather than by creating CFStrings. This gets consistent behavior with non-smol Strings when the String contains a BOM 2019-07-02 16:34:22 -07:00
Michael Ilseman
63a6794cf9 [String] Switch scalar-aligned bit to a reserved bit.
Since scalar-alignment is set in inlinable code, switch the alignment
bit to one of the previously-reserved bits rather than a grapheme
cache bit. Setting a grapheme cache bit in inlinable would break
backward deployment, as older versions would interpret it as a cached
value.

Also adjust the name to "scalar-aligned", which is clearer, and
removed assertion (which should be a real precondition).
2019-07-02 16:25:04 -07:00
Saleem Abdulrasool
88f8a3c597 Merge pull request #25846 from plotfi/master2
Appending SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS to SWIFT_COMPILE_FLAGS.
2019-07-01 16:34:40 -07:00
Karoy Lorentey
f0291626e3 Merge pull request #25873 from lorentey/RawRepresentable-hashing
[stdlib] RawRepresentable: revert to default _rawHashValue(seed:)
2019-07-01 16:22:57 -07:00
Scott Perry
f994fc3f80 Merge pull request #25808 from numist/numist/diffing-performance-master
Performance improvements and availability updates for Collection.difference(from:using:)
2019-07-01 14:20:07 -07:00
Puyan Lotfi
6691fda8ec Appending SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS to SWIFT_COMPILE_FLAGS.
There are situations where you want to build against a libc that is out
of tree or that is not the system libc (Or for cross build scenarios).
This is a change for passing the -sdk and include paths for things like
this.
2019-07-01 09:43:47 -07:00
Karoy Lorentey
09bf1f72b1 [stdlib] RawRepresentable: revert to default _rawHashValue(seed:)
https://bugs.swift.org/browse/SR-10734
2019-06-29 11:49:51 -07:00
Scott Perry
3d741f7f2e Restore call to reserveCapacity 2019-06-27 16:01:17 -07:00
Michael Ilseman
1de84fc531 Merge pull request #23834 from milseman/a_line_scaler
[String] Scalar-alignment bug fixes.
2019-06-27 14:28:09 -07:00
Scott Perry
3ddfff92a6 add CollectionDifference.inverse() and test coverage 2019-06-27 11:40:46 -07:00
Michael Ilseman
bd5a40ff1b [gardening] Add underscore to internal member 2019-06-27 11:11:44 -07:00
Scott Perry
0fc5d6ad31 Performance improvements and availability updates for Collection.difference(from:using:) 2019-06-26 16:55:29 -07:00
Michael Ilseman
4cd1e812b7 [String] Scalar-alignment bug fixes.
Fixes a general category (pun intended) of scalar-alignment bugs
surrounding exchanging non-scalar-aligned indices between views and
for slicing.

SE-0180 unifies the Index type of String and all its views and allows
non-scalar-aligned indices to be used across views. In order to
guarantee behavior, we often have to check and perform scalar
alignment. To speed up these checks, we allocate a bit denoting
known-to-be-aligned, so that the alignment check can skip the
load. The below shows what views need to check for alignment before
they can operate, and whether the indices they produce are aligned.

┌───────────────╥────────────────────┬──────────────────────────┐
│ View          ║ Requires Alignment │ Produces Aligned Indices │
╞═══════════════╬════════════════════╪══════════════════════════╡
│ Native UTF8   ║ no                 │ no                       │
├───────────────╫────────────────────┼──────────────────────────┤
│ Native UTF16  ║ yes                │ no                       │
╞═══════════════╬════════════════════╪══════════════════════════╡
│ Foreign UTF8  ║ yes                │ no                       │
├───────────────╫────────────────────┼──────────────────────────┤
│ Foreign UTF16 ║ no                 │ no                       │
╞═══════════════╬════════════════════╪══════════════════════════╡
│ UnicodeScalar ║ yes                │ yes                      │
├───────────────╫────────────────────┼──────────────────────────┤
│ Character     ║ yes                │ yes                      │
└───────────────╨────────────────────┴──────────────────────────┘

The "requires alignment" applies to any operation taking a
String.Index that's not defined entirely in terms of other operations
taking a String.Index. These include:

* index(after:)
* index(before:)
* subscript
* distance(from:to:) (since `to` is compared against directly)
* UTF16View._nativeGetOffset(for:)
2019-06-26 16:42:58 -07:00
Stephen Canon
166d0fa961 FloatingPoint.radix should be transparent. (#25789)
* FloatingPoint.radix should be inlinable.

* Switch transparent to inlinable+inline(__always).
2019-06-26 18:20:27 -04:00
David Smith
149080c526 Merge pull request #25771 from Catfish-Man/very-normal-hash
Remove a retain release pair in foreign string hashing
2019-06-26 14:21:45 -07:00
Michael Ilseman
93d65fc9c3 [gardening] Remove trailing whitespace 2019-06-26 09:22:17 -07:00
Michael Ilseman
f52a865570 [String] Slice contents before asking ICU
ICU will return different results if we call with an offset into a
code unit buffer vs if we slice the buffer first and provide an offset
of zero. Slicing more closely models the semantics of SE-0180, so use
that.

Test case coming in subsequent commit enforcing index
scalar-alignment.
2019-06-26 09:22:17 -07:00
t.ae
f96cbb8a36 Make AdditiveArithmetic.zero @_transparent (#25658) 2019-06-26 09:07:30 -04:00
David Smith
75185aa556 Remove a retain release pair in foreign string hashing 2019-06-25 18:17:39 -07:00
Joe Groff
a868cfb237 Merge pull request #25329 from linux-on-ibm-z/s390x-keypathmultimodule-fix
Fix for KeyPathMultiModule test failure
2019-06-25 09:41:51 -07:00
Lei Zhang
6ac15e9348 Fix for KeyPathMultiModule test failure 2019-06-24 16:17:39 -04:00
David Smith
460a5213fc Revert "[stdlib] AutoreleasingUnsafeMutablePointer: Switch subscripts to _read accessors"
This was an ABI break, since it didn't make it into 5.0. Using _read here is unimportant, so we're just going to revert rather than try being fancy.

This reverts commit 04586e3916.
2019-06-24 11:33:36 -07:00
Ed Greenaway
a92357ab05 Update documentation for CommandLine.arguments (#25304)
Addresses SR-6776 Documentation comment for CommandLine.arguments contains implementation remarks
2019-06-19 15:47:17 -07:00
Vlad Gorlov
6370681656 Android cross-compile on macOS: Fix for compile error addressed Float80 data type. (#25502)
* Fixes issue addressed Float80 data type. Float80 is disabled for Intel architectures (i.e. Android Simulator).

* More precise condition check.
2019-06-17 13:40:44 -04:00
Nate Cook
e730bd1256 Remove residual gyb bits from LazyPrefixWhileCollection. 2019-06-13 11:39:15 -05:00
Stephen Canon
2df36527d3 Provide a default implementation of multipliedFullWidth (#25346)
* Provide a default implementation of multipliedFullWidth

Previously, [U]Int64 fatalErrored on 32b platforms, which is obviously undesirable. This PR provides a default implementation on FixedWidthInteger, which is not ideally efficient for all types, but is correct, and gives the optimizer all the information that it needs to generate good code in the important case of Int64 arithmetic on 32b platforms. There's still some minor room for improvement, but we'll call that an optimizer bug now.

* Clarify comments somewhat, remove `merge` nested function

I was only using `merge` in one place, so making it a function seems unnecessary. Also got rid of some trucatingIfNeeded inits where the compiler is able to reason that no checks are needed anyway.

* Add some basic test coverage specifically for multipliedFullWidth

* Fix typo, further clarify bounds comments.

* Make new defaulted implementation @_aEIC so we don't need availability.
2019-06-11 22:02:48 -07:00
Karoy Lorentey
fd39f2f9d2 Merge pull request #25301 from fassko/SR_10094_withContiguousStorageIfAvailable_docs
[Doc] [SR-10094]  Add missing documentation for SE-0237
2019-06-11 11:52:50 -07:00
Stephen Canon
bbd44a186f Replace two #ifs with #if/#else in new integer random algorithm (#25352)
Swift gets used on archs other than 32 and 64b Intel and ARM (e.g. IBM's systems); as written this would fail to compile there.
2019-06-11 14:36:43 -04:00
Pavol Vaskovic
2bc648c26b [stdlib] Lemire’s Nearly Divisionless Random Integer Generation (#25286)
* [stdlib] Lemire’s nearly divisionless random int

Implementation of Daniel Lemire’s “Fast Random Integer Generation in Interval”
See https://arxiv.org/pdf/1805.10941.pdf

* [stdlib] Simpler, optimized expression

* [stdlib] O'Neill’s modulo optimization

See http://www.pcg-random.org/posts/bounded-rands.html#optimizing-modulo

* [stdlib] Remove modulo optimization

Swift, compared to C, seems unable to generate tightly fused instructions here for some reason (probably the division by zero check?)… removing.

* [stdlib] Keep OpenBSD debiasing method on 32-bit

systems until the https://bugs.swift.org/browse/SR-10910 is resolved.

* [stdlib] TODO FIXME SR-10912

Remove the old OpenBSD generation method, once 32-bit systems support multipliedFullWidth on UInt64.
2019-06-10 22:44:09 -04:00
Steve (Numerics) Canon
4b5a85a34d Fix a bug in root and add a test case for it.
For odd roots of negative values, we need to take the root of the *magnitude* of the number to avoid a NaN from the platform's implementation of `pow`, then restore the sign afterwards. We had the basic logic in place already, but were missing the step of taking the magnitude first. Also modified a test case to find this error.
2019-06-10 11:50:36 -04:00
Kristaps Grinbergs
f0e3a99f97 [Doc] [SR-10094] Add missing documentation for SE-0237
https://bugs.swift.org/browse/SR-10094
2019-06-07 14:32:42 -07:00
Slava Pestov
ec4c597156 stdlib: ManagedBuffer.init(_doNotCallMe:) was ABI in Swift 5 and should be @usableFromInline 2019-06-01 00:08:05 -04:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Steve (Numerics) Canon
957384129a It turns out that _SmallBuffer<T> simply isn't used at all
... so that's another vestigial static-buffer we can eliminate.
2019-05-29 19:43:39 -04:00
Steve (Numerics) Canon
27ccf1b914 De-GYB FixedArray.swift
It turns out that 16 is the only size that the stdlib actually uses, so the .gyb isn't eliminating any boilerplate anyway.
2019-05-29 19:19:54 -04:00
Slava Pestov
3917268b35 stdlib: Work around associated type inference bugs 2019-05-28 22:08:31 -04:00
Sho Ikeda
44f0e93747 Merge pull request #25067 from ikesyo/avoid-fallthrough-where-appropriate
[gardening] Avoid fallthrough where appropriate (for readability/understandability)
2019-05-29 00:27:05 +09:00
Sho Ikeda
2019a97e55 Merge pull request #25066 from ikesyo/use-isempty-over-count
[gardening] Use `Collection.isEmpty` over `Collection.count`
2019-05-29 00:24:48 +09:00
Turushan Aktay
c61691919b Fix documentation typos. 2019-05-26 14:17:45 +02:00
Sho Ikeda
c1bb945124 [gardening] Avoid fallthrough where appropriate (for readability/understandability) 2019-05-26 09:50:02 +09:00
Sho Ikeda
a35c9f0c60 [gardening] Use Collection.isEmpty over Collection.count 2019-05-26 09:35:20 +09:00
Federico Zanetello
afcf4b6991 fix documentation typo (#25061) 2019-05-25 12:43:49 -05:00
David Smith
803227a46b Avoid O(n) character accesses in String.UTF8View._foreignCount 2019-05-21 13:22:42 -07:00
Ted Kremenek
4beb673b8e Bump compiler version to Swift 5.1 (#24671)
* Bump version to Swift 5.1

* Update tests with compiler version bump

* Undo flatMap and math obsolescences
2019-05-13 07:32:39 -07:00
Xiaodi Wu
da9f67c781 [docs] Update trailingZeroBitCount documentation (#24713)
* [docs] Update `trailingZeroBitCount` documentation

Document the required behavior for `trailingZeroBitCount` when the value is zero. Namely, in that scenario, `trailingZeroBitCount` should be equal to `bitWidth`.

* [docs] Address reviewer comments on `trailingZeroBitCount` docs
2019-05-13 08:53:28 -04:00