Commit Graph

6024 Commits

Author SHA1 Message Date
Guillaume Lessard
9fbf3594da Merge pull request #38828 from glessard/sr9604
[stdlib] implement _copyContents for UnsafeRawBufferPointer
2021-08-21 16:47:04 -06:00
David Smith
834e82b7da Avoid an unnecessary call to CFStringGetCharactersPtr in bridging 2021-08-20 00:40:54 -07:00
Karoy Lorentey
48fa06b7f9 [stdlib] ContiguousArray & ArraySlice: Stop swapping self in wUMBP
Implements https://github.com/apple/swift/pull/38867 for ContiguousArray and ArraySlice -- these have the same unnecessary swapping logic.
2021-08-16 14:27:24 -07:00
Karoy Lorentey
ed287af766 [stdlib] Stop swapping self in Array.withUnsafeMutableBufferPointer
The law of exclusivity now allows us to remove the safety belt of swapping out self, getting rid of the need to create an empty array. (Which eliminates a swift_retain call.)
2021-08-12 19:30:37 -07:00
Alejandro Alonso
b651278616 Fix a crash on Scalar init with negative numbers (#38829) 2021-08-12 11:42:54 -07:00
Guillaume Lessard
af036db7bd [stdlib] implement _copyContents for UnsafeRawPointer 2021-08-10 15:35:07 -06:00
Xi Ge
ed13a2f0e4 ABI checker: require explicit @available attributes for new APIs
Before this change, the ABI checker didn't complain about missing @available
attributes on new APIs if the enclosing scopes of new APIs have
availability information. Instead, we should require explicit @available attributes
for new APIs to prevent them inheriting wrong availability information from a
preexisting scope.

rdar://81719628
2021-08-10 11:24:08 -07:00
Stephen Canon
a3ba517837 Mark legacy overloads of &+ and &- unavailable. (#38723)
These were defined for both FixedWidthInteger and FixedWidthInteger & SignedInteger for source compatibility with Swift 3; the latter set probably should have been removed when we stabilized the ABI, but were not. We can't easily remove them entirely (because we need them for ABI stability now), but we can mark them unavailable so that the typechecker doesn't have to consider them..
2021-08-05 21:18:48 -04:00
Stephen Canon
ce122dbb81 Clarify the documentation of SignedNumeric.
Previously we said that a type conforming to SignedNumeric allows positive and negative values, but that's nonsense. A type conforms to signed numeric if it has a negate() operation; it doesn't even have to have a notion of positive or negative values (for examples, see complex numbers, quaternions, integers mod n, etc).
2021-08-04 23:03:33 -04:00
Becca Royal-Gordon
627ecbdfff Rip designated types out of the AST
Designated types were removed from the constraint solver in #34315, but they are currently still represented in the AST and fully checked. This change removes them as completely as possible without breaking source compatibility (mainly with old swiftinterfaces) or changing the SwiftSyntax tree. Designated types are still parsed, but they are dropped immediately and a warning is diagnosed. During decl checking we also still check if the precedence group is really a designated type, but only so that we can diagnose a warning and fall back to DefaultPrecedence.

This change also fixes an apparent bug in the parser where we did not diagnose operator declarations that contained a `:` followed by a non-identifier token.
2021-08-03 16:13:59 -07:00
Guillaume Lessard
92335b115a Merge pull request #38677 from glessard/sr14491-v1
[stdlib] fast path for UMBP.initialize<C>(from: C) when C is a Slice
2021-08-03 11:28:32 -06:00
Guillaume Lessard
1e6b758330 Merge pull request #38509 from glessard/sr14850
[stdlib] prevent MutableCollections from inappropriately inheriting a Slice<Self> subscript
2021-08-02 14:12:29 -06:00
Guillaume Lessard
3302750fa2 [stdlib] avoid ABI impact 2021-08-02 12:20:24 -06:00
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