Commit Graph

6693 Commits

Author SHA1 Message Date
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
Tim Kientzle
fbec09bd56 Consolidate format-independent discussion at the end 2021-04-20 15:40:39 -07:00
Robert Widmann
0149ccd0ca Add arm64_32 support for Swift
Commit the platform definition and build script work necessary to
cross-compile for arm64_32.

arm64_32 is a variant of AARCH64 that supports an ILP32 architecture.
2021-04-20 14:59:04 -07:00
Stephen Canon
8736683cf7 Prevent arbitrary objects from conforming to RNG. (#36969)
Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at anything: "RNG."
2021-04-20 16:39:16 -04:00
Tim Kientzle
2a476586d7 Backwards compatibility note 2021-04-20 11:25:03 -07:00
Tim Kientzle
1d5eb5b2be Wordsmithing 2021-04-19 10:30:31 -07:00
Tim Kientzle
0c7f85c56d Feedback 2021-04-19 10:25:09 -07:00
Tim Kientzle
33226b0505 Distinguish "string" (input), "value" or "number" (abstract real number that the string represents), and "instance" (the resulting ${Self}). 2021-04-19 09:09:11 -07:00
Tim Kientzle
b183c7d6c3 present, not future 2021-04-16 16:12:12 -07:00
Tim Kientzle
20ba149dc3 More wordsmithing. 2021-04-16 14:00:11 -07:00
Tim Kientzle
98cec1321d Document how out-of-range inputs are handled
This changed recently so that overflow and underflow consistently return signed
infinity or zero instead of nil.  (Previously, overflow returned nil, underflow
returned zero.)

Among other benefits:
 * The new behavior distinguishes malformed input (nil) from valid but out-of-range input.
 * The new behavior preserves the sign of the input
 * The new behavior is consistent with how floating-point parsing behaves in other langauges

Resolves rdar://76728925
2021-04-16 10:22:59 -07:00
Doug Gregor
194536472a [AnyHashable] Work around older compiler limitation.
An older Swift compiler failed to account for the witnesses in a
conformance with platform availability having their own availability,
which causes that compiler to reject the Swift module's .swiftinterface
file when it includes `AnyHashable` 's conformance to
`_HasCustomAnyHashableRepresentation`. Work around the issue by making
the one witness (`_toCustomAnyHashable`, which is trivial)
always-emit-into-client, so it does not need any availability.

Fixes rdar://76370138.
2021-04-15 21:21:41 -07:00
heoblitz
20ffc036ed Add whitespace to markup 2021-04-14 14:43:14 +09:00
Benzi
4e0c6f99b8 [stdlib] Set.intersection iterate over smaller set (#36678)
* [stdlib] Set.intersection iterate over smaller set

When intersecting two sets, it is beneficial to iterate over the smaller sized set of the two, and check membership on the other. This speeds up runtime dramatically for cases where the current set is significantly larger than the set you are intersecting against.

* Review comments - variable names, implicit swap
2021-04-11 11:42:10 -04:00
Ben Cohen
125902923c Revert lazy mirror children (#36722) 2021-04-08 16:34:50 -10:00
Doug Gregor
fcd5d43457 Revert "stdlib: Add reasync variants of '&&', '||' and '??'" 2021-04-05 16:45:44 -07:00
Alex Martini
1c5c111aab Merge pull request #36709 from amartini51/main
Doc comment corrections
2021-04-05 15:46:31 -07:00
Michael Ilseman
9ab21d3215 Merge pull request #36623 from xwu/better-atoi
[stdlib][SR-7556] Re-implement string-to-integer parsing
2021-04-03 08:30:25 -06:00
Michael Ilseman
f495c02afe Merge pull request #36667 from milseman/small_differential
[stdlib] Fix bug in small string uninitialized init
2021-04-02 16:46:51 -06:00
Xiaodi Wu
cef11cd82e [stdlib][NFC] Final renamings for new integer parsing implementations. 2021-04-02 10:20:04 -04:00