Commit Graph

7762 Commits

Author SHA1 Message Date
Guillaume Lessard
f6f36fa6d1 [stdlib] simplify indexing 2021-08-02 12:20:24 -06:00
Alastair Houghton
ad147308af Merge pull request #38309 from al45tair/problem/47902425
[Runtime] Add ObjC support to isKnownUniquelyReferenced.
2021-08-02 17:39:49 +01:00
Guillaume Lessard
9457406d0b Merge pull request #38463 from wongzigii/SR-14886
Check withContiguousStorageIfAvailable before copying byte by byte
2021-07-30 09:40:09 -06:00
ZigiiWong
26b3c55c23 [SR-14886] Check wCSIA before copying byte by byte. 2021-07-30 11:04:15 +08:00
Alastair Houghton
abec55f432 [Runtime] Add ObjC support to isKnownUniquelyReferenced.
Add code to support detecting uniquely referenced Objective-C and Core
Foundation objects.

rdar://47902425
rdar://66805490
2021-07-29 16:29:48 +01:00
Guillaume Lessard
2bc053f815 [stdlib] implement _copyContents for Slice
`Sequence._copyContents(initializing:)` is the function relied on by
`UnsafeMutableBufferPointer` for performant initialization from Collections.
Until now, `Slice<Base: Collection>` has not had its own implementation,
and therefore fell back to the default version implemented on `Sequence`.

This implementation adds an attempted fast path, using
`withContiguousStorageIfAvailable`. If that fails, the `Sequence`
algorithm is used, as before.

This resolves https://bugs.swift.org/browse/SR-14491
2021-07-28 15:23:03 -06:00
Guillaume Lessard
a9e0af40d3 [stdlib] make Sequence's _copyContents call into a non-protocol function 2021-07-28 15:23:03 -06:00
Guillaume Lessard
9ccf71e0b7 [stdlib] More MutableCollection fix to _SmallString 2021-07-28 02:13:45 -06:00
swift-ci
6d07945ff2 Merge pull request #38635 from lorentey/update-subsequence-docs 2021-07-27 21:17:50 -07:00
Karoy Lorentey
849f6b9818 [stdlib] Update SubSequence docs 2021-07-27 18:40:23 -07:00
David Smith
97073fb5a8 Fast-path contains() for empty Dictionaries 2021-07-26 17:12:00 -07:00
Guillaume Lessard
53db35c80f [stdlib] fix availability annotation 2021-07-23 13:40:19 -06:00
Guillaume Lessard
0ea4e3c4d9 [stdlib] add availability annotations and tests 2021-07-21 09:20:12 -06:00
Guillaume Lessard
3789ce292a [stdlib] fix an accidental recursion bug involving MutableCollection
- add a default implementation of MutableCollection’s
  subscript(bounds: Range<_>) with the most general signature possible
- it is marked unavailable in order to prevent the
  infinite recursion bug reported in SR-14848
- add a conditionally-available subscript(bounds: Range<_>) -> Slice<Self>
  only when Subsequence is Slice<Self>. This will supersede
  the unconditional extension that provides the same signature.
2021-07-20 16:11:23 -06:00
Guillaume Lessard
50e7c98583 [stdlib] MutableCollection fix to _SmallString 2021-07-20 13:25:55 -06:00
Guillaume Lessard
3b78f38438 Merge pull request #38438 from glessard/umbp-allocate-deduplication
[stdlib] remove duplicated code
2021-07-16 22:22:23 -06:00
Guillaume Lessard
ae10c297a9 make documentation of UMRBP.allocate() more complete. 2021-07-16 12:33:24 -06:00
Guillaume Lessard
e946cd02c0 remove duplicated code
- call `UnsafeMutablePointer.allocate(capacity:)` from
  `UnsafeMutableBufferPointer.allocate(capacity:)`.
- This was a straight code duplication.
2021-07-16 12:18:33 -06:00
Guillaume Lessard
7f68d6a4f5 document the requirement that allocation alignments must be powers of two. 2021-07-15 19:19:15 -06:00
Xiaodi Wu
1ca4d7cbc3 [stdlib] Make unavailable protocol implementation @_alwaysEmitIntoClient and add a comment about use of Lemire's nearly divisionless method (#38263) 2021-07-06 11:24:19 -04:00
Stephen Canon
d18305caa0 We don't need the unavailable default implementation of RNG.next() to be ABI.
Make it @_aEIC so that we're not stuck with it forever if we get a better solution someday.
2021-07-06 08:15:03 -04:00
Ted Kremenek
6a1e58a5c3 Merge pull request #38103 from kylemacomber/never-identifiable
Conform Never to Identifiable
2021-07-02 19:31:24 -07:00
Guillaume Lessard
6053c47f6d Merge pull request #38161 from glessard/sr14848
[stdlib] fix an accidental recursion bug involving Collection
2021-07-01 07:58:53 -06:00
Guillaume Lessard
7d6260560e [stdlib] fix an accidental recursion bug involving Collection
- adds a default implementation of Collection’s subscript(bounds: Range<_>)
  with the most general signature possible
- it is marked unavailable in order to prevent the
  infinite recursion bug reported in SR-14848
- Collections whose SubSequence is Slice<Self> still get the proper default, as intended.
2021-06-30 21:58:48 -06:00
Kyle Macomber
98bdf354ca Minor edit based on pitch thread feedback 2021-06-29 16:15:43 -07:00
Kyle Macomber
4c169c12ba Conform Never to Identifiable
rdar://75988520
2021-06-28 20:11:55 -07:00
eeckstein
53fc177261 Merge pull request #37945 from eeckstein/fix-cow-check-availability
stdlib: fix availability for internal COW checks.
2021-06-22 07:20:40 +02:00
Guillaume Lessard
dc11047dcc Merge pull request #37697 from glessard/availability-message-fix
[documentation] make `customPlaygroundQuickLook` availability message match reality
2021-06-17 16:42:20 -06:00
Erik Eckstein
2f2c132e27 stdlib: fix availability for internal COW checks.
Those checks should only be done if linked with a built library, but not when linked with the OS libraries.
2021-06-17 11:30:59 +02:00
Alastair Houghton
6ec0bbd49c Merge pull request #37949 from al45tair/problem/56473712
Print raw values for C/C++ enums.
2021-06-17 09:10:39 +01:00
Karoy Lorentey
5847452f54 Merge pull request #37914 from lorentey/fix-array-storage-access
[stdlib] Implement _copyContents on internal Array types
2021-06-16 18:06:33 -07:00
Karoy Lorentey
466e26a872 [stdlib] Implement _copyContents on internal Array types
`_copyContents(initializing:)` is a core method of Sequence, and it is used surprisingly often to copy stuff out of sequences. Array’s internal types currently have explicit implementations of it that trap (to prevent a performance bug due to the default iterator-based implementation. This has proved a bad idea, as not all code paths that end up calling `_copyContents` have actually been expunged — so we replaced a performance bug with a catastrophic correctness bug. 😥

Rather than trying to play whack-a-mole with code paths that end up in `_copyContents`, replace the traps with (relatively) efficient implementations, based on the ancient `_copyContents(subRange:initializing)` methods that have already been there all this time.

This resolves https://bugs.swift.org/browse/SR-14663.

I expect specialization will make this fix deploy back to earlier OSes in most (but unfortunately not all) cases.
2021-06-16 13:47:00 -07:00
Alastair Houghton
02a13e71c7 Print raw values for C/C++ enums.
When printing C/C++ enum values, in lieu of having proper metadata for the enum
type, try to display a raw value (see SR-6550)

rdar://56473712
2021-06-16 14:45:50 +01:00
swift-ci
6c2c03d588 Merge pull request #37892 from NevinBR/patch-2 2021-06-15 22:43:54 -07:00
Stephen Canon
f538b49fc9 Use the "nearly divisionless" algorithm on all targets. (#37920)
* Use the "nearly divisionless" algorithm on all targets.

We have multipliedFullWidth available everywhere now, so we don't need to carry around the old implementation on 32b targets.

Also adds a few more benchmarks for random number generation.

* Obscure the range boundaries for some of the new random value benchmarks.

When these are visible compile-time constants, the compiler is smart enough to evaluate the division in the "nearly divisionless" algorithm, which makes it completely divisionless. That's good, but it obscures what the runtime performance of the algorithm will be when the bounds are _not_ available as compile-time constants. Thus, for some of the newly-added benchmarks, we pass the upper bound through `identity` to hide it from the optimizer (this is imperfect, but it's the simplest tool we have).

We don't want to do this for all the tests for two reasons:
- compile-time constant bounds are a common case that should still be reflected in our testing
- we don't want to perturb existing benchmark results more than we have to.
2021-06-15 20:27:49 -04:00
Guillaume Lessard
a1d1b2d9ba Merge pull request #37836 from glessard/initialize-repeating
[doc] update doc-comment references to a long-renamed function
2021-06-15 16:27:37 -06:00
NevinBR
1c94fbe25c Apply suggestions from code review
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-06-15 09:05:40 -04:00
NevinBR
7477f99f24 Updated diagram to show srcHigh and destLow are the same 2021-06-14 23:04:57 -04:00
Stephen Canon
9956097927 Use the custom implementation of multipliedFullWidth on arm64_32 (#37905)
Previously we were falling back on the generic implementation for 64b integers, which resulted in the following codegen:

00000008	asr	x8, x0, #32
0000000c	asr	x9, x0, #63
00000010	cmp	x0, #0x0
00000014	cinv	w10, w0, lt
00000018	eor	w9, w10, w9
0000001c	asr	x10, x1, #32
00000020	asr	x11, x1, #63
00000024	cmp	x1, #0x0
00000028	cinv	w12, w1, lt
0000002c	eor	w11, w12, w11
00000030	umull	x12, w11, w9
00000034	mul	x11, x11, x8
00000038	add	x11, x11, x12, lsr #32
0000003c	asr	x12, x11, #63
00000040	cmp	x11, #0x0
00000044	cinv	w13, w11, lt
00000048	eor	w12, w13, w12
0000004c	madd	x9, x9, x10, x12
00000050	mul	x8, x10, x8
00000054	add	x8, x8, x11, asr #32
00000058	add	x0, x8, x9, asr #32
0000005c	ret

Instead, we should use the 64b implementation when targeting arm64_32, which allows us to generate:

00000008	smulh	x0, x1, x0
0000000c	ret

Unsurprisingly, this is considerably faster.
2021-06-14 21:38:51 -04:00
NevinBR
ed0b7737fd [nfc] Fixed typos in comments in Sort.swift
There is still an incongruity between where `srcHigh` and `destHigh` are displayed in the diagram:

`srcHigh` is shown at the location it logically represents, not its true position which is one past that, whereas `destHigh` (as well as `bufferHigh`) is shown at its true position (past the end) not at the location it logically represents.

I am not sure if that is intentional.
2021-06-11 23:27:51 -04:00
Guillaume Lessard
2bcc6a7f72 [doc] update doc-comment references to a long-renamed function
fixes SR-12938
2021-06-08 15:05:13 -06:00
Mishal Shah
23c3b15f5f Support Xcode 13 beta
* Updating availability versions
* Remove all remaining overlays in stdlib/public/Darwin/*:
   - ObjectiveC
   - Dispatch
   - CoreFoundation
   - CoreGraphics
   - Foundation
2021-06-07 12:04:31 -07:00
Guillaume Lessard
09ea2fbda5 bring customPlaygroundQuickLook availability message in line with reality
- all other instances of the customPlaygroundQuickLook availability message
  mention "a future Swift version" rather than "Swift 5.0".
2021-05-28 15:11:11 -06:00
Chris Adamson
8f76011ac4 Remove extraneous /-es from license comments. (#37632)
Co-authored-by: Chris Adamson <cadamson@apple.com>
2021-05-26 14:20:17 -04:00
Kyle Macomber
c09bdead88 Fixes copyright comment
rdar://78178197
2021-05-25 21:08:42 -07:00
Cory Benfield
b1683c89be Remove as much checked math as possible from buffer pointers.
This patch removes as much checked math as I was able to find from the
unsafe buffer pointers types. In particular, I removed two kinds of
checked math:

1. Checked math that was provably unable to trap due to prior operations
   done in the same function, or in a function that must have been
   called before the current one. For example, in
   index(_:offsetBy:limitedBy:), when we do the final index addition we
   have already validated that it must be in-bounds. Therefore, it
   cannot overflow.
2. Checked math that can only fail if the user is misusing the indices.
   As previously discussed with Karoy and Andrew, the unsafe raw buffer
   types are not obligated to crash if you misuse their indices, they
   are free to invoke undefined behaviour. In these cases, I added
   defensive overflow checks in debug mode.

The result of this change should be reductions in code size in almost
all usage sites of the raw buffer types.
2021-05-21 09:25:32 +01:00
ensan
b24892becf rename hasPrefix(_ prefix: String) -> Bool to hasSuffix(_ suffix: String) -> Bool (#37336) 2021-05-08 12:31:14 -04:00
swift-ci
512be2cec6 Merge pull request #36945 from tbkka/tbkka/rdar76728925 2021-04-20 18:12:34 -07:00
Robert Widmann
b65777eabe Merge pull request #36963 from CodaFi/arm64_32
Add arm64_32 support for Swift
2021-04-20 17:42:56 -07:00
Alex Martini
4b2f4874b3 Use markup for a note box. 2021-04-20 15:46:45 -07:00