Commit Graph

6024 Commits

Author SHA1 Message Date
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
Doug Gregor
422fb5cd57 Move String conformance to ConcurrentValue out-of-line. 2021-02-04 13:14:24 -08:00
Doug Gregor
f81621f2e1 Fix AutoreleasingUnsafeMutablePointer conformance 2021-02-04 12:31:15 -08:00
Doug Gregor
91ea115046 Use UnsafeConcurrentValue conformance for Array 2021-02-04 11:53:54 -08:00
Doug Gregor
0e2b658876 Fix build problem on Linux. _ArrayBuffer is Darwin-only 2021-02-04 08:35:22 -08:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Doug Gregor
866a8d8944 Introduce checking for ConcurrentValue conformance across actors.
When referring to an actor-isolated declaration from outside of the
actor, ensure that the types involved conform to the `ConcurrentValue`
protocol. Otherwise, produce a diagnostic stating that it is unsafe to
pass such types across actors.

Apply the same rule to local captures within concurrent code.
2021-02-03 17:37:43 -08:00
Doug Gregor
a632118d6a Sink ConcurrentValue into the standard library as a marker protocol
By making ConcurrentValue a marker protocol, it no longer has any ABI
impact whatsoever. Sink it down into the Standard Library so it's
easier to use, even from code that isn't building with concurrency
enabled.
2021-02-03 16:43:33 -08:00
Robert Widmann
1f116aed84 Merge pull request #35223 from masters3d/patch-2
[gardening] precondition message wording in stdlib/public/core/Misc.swift
2021-01-12 21:40:51 -08:00
Andrew Trick
c4661b9b47 Fix _StringObject.init(object:...)
Add a missing fix_lifetime. This miscompiles with OSSA because
`object` is destroyed before `bridgeObject` is retained.

Reinterpreting a reference to a trivial type always requires a
fix_lifetime.
2020-12-30 00:33:34 -08:00
Chéyo Jiménez
c87c9fe998 precondition message wording in stdlib/public/core/Misc.swift 2020-12-24 15:44:55 -05:00
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Nate Cook
c35b567001 Temporary removal of RangeSet/DiscontiguousSlice (#35076) 2020-12-14 08:42:01 -06:00
Karoy Lorentey
8082b58365 Merge pull request #34961 from lorentey/buffers-need-to-be-fast-but-not-too-fast
[stdlib] Review and fix some problems with unsafe buffer and Range initialization
2020-12-12 19:13:20 -08:00
Karoy Lorentey
94a7eeebe5 [stdlib] Document sources of code bloat 2020-12-11 18:31:00 -08:00
Karoy Lorentey
1f92df093c [stdlib] Add an unsafe U[M]BP initializer to work around some inliner test failures 2020-12-09 19:31:28 -08:00
Stephen Canon
95309e1dce Fixup Float16 availability for macCatalyst/x86_64 2020-12-09 13:51:51 -05:00
Karoy Lorentey
282a1408de [stdlib] U[R]BP: Restore compile-time condition lost with removed precondition 2020-12-08 22:25:16 -08:00
Karoy Lorentey
93368213cf [stdlib] Don’t use unbound ranges (foo[…]) in String → Substring conversions
The UnboundRange → Range conversion path is complicated and it involves at least one unnecessary _precondition check for startIndex ..< endIndex.
2020-12-04 19:55:39 -08:00
Karoy Lorentey
d1ef4c4386 [stdlib] Use [Closed]Range.init(_uncheckedBounds:) in more places
When the stdlib says not to check, it’s a good idea to actually not have any checking, so that we leave existing code paths unchanged. (And because we do trust that the stdlib is responsible about such things.)
2020-12-04 19:27:19 -08:00