Commit Graph

5543 Commits

Author SHA1 Message Date
Erik Eckstein
dfc5b06819 stdlib: annotate Array's remove functions with semantic attributes.
All mutating Array functions must be annotated with semantics, because otherwise some high level optimizations get confused.
The semantic attributes prevent inlining those functions in high-level-sil.
This is need so that the optimizer sees that the Array is taken as inout and can reason that it's modified.

This restriction is not needed anymore when we’ll have COW representation in SIL.

rdar://problem/58478089
2020-01-10 17:09:47 +01:00
Cory Benfield
68f0816daa [stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View
Due to an oversight it seems that we never added a
withContigousStorageIfAvailable implementation to SubString.UTF8View,
which meant that if you sliced a String you lost the ability to get fast
access to the backing storage. There's no good reason for this
functionality to be missing, so this patch adds it in by delegating to
the Slice implementation.

Resolves SR-11999.
2020-01-10 09:10:09 +00:00
Erik Eckstein
60a0718922 stdlib: simplify Array/ContiguousArray's withUnsafeMutableBufferPointer and withUnsafeMutableBufferPointer
Again, to reduce code size
2020-01-09 16:17:38 +01:00
Erik Eckstein
bda8af0958 stdlib: simplify Array/ContiguousArray's append(contentsOf:)
Instead of calling ArrayBuffer's _arrayAppendSequence, inline the code. This saves some code size.
2020-01-09 16:17:38 +01:00
Erik Eckstein
88a9ebb9f8 stdlib: Don't request additional capacity in Array/ContiguousArray's remove.
Just copy the buffer if it's not unique.
This also implies that if there is a copy-on-write in remove, "shrink" the capacity of the new buffer to the required amount of elements (instead of copying the capacity of the original buffer).
2020-01-09 16:17:38 +01:00
Erik Eckstein
ea3b6a02af stdlib: rewrite Array/ContiguousArray logic for reserving capacity and creating a new buffer.
Share more code and avoid the large generic functions of ArrayProtocol.
The result is a significant code size win.
2020-01-09 16:17:38 +01:00
tbkka
93d07c6c30 _isOptional(type(of: value)) Does Not Do What You Think It Does (#28994)
In particular, if value is `Any` in a generic context, then `type(of: value)` is
`Any.Protocol` which is never considered optional.  As a result, the first
clause here was never actually being used for `print()` or other similar paths.
(Curiously, it _was_ used for string interpolation.)

This changes how we test for an optional type so that the first clause is consistently used for all optionals, even when they are wrapped in `Any` containers.

Fortunately? `print()` was producing the right results for
optionals because of a dynamic cast bug that failed to
unwrap optionals in these same contexts. <sigh>
2020-01-06 10:29:36 -08:00
tbkka
246d52defe Simplify the floating-point parsing initializers (#28992)
The original version scanned the entire input string for whitespace and
non-ASCII characters.  Both are unnecessary: the C routines we're building on
already stop at non-ASCII characters or non-leading whitespace.  So we need only
check the first character for whitespace and verify that all characters are
consumed.

This both improves performance and reduces the amount of code that gets inlined into consumers.
2020-01-06 09:52:21 -08:00
Karoy Lorentey
b7e08accb1 [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable (#28883)
* [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable

We can easily make an UnsafeBufferPointer that slices another UnsafeBufferPointer, so let’s allow Slice to vend a slice of the base collection’s contiguous storage, if it provides access to one.

We need to do some index distance calculations to implement this, but those will be constant-time in the usual case where the base collection is a RAC.

https://bugs.swift.org/browse/SR-11957
rdar://58090587

* [test] UnsafeBufferPointer: fix some warnings

* [stdlib] Slice: don’t calculate index distances unless the base provides contiguous mutable storage
2020-01-06 12:32:30 -05:00
kelvin13
ed2552a694 fix merge conflict and update caseless stdlib enums to use synthesized Comparable 2020-01-02 18:40:50 -06:00
David Smith
257c93a183 Use -[NSSet getObjects:] instead of -[NSSet getObjects:count:] to maintain compatibility with existing code passing NSArrays into this function 2019-12-16 15:43:16 -08:00
Karoy Lorentey
d83a4257f0 [stdlib] Don’t use assert() in the stdlib
assert() is designed to be used in user code only; the equivalent stdlib function is called _internalInvariant().

rdar://57101013
2019-12-11 19:23:46 -08:00
Luciano Almeida
392baefc47 [stdlib][Qol] SR-11295 Removing stdlib unnecessary coercions (#27165)
* Removing unnecessary casts from stdlib

* Minor adjustments

* [stdlib][qol] Clean up error variable assign NSError

* Removing unnecessary coercions after removing DeclRefExpr restriction.
2019-12-11 07:30:25 -08:00
Robert Widmann
43a3ab7e35 Merge pull request #28665 from CodaFi/the-phantom-menace
Explicitly State CodingKeys as a Codable Requirement
2019-12-10 21:06:01 -08:00
Karoy Lorentey
2e17867774 Merge pull request #28378 from JacobMao/fix/SR-11283
SR-11283: Amend OptionSet.remove method
2019-12-10 17:41:45 -08:00
Robert Widmann
3bda241b11 State CodingKeys as an explicit requirement
The presence of this attribute will be used to guide the protocol derivation machinery to synthesize CodingKeys.
2019-12-10 16:28:51 -08:00
Azoy
e3a440186a Reorder conformances in cake test 2019-12-07 14:53:13 -05:00
Azoy
eebf8825f9 post de-gyb formatting 2019-12-07 11:05:45 -05:00
Azoy
0c4aa6055f de-gyb unavailablestringapis 2019-12-07 11:05:45 -05:00
Azoy
3f5c7162cc de-gyb runtime 2019-12-07 11:05:45 -05:00
Azoy
73250ad93a de-gyb mirrors 2019-12-07 11:05:45 -05:00
Azoy
48672551c9 de-gyb existentialcollection 2019-12-07 11:05:44 -05:00
Azoy
eb8bd16ca5 de-gyb codable 2019-12-07 11:05:44 -05:00
Azoy
5469cd2c62 de-gyb builtinmath 2019-12-07 11:05:44 -05:00
Robert Widmann
5725984dc6 Merge pull request #28462 from dtorres/patch-1
[LazyFilterSequence] Preserve order of predicates
2019-12-03 19:37:36 -08:00
Erik Eckstein
3e932c075d stdlib: Add custom .first to Array
This makes Array.first much small and more efficient.
Without this, Array.first compiled down to RandomAccessCollection.first, which ended up in pretty unefficient code.

rdar://problem/46291397
2019-11-27 09:55:27 +01:00
Erik Eckstein
87298c07c8 stdlib: make the non-native Array.count smaller more efficient.
Use _CocoaArrayWrapper.endIndex which returns the NSArray.count.
In the old version, "count" translated to RandomAccessCollection.count, which ended up in multiple calls to endIndex.
2019-11-26 18:20:39 +01:00
Diego Torres
3c4eeadc83 Preserve order of predicates
Fixes https://bugs.swift.org/browse/SR-11841
2019-11-24 15:42:33 +01:00
zhuowei
b9c1deff5f [stdlib] fix return type of getNumRuntimeFunctionCounters (#24182)
The return type of getNumRuntimeFunctionCounters is defined as uint64_t in RuntimeInvocationsTracking.cpp, but it has return type Int in RuntimeFunctionCounters.swift.

Found when compiling the stdlib for WebAssembly, as WebAssembly validates return types. uint64_t corresponds to i64, but Int is i32, so the program fails validation.
2019-11-22 13:44:56 -05:00
Stephen Canon
671df74418 Use the truncatingIfNeeded init on the result of these runtime funcs. (#28426)
The swift_floatNToString, swift_int64ToString, and swift_uint64ToString functions all return a uint64_t from c++. This is a historical accident, but these are SWIFT_RUNTIME_STDLIB_API, which means that we can't trivially change the return type. The result should naturally be size_t or int (it's always small enough to fit into *any* c integer type). However, we can elide the check in the caller at the point that the result is converted to Int, because we know that the check will always pass. This makes it so that the only overhead the wrong type introduces on 32b platforms is zeroing a register, which is free or nearly-free.
2019-11-21 20:45:04 -05:00
zhuowei
8b3a15babf [stdlib] Fix return type of swift_{uint64,int64,float*}ToString (#24181)
The return type of these functions are uint64_t in Stubs.cpp but UInt in the Swift code; this changes the Swift code to match the C++ return type.

Found when compiling the stdlib for WebAssembly, which requires that all return types match: UInt maps to i32 while uint64_t maps to i64, so functions calling these functions fail the validation.
2019-11-21 17:21:22 -05:00
Robert Widmann
b9fe66e0e8 Add documentation to _DependenceToken 2019-11-21 10:48:18 -08:00
Mao ZiJun
d5e2533cef improved OptionSet.remove's code style 2019-11-21 14:55:39 +09:00
Mao ZiJun
a8fd973876 fixed OptionSet's remove method 2019-11-21 11:25:41 +09:00
swift-ci
598042b521 Merge pull request #21550 from valeriyvan/patch-1 2019-11-18 15:27:40 -08:00
Slava Pestov
50872964dd Merge pull request #28289 from slavapestov/generic-parameters-are-unreliable-witnesses
Revert "Sema: Look for generic parameters first when inferring an associated type"
2019-11-16 01:56:16 -05:00
Nate Cook
8bfe519413 [stdlib] Use RRC.filter in removeAll(where: _) (#18825) 2019-11-15 16:24:27 -06:00
Slava Pestov
55e3797471 Revert "Sema: Look for generic parameters first when inferring an associated type"
This breaks source compatibility a little bit more than we'd like, so
reverting it for now.

Fixes <rdar://problem/57213598>.

This reverts commit 04fbcc0149.
2019-11-15 14:32:13 -05:00
Nate Cook
7c0ed24867 [stdlib] Document Windows implementation of SystemRandomNumberGenerator (#28268) 2019-11-15 10:38:44 -06:00
Slava Pestov
04fbcc0149 Sema: Look for generic parameters first when inferring an associated type
Previously we did this as a last resort if inference fails. The new
behavior is technically source-breaking, but I suspect nobody
relied on the old behavior.

This can help avoid cycles by eliminating some unnecessary validation work.

Fixes <https://bugs.swift.org/browse/SR-11407>, <rdar://problem/54979757>.
2019-11-13 23:42:08 -05:00
Michael Ilseman
1d63710a06 Merge pull request #28016 from milseman/swept_under_the_bridge
[stdlib] [gardening] Refactor bridging from StringStorage.swift
2019-11-06 13:43:32 -08:00
Dan Zheng
53e61a9587 [AutoDiff upstream] Add the _Differentiation module. (#27511)
The `_Differentiation` module is the experimental support library for
differentiable programming. It is built when the build-script flag
`--enable-experimental-differentiable-programming` is enabled.

The `Differentiable` protocol generalizes all types that work with
differentiation. It is a core piece of the differentiable programming
project. Other parts depending on the `Differentiable` protocol will
be upstreamed piece by piece.

The `Differentiable` protocol is compiler-known and will be used during
type-checking, SILGen, and the SIL differentiation transform.
2019-11-06 11:31:12 -08:00
Hamish Knight
1bc56dcc11 [stdlib] Mark some parameters @_nonEphemeral
These include the pointer-to-pointer and pointer-to-buffer-pointer
initialiser parameters amongst a couple of others, such as
`Unmanaged.fromOpaque`, and the source for the `move[...]` family of
methods.
2019-11-03 08:42:26 -08:00
Michael Ilseman
8463e53df3 [stdlib] [gardening] Refactor bridging from StringStorage.swift
Add StringStorageBridge.swift to separate out ObjC interop
functionality.

NFC
2019-11-01 17:25:08 -07:00
David Smith
ed1f9b30ef Implement both -isEqual: and -isEqualToString: to directly call the internal _isEqual, to avoid a redundant ObjC message send + type check 2019-10-28 16:36:13 -07:00
David Smith
637af2f9fe Merge pull request #27709 from Catfish-Man/bridge-to-the-future
Optimize accessing Swift arrays via ObjC
2019-10-23 00:19:06 -07:00
David Smith
d9cef0afef Optimize accessing Swift Arrays from ObjC 2019-10-22 20:57:36 -07:00
Julian Lettner
e819acdc29 Merge pull request #27808 from apple/tsan-empty-array-storage
[TSan] Do not report benign race on `_swiftEmptyArrayStorage`
2019-10-21 18:39:36 -07:00
David Smith
282e0c858b Merge pull request #27826 from Catfish-Man/last-object-standing
Bridging fidelity: allow removeLastObject() on empty NSMutableArrays
2019-10-21 18:32:24 -07:00
David Smith
da6adc8ba2 Bridging fidelity: allow removeLastObject() on empty NSMutableArrays 2019-10-21 17:20:32 -07:00