Commit Graph

5543 Commits

Author SHA1 Message Date
Scott Perry
6c992d91b2 Return nil on applying() failure instead of crashing (rdar://problem/53663769) 2019-08-08 16:50:13 -07:00
Karoy Lorentey
d7e57347ee [stdlib] Unify _NativeDictionary.subscript._modify’s two yields to work around SR-10604 2019-08-07 17:15:04 -07:00
swift-ci
b2d83d4c99 Merge pull request #26422 from Catfish-Man/its-about-sending-a-message 2019-08-07 15:57:00 -07:00
David Smith
d0ed51925b Review comments and subsequent build fix on https://github.com/apple/swift/pull/26422 2019-08-07 13:42:51 -07:00
Stephen Canon
fb2128b33b Remove doc comments from concrete floating-point types (#26399)
* Remove doc comments from concrete floating-point types

... when they are already present on the protocol. I don't *think* that we need them anymore for xcode documentation purposes. There are reasonable arguments both ways on this:
1. when you're editing the concrete implementations, it's sometimes nice to have the doc comment right there.
2. but it needlessly repetitive, and introduces the opportunity for comments to get out of sync.
3. it also adds noise; it would be nice for information density if the implementation only had implementation notes.

* Add examples to documentation for FloatingPoint.isCanonical

In particular, document that subnormal encodings are treated as non-canonical zeros on platforms that flush to zero.

* Additional fixes by @xwu and @natecook1000 .
2019-08-06 18:17:37 -04:00
David Smith
0887299d9e Fix sub-scalar index distances in foreign UTF8 views 2019-08-02 16:45:42 -07:00
Alex Langford
184d942ba0 [CMake] add_swift_target_library shouldn't implicitly set INSTALL_IN_TARGET
This makes it more explicit what the install component of a target
library is if you don't see one (and its marked as IS_SDK_OVERLAY).
Explicit in this case makes more sense, as you don't have to rely on
knowledge of how `add_swift_target_library` is implemented to understand
what component is used to install the target.
2019-08-02 13:51:52 -07:00
David Smith
c5fc715746 Reimplement the CF stub system using ObjC. The primary effect of this is to break the link-time dependency on the CF symbols, but it also improves performance a bit.
One additional tweak (setting the scalar-aligned bit on foreign indices) had to be made to avoid a performance regression for long non-ASCII foreign strings.
2019-08-01 19:56:45 -07:00
Karoy Lorentey
a25e53468e [gardening] Delete StringGutsVisitor.swift (#26393) 2019-07-29 19:08:46 -07:00
Xiaodi Wu
a078c33ceb [stdlib] Change documented behavior of FloatingPoint.significand (#26390) 2019-07-29 11:08:04 -04:00
Karoy Lorentey
62c1cf31d2 Merge pull request #26022 from anandabits/Identifiable
Add Identifiable protocol to the standard library
2019-07-26 17:38:26 -07:00
David Smith
e7b1107212 Merge pull request #26374 from Catfish-Man/unindex-set
Remove unused Foundation subclasses
2019-07-26 17:09:45 -07:00
David Smith
48266a6f56 Remove unused Foundation subclasses 2019-07-26 14:47:43 -07:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Erik Eckstein
117b1dafe6 Rename the two-parameter Builtin.condfail(c, message) to Builtin.condfail_message(c, message)
This is necessary to also support the old single paramter Builtin.condfail(c)
2019-07-17 17:41:59 +02:00
swift-ci
c76925c4ea Merge pull request #26152 from Catfish-Man/serrated-surrogates 2019-07-16 15:38:25 -07:00
David Smith
d091ecb009 Restore more-correct behavior of getting the full contents of bridged NSStrings containing invalid UTF-8 2019-07-16 12:05:56 -07:00
Erik Eckstein
6ed8a084d9 stdlib: Use the new failure message method for the "unexpected found nil while unwrapping an optional" failure message.
Advantage: the failure message is now also visible in release builds.
2019-07-16 14:51:18 +02:00
Erik Eckstein
3195bdc973 stdlib: let _precondition include the file+line info in debug builds.
For using the improved condfail messages in the stdlib, we need a function, like precondition(), just taking a StaticString instead of a String for the message.
The existing (underscored) _precondition is a perfect fit for this, except that it's not printing the location info in debug builds.
This change makes _precondition() equivalent to precondition, just taking a StaticString as argument.

The other alternative would be to add another variant of precondition, just taking a StaticString. But we already have so many failure functions in Assert.swift, so adapting an existing one seems to be a better solution.
This effectively undos a change from 5 years ago which intentionally removed the location info from _precondition (rdar://problem/16958193).  But this was at a time where swift was not open source yet. So I think today it's okay to always add location information, even if it's from inside the stdlib. It can be even very useful for expert users for looking up the location the stdlib source.
2019-07-16 14:51:18 +02:00
Erik Eckstein
b40ce6b34f SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-16 14:44:09 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Karoy Lorentey
b0f30c8123 Merge pull request #26125 from lorentey/cutting-the-gordian-array-count
[stdlib] Simplify __SwiftNativeNSArrayWithContiguousStorage.count
2019-07-13 19:53:45 -07:00
Karoy Lorentey
d186e9ca91 [stdlib] Simplify __SwiftNativeNSArrayWithContiguousStorage.count 2019-07-12 16:43:03 -07:00
Michael Ilseman
e01a294da6 [stdlib] Introduce _invariantCheck_5_1 for 5.1 and later assertions.
Inlinable and non-inlinable code can cause 5.1 code to intermix with
5.0 code on older OSes. Some (weak) invariants for 5.1 should only be
checked when the OS's code is 5.1 or later, which is the purpose of
_invariantCheck_5_1.

Applied to String.Index._isScalarAligned, which is a new bit
introduced in 5.1 from one of the reserved bits from 5.0. The bit is
set when the index is proven to be scalar aligned, and we want to
assert on this liberally in contexts where we expect it to be
so. However, older OSes might not set this bit when doing scalar
aligning, depending on exactly what got inlined where/when.
2019-07-12 15:58:27 -07:00
Stephen Canon
dc5915cdb5 Replace stdlib and test/stdlib 9999 availability. (#26108)
* Replace stdlib and test/stdlib 9999 availability.

macOS 9999 -> macOS 10.15
iOS 9999 -> iOS 13
tvOS 9999 -> tvOS 13
watchOS 9999 -> watchOS 6

* Restore the pre-10.15 version of public init?(_: NSRange, in: __shared String)

We need this to allow master to work on 10.14 systems (in particular, to allow PR testing to work correctly without disabling back-deployment tests).
2019-07-12 16:30:36 -04:00
Erik Eckstein
bc48b3d69d stdlib: Use the new failure message method for the "unexpected found nil while unwrapping an optional" failure message.
Advantage: the failure message is now also visible in release builds.
2019-07-12 14:03:13 +02:00
Erik Eckstein
f8325add8f stdlib: let _precondition include the file+line info in debug builds.
For using the improved condfail messages in the stdlib, we need a function, like precondition(), just taking a StaticString instead of a String for the message.
The existing (underscored) _precondition is a perfect fit for this, except that it's not printing the location info in debug builds.
This change makes _precondition() equivalent to precondition, just taking a StaticString as argument.

The other alternative would be to add another variant of precondition, just taking a StaticString. But we already have so many failure functions in Assert.swift, so adapting an existing one seems to be a better solution.
This effectively undos a change from 5 years ago which intentionally removed the location info from _precondition (rdar://problem/16958193).  But this was at a time where swift was not open source yet. So I think today it's okay to always add location information, even if it's from inside the stdlib. It can be even very useful for expert users for looking up the location the stdlib source.
2019-07-12 14:03:13 +02:00
Erik Eckstein
3fd7eea96c SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-12 14:03:13 +02:00
David Smith
68687e7408 Merge pull request #26007 from Catfish-Man/uninitialized-initialize-uppercase
Add a private implementation of a String initializer with access to uninitialized storage (https://github.com/apple/swift-evolution/pull/1022) and use it to speed up uppercased() and lowercased()
2019-07-09 17:58:42 -07:00
David Smith
b06137b283 Add a private implementation of a String initializer with access to uninitialized storage (https://github.com/apple/swift-evolution/pull/1022) and use it to speed up uppercased() and lowercased() 2019-07-09 15:05:00 -07:00
Scott Perry
3924d1a99d Merge pull request #25825 from numist/numist/diff-inverse-master
add `CollectionDifference.inverse()` and test coverage
2019-07-09 14:46:20 -07:00
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