Commit Graph

6693 Commits

Author SHA1 Message Date
Karoy Lorentey
63d0b734c0 Merge pull request #36669 from lorentey/fix-float16-sendable
[stdlib] Float16/Intel: Add an explicit Sendable conformance to work around a swiftinterface issue
2021-04-02 01:37:07 -07:00
Alex Martini
4b3064ede5 Simplify prose in doc comment.
Incorporates PR feedback from @tbkka.
2021-04-01 16:05:48 -07:00
Alex Martini
1bfce98e8d Revise finite/infinite note for NaN.
Incorporates PR feedback from @tbkka.
2021-04-01 16:05:48 -07:00
Xiaodi Wu
c40c90402a [stdlib] Address reviewer comments and make some minor edits to string-to-integer parsing. 2021-04-01 13:03:56 -04:00
Karoy Lorentey
cb67f45394 [stdlib] Float16: Add explicit Sendable conformance to work around swiftinterface issue 2021-04-01 00:51:14 -07:00
Slava Pestov
c473869141 stdlib: Add reasync variants of '&&', '||' and '??'
Fixes rdar://problem/72770687.
2021-03-31 19:21:08 -04:00
Karoy Lorentey
ec7258e2fc [stdlib] Fix incorrect Float16 extension
This extension (introduced in https://github.com/apple/swift/pull/35264) was placed in a file location where it wasn’t correctly guarded against mentioning Float16 on macOS/x86_64, so the generated .swiftinterface file included a reference to an unavailable declaration. (The dummy stand-in Float16 type that we currently use on Intel macOS.)

Moving the declaration out of the “AnyHashable” section and into a file region that’s more suitable for it (i.e., enclosed in `#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))`) resolves the issue.

rdar://76025365
2021-03-30 18:43:16 -07:00
Michael Ilseman
49eddbf318 [stdlib] Fix bug in small string uninitialized init
Fix a bug and enforce the invariant that all bits between the last code unit
and the descriminator in a small string should be unset.
2021-03-30 18:24:28 -06:00
Xiaodi Wu
5d943f46bd [stdlib] Further simplify string-to-integer parsing and change some inlining choices. 2021-03-29 12:08:28 -04:00
Xiaodi Wu
0319bdc966 [gardening] Fix tab size inconsistency. 2021-03-29 11:30:48 -04:00
Xiaodi Wu
529891c911 [stdlib] Simplify implementation of string-to-integer parsing. 2021-03-29 11:27:21 -04:00
Xiaodi Wu
ebad4bbb5d [stdlib] Specialize FixedWidthInteger.init(_:radix:). 2021-03-29 10:19:22 -04:00
Xiaodi Wu
cc8a351cc1 [stdlib] Never inline two more string-to-integer parsing methods. 2021-03-29 09:02:41 -04:00
Xiaodi Wu
7c333b8e44 [stdlib] Never inline fallback helper methods when parsing strings to integers. 2021-03-28 22:22:50 -04:00
Xiaodi Wu
a9c57c3bcd [stdlib] Make FixedWidthInteger.init?(_:radix:) always inlined, and fix a think-o. 2021-03-28 20:44:11 -04:00
Xiaodi Wu
ad992f48dd [stdlib][SR-7556] Re-implement string-to-integer parsing. 2021-03-28 16:49:09 -04:00
Stephen Canon
09cd45d4c2 Remove a small helper function that took a Builtin.VecNxInt1 type.
It saved some boilerplate, but if it doesn't get inline (as in debug builds), Swift doesn't know how to legalize the type at the call boundary, and we crash.
2021-03-24 23:34:28 -04:00
Stephen Canon
5afe404707 Concrete simd mask operations (#36571)
* Replace lhs/rhs with a/b for clarity of documentation and to match concrete ops.

* Concretize additional SIMDMask operations:

.&=, .|=, .^=, .==, .!=

Also reflect documentation changes back to generic implementations.
2021-03-24 23:15:46 -04:00
Karoy Lorentey
390cebe88b Merge pull request #36004 from lorentey/document-copyContents
[stdlib] Document a fatal surprise with `Sequence._copyContents`
2021-03-22 16:49:18 -07:00
Stephen Canon
7e326063c5 Concrete SIMD operations, part 1 (#36172)
Adds concrete overloads of the following SIMD operations:
- Comparisons: .==, .!=, .<, .<=, .>, .>=
- Logical operations on masks: .!, .&, .^, .|
- Integer arithmetic: &+, &-, &, &+=, &-=, &=
This makes some simple benchmarks 10-100x faster, which is basically a no-brainer, while staying away from the most heavily used operators, so hopefully doesn't impact compilation performance too badly.
2021-03-22 16:48:21 -04:00
tbkka
26ab27648e Casting from AnyHashable to AnyHashable should never create another wrapper (#36470)
* Casting from AnyHashable to AnyHashable should never create another wrapper

This adds a conformance for _HasCustomAnyHashableRepresentation to
AnyHashable that simply returns self.  This ensures that anytime
you try to create a new AnyHashable wrapper for an existing
AnyHashable, you just get back the original.

Resolves rdar://75180619

* Move the `Struct AnyHashable` change to `without-asserts` list

As suggested by @lorentey
2021-03-22 09:03:29 -07:00
Robert Widmann
c5a751212d Merge pull request #36446 from wonhee009/Result 2021-03-21 09:58:14 -07:00
David Smith
e793e0e0e4 Always ask Cocoa for terminated char*s
(cherry picked from commit b7ce22ba1525dccd47f4095a9bf8a640b238a5fa)
2021-03-19 13:01:23 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Meghana Gupta
dbea482085 Refactor FixedWidthInteger init (#36485) 2021-03-18 13:47:12 -07:00
wonhee
09971acf8c fix Result flatMapError remark 2021-03-16 14:03:18 +09:00
Xiaodi Wu
4c7059f59a [stdlib][SR-13883] Avoid advancing past representable bounds when striding (#34860)
* [stdlib][SR-13883] Avoid advancing past representable bounds when striding.

* [stdlib] Expand a test and add a comment to ensure correct floating-point stride bounds checking.

* [stdlib][NFC] Clarify a comment in a test.

* [stdlib][NFC] Adjust copyright notices, clarify comments, delete '-swift-version=3' for tests.

* [stdlib] Add implementations for fixed-width integer strides for performance.

* [stdlib] Document `Strideable._step` and modify overflow checking behavior of `Stride*Iterator`.

* [stdlib] Address reviewer comments, postpone documentation changes

* [stdlib][NFC] Update documentation for '_step(after:from:by:)'

* [stdlib][NFC] Use 'nil' instead of an arbitrary value for integer striding '_step' index
2021-03-11 08:18:28 -05:00
eeckstein
38efe16ad5 Merge pull request #36355 from eeckstein/fix-arrayslice
stdlib: fix ARC for getting an ArraySlice of an CocoaArray with non-contiguous storage.
2021-03-10 09:12:50 +01:00
Erik Eckstein
375f289597 stdlib: fix ARC for getting an ArraySlice of an CocoaArray with non-contiguous storage.
For this special case we copied the objects out of the cocoa array without retaining them.
This lead to a double-free crash.

Unfortunately I could not come up with an isolated test case.

rdar://74624065
2021-03-08 20:34:19 +01:00
Erik Eckstein
5be350a975 stdlib: add a semantic attribute on the String.utf8CString and define it as "readonly"
Needed for StringOptimization.
2021-03-08 08:34:53 +01:00
Xiaodi Wu
d4300dd7fe [stdlib] Fix conversion from Float16 to unsigned integer types (#36219)
* [stdlib] Fix conversion from Float16 to unsigned integer types

* [stdlib] Tighten up concrete Float16-to-integer conversions
2021-03-02 08:57:41 -05:00
Karoy Lorentey
0836707303 [stdlib] Deprecate MutableCollection._withUnsafeMutableBufferPointerIfSupported (#36003)
* [stdlib] Deprecate MutableCollection._withUnsafeMutableBufferPointerIfSupported

In Swift 5.0, [SE-0237] introduced the public `MutableCollection.withContiguousMutableStorageIfAvailable` method. It’s time we migrated off the old, underscored variant and deprecated it.

The default `MutableCollection.sort` and `.partition(by:)` implementations are currently calling this hidden method rather than the documented interface, preventing custom Collection implementations from achieving good performance, even if they have contiguous storage.

[SE-0237]: https://github.com/apple/swift-evolution/blob/master/proposals/0237-contiguous-collection.md

* [test] Update tests for stdlib behavior changes

* Update stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

Co-authored-by: Nate Cook <natecook@apple.com>

* Update stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

Co-authored-by: Nate Cook <natecook@apple.com>

* Apply suggestions from code review

Co-authored-by: Nate Cook <natecook@apple.com>

* [test] LoggingMutableCollection: Fix logging targets

* [stdlib] Fix warning by restoring original workaround

Co-authored-by: Nate Cook <natecook@apple.com>
2021-02-26 11:32:27 -08:00
Karoy Lorentey
aede1cca1a [stdlib] Document a fatal surprise with Sequence._copyContents
Array’s _copyContents implementation traps if given too small a buffer. This prevents Sequence._copyContents from being used to speed up copying data into discontiguous memory. (We have to require a Collection conformance and run _copyContents on slices instead).

Document the underlying requirement.
2021-02-26 00:43:19 -08:00
Michael Gottesman
91317c723c [ownership] Make whether or not we serialize in OSSA form based off of the flag -enable-ossa-modules.
I added a change to CMake so that the stdlib still gets the option passed in so
should be NFC.
2021-02-22 19:07:45 -08:00
Doug Gregor
d9e4184742 Make Error and CodingKey conform to ConcurrentValue.
Make both Error and CodingKey conform to ConcurrentValue, so that
thrown errors always conform to ConcurrentValue. Downgrade (to
warnings) and ConcurrentValue-related diagnostics that are triggered
by this change in existing Error and CodingKey-conforming types to
reduce the impact on source compatibility.
2021-02-20 22:01:28 -08:00
Karoy Lorentey
9acf214b98 Merge pull request #36002 from lorentey/inline-partitioning-impl
[stdlib] Make MutableCollection.partition(by:) implementation inlinable
2021-02-17 18:56:55 -08:00
Alex Martini
9eabba58cb Make abstracts one sentence long.
The second sentence was added while rewriting to remove 'iff' in commit
6bc4c85005.
2021-02-17 15:31:24 -08:00
Alex Martini
db9fc0beed Fix a few contractions, per reference style guide. 2021-02-17 15:16:34 -08:00
Alex Martini
0b9ae84d66 Remove misleading comment about .zero.
There's nothing useful to say about the type of .zero -- it's
constrained by the protocol to Self, so you don't have any choice what
it is when conforming to AdditiveArithmetic.

Fixes <rdar://problem/72592923> (SR-13983).
2021-02-17 15:09:49 -08:00
Alex Martini
cc708f8cf6 Make an abstract one sentence long.
Fixes <rdar://problem/70543419>.
2021-02-17 15:03:18 -08:00
Alex Martini
9180e6a373 Use the correct argument label in prose.
See also these commits, which fixed the same issue in the code listing:

    589dd73d39
    bbe1811950
2021-02-17 14:52:00 -08:00
Alex Martini
349034651c Add missing code voice. 2021-02-17 14:52:00 -08:00
Alex Martini
e19a2f5811 Avoid 'a' vs 'an' alternation before type name. 2021-02-17 14:51:59 -08:00
Alex Martini
b92a5bd290 Fix spelling and stray space. 2021-02-17 14:51:59 -08:00
Alex Martini
d7ac2123d8 Keep doc comment before declaration.
Because the attribute is part of the declaration, putting a doc comment
between the attribute and "public" ends up with the comment in the
middle of the declaration.  This results in SourceKit skipping over the
comment, and the docs not being shown.

Fixes <rdar://problem/58716408>.
2021-02-17 14:51:58 -08:00
Alex Martini
5fb5a7265b Put code snippet in code voice.
Fixes <rdar://problem/65609221>.
2021-02-17 14:51:58 -08:00
Alex Martini
aad4fed25d Document floating point descriptions.
Fixes <rdar://problem/51409021>.
2021-02-17 14:51:57 -08:00
Karoy Lorentey
4f016c9caf [stdlib] Make MutableCollection.partition(by:) implementation inlinable
The default `partition(by:)` implementation cannot currently be specialized, which makes it ~64-100x slower than it could be for common cases. (E.g., `Array<Int>.partition(by: { $0 >= foo})` is slower than `.sort()` by a factor of 2-32.)

Make the implementation inlinable.
2021-02-16 13:56:17 -08:00
Slava Pestov
7a500a1307 stdlib: Float16 needs an @available annotation for macOS
Even though Float16 is unavailable on macOS, the type metadata can
still be referenced, for example from another unavailable declaration.

Make sure it has the correct OS version annotation so that it can be
weak linked.

Part of <rdar://problem/72151067>.
2021-02-16 13:54:27 -05:00
Mike Ash
a84a3a8f23 [Stdlib] Fix _swift_modifyAtWritableKeyPath_impl to check for ReferenceWritableKeyPaths.
Call through to _swift_modifyAtReferenceWritableKeyPath_impl in that case. This fixes an assertion failure (or worse) when upcasting a ReferenceWritableKeyPath and then using subscript(keyPath:) to modify a value with it.

rdar://74191390
2021-02-11 13:58:34 -05:00