Commit Graph

5783 Commits

Author SHA1 Message Date
Michael Gottesman
7820ddc7c7 [stdlib] Change _withUnsafeGuaranteedRef to use Builtin.convertUnownedUnsafeToGuaranteed.
This builtin (which lowers to raw SIL that doesn't use an actual builtin
instruction) allows us to access an unmanaged value at +0 with a language
guarantee rather than relying on the optimizer.

Previously, we did not do this directly since without OSSA, we were scared that
the frontend/optimizer would not be able to safely emit this code. Now that we
have ownership ssa, we are able to ensure that the frontend always copies the +0
value passed into the closure if the value +0 escapes from the closure (either
via a return, storing into memory, or by passing off as a +1 parameter to a
function).

rdar://59735604
2020-02-24 12:49:45 -08:00
Xiaodi Wu
ae423c5bcd [NFC] Replace two uses of 'fileprivate' with 'private' 2020-02-23 12:05:39 -05:00
Nate Cook
c6183ee71b Add RangeSet and discontiguous collection operations (#28161)
This adds the RangeSet and DiscontiguousSlice types, as well as collection
operations for working with discontiguous ranges of elements. This also adds
a COWLoggingArray type to the test suite to verify that mutable collection
algorithms don't perform unexpected copy-on-write operations when mutating
slices mid-operation.
2020-02-22 15:33:03 -06:00
Michael Ilseman
2897daa434 Merge pull request #22616 from karwa/substring_inline
[stdlib] Make some trivial Substring methods inlinable
2020-02-20 09:25:38 -08:00
Alexis Laferrière
814491af50 Merge pull request #29942 from xymus/spitdlib
[stdlib] Update one String initializer and client to use @_spi
2020-02-19 19:43:39 -08:00
David Smith
3fe6b65899 Merge pull request #24303 from Catfish-Man/uninitialized-initialize
Add the new uninitialized buffer String initializer privately and use it to fix a perf TODO in append
2020-02-19 16:42:25 -08:00
Alexis Laferrière
4055c94d6d [stdlib] Update one String initializer and client to use @_spi 2020-02-19 16:38:51 -08:00
David Smith
35e21b0bbd SR-10556 _foreignGrow should use the uninitialized-buffer String initializer once it's in 2020-02-19 11:17:11 -08:00
swift-ci
04fafd7e26 Merge pull request #29881 from swiftwasm/swiftwasm-string 2020-02-18 04:22:21 -08:00
Mike Ash
57a3df5da9 Merge pull request #29848 from mikeash/eagerly-realize-empty-singletons
[Stdlib] Eagerly realize EmptyDictionarySingleton and EmptySetSingleton.
2020-02-17 09:56:19 -05:00
Max Desiatov
8e705f3413 [WebAssembly] Add wasm32 support to stdlib String 2020-02-17 12:51:34 +00:00
tbkka
4d0e2adbef Further refinement of {Float,Double,Float80}.init(_:String) (#29028)
* Further refinement of {Float,Double,Float80}.init(_:String)

After talking with @stephentyrone, I found some additional simplifications. No
functional change, just shorter/simpler.

This makes the generic inlineable part a small stub that delegates to the full
non-inlined version.

ABI compatibility:
* We support the same generic init() as before
* _swift_stdlib_strtoXYZ_clocale is still available to
  support old inlined code

API addition:
* We now have a public specialized form of init?(_: Substring)
  in addition to the generic init?<S:StringProtocol> form.

* Add @available marker to new API

* Support back-deployment to older OSes by inlining the full version
2020-02-14 16:16:29 -08:00
Mike Ash
440d2799f7 [Stdlib] Eagerly realize EmptyDictionarySingleton and EmptySetSingleton.
These objects can escape into ObjC without their class being realized first, which can cause a crash if the unrealized class gets passed into the ObjC runtime.

rdar://problem/59295395
2020-02-14 11:57:52 -05:00
Devin Coughlin
664e7cc00e [Availability] Make _stdlib_isOSVersionAtLeast() no longer inlinable
To make it possible to change the implementation of
_stdlib_isOSVersionAtLeast(), remove the @inlinable attribute from it.

Since it is currently inlinable and calls the helper function
_swift_stdlib_operatingSystemVersion(), we’ll have to keep the
helper around as ABI.

This change causes a minor pessimization where the LLVM optimizer can no
longer reason that, for example, a successful check for 10.12 availability
means that a later check for 10.11 will always succeed. I don't expect this
pessimization to be a problem, but if needed we could write a custom SIL
optimizer pass to claw back the performance.

<rdar://problem/59447474>
2020-02-13 20:08:48 -08:00
Dmitri Gribenko
3566e6ed7a Merge pull request #29530 from swiftwasm/swiftwasm-ifdefs
[WebAssembly] Add ifdefs for the WASI target
2020-02-13 17:40:45 +01:00
Karoy Lorentey
bbd888f727 Merge pull request #29498 from xwu/any-hashable-docs
[docs] Update AnyHashable documentation
2020-02-12 13:16:15 -08:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00
Ravi Kandhadai
ec9844b2d9 [SIL Optimization] Add a new mandatory pass for unrolling forEach
calls over arrays created from array literals. This enables optimizing
further the output of the OSLogOptimization pass, and results in
highly-compact and optimized IR for calls to the new os log API.

<rdar://58928427>
2020-02-07 20:06:29 -08:00
Robert Widmann
1ed846d852 Merge pull request #25696 from kelvin13/comparable-enums
synthesized comparable for enums
2020-02-06 21:38:36 -08:00
Xiaodi Wu
06f12fc268 Incorporate further review comments 2020-02-05 20:30:33 -05:00
NevinBR
a7f28785c9 Fixes for FixedWidthInteger.random(in: ClosedRange<Self>, using:) (#29633)
Allow the closed-range version of `FixedWidthInteger.random(in:using:)` to work for types larger than 64 bits when the entire valid range (`.min ... .max`) is passed in.

Also, closed ranges are never empty, so the unnecessary `!isEmpty` precondition has been removed.
2020-02-05 17:17:20 +01:00
Kelvin
19a8759cee Merge branch 'master' into comparable-enums 2020-02-04 22:08:40 -06:00
Xiaodi Wu
4ee0cc16e1 Update stdlib/public/core/AnyHashable.swift
Co-Authored-By: Karoy Lorentey <klorentey@apple.com>
2020-01-29 21:15:04 -05:00
Xiaodi Wu
518ccce520 Optimize documentation wording for clarity 2020-01-28 21:07:58 -05:00
Xiaodi Wu
1e861acd1f Incorporate review comments 2020-01-28 21:00:52 -05:00
Ravi Kandhadai
c198c1a2aa [Constant Evaluator] Add support for BinaryInteger.description which
converts an integer to a string. This patch adds a @_semantics
annotation to the BinaryInteger.description function.
2020-01-27 21:13:50 -08:00
Xiaodi Wu
31e9807fc8 Update AnyHashable documentation 2020-01-27 22:00:33 -05:00
eeckstein
7b12c2efbf Merge pull request #29353 from eeckstein/dict-code-size
stdlib: move Dictionary's find functions into __RawDictionaryStorage.
2020-01-24 22:37:14 +01:00
Erik Eckstein
78728d8df5 stdlib: extract the common code of _NativeDictionary.resize and copyAndResize into a separate function
For code size reduction.
2020-01-24 10:40:41 +01:00
kelvin13
fb4bd68653 Merge branch 'master' into comparable-enums 2020-01-22 18:38:31 -06:00
Michael Ilseman
38de918213 Merge pull request #29146 from Lukasa/cb-substring-fast-access-2
[stdlib] Re-add withContiguousStorageIfAvailable to SubString.UTF8View
2020-01-22 10:36:58 -08:00
Erik Eckstein
ef007519b1 stdlib: move Dictionary's find functions into __RawDictionaryStorage.
The find functions do not require the generic Value parameter. Moving them to __RawDictionaryStorage allows to define them with only one generic parameter: the Key.
This allows the optimizer to share specializations for dictionaries which have the same Key, but a different Value.
Also, prevent inlining of the find-functions to save some additional code size.
2020-01-22 15:29:32 +01:00
eeckstein
2715c705f4 Merge pull request #29220 from eeckstein/improve-array-append
stdlib: add a shortcut for Array.append(contentsOf:) in case the argument is an Array, too.
2020-01-16 11:51:20 +01:00
Brent Royal-Gordon
0c478b6be6 Revert "Merge pull request #28665 from CodaFi/the-phantom-menace"
This reverts commit 43a3ab7e35, reversing
changes made to 4f39d9c749.

# Conflicts:
#	include/swift/AST/Attr.def
#	lib/AST/Attr.cpp
#	lib/Serialization/Deserialization.cpp
#	lib/Serialization/ModuleFormat.h
#	lib/Serialization/Serialization.cpp
2020-01-15 15:28:42 -08:00
Erik Eckstein
172c72b95a stdlib: add a shortcut for Array.append(contentsOf:) in case the argument is an Array, too.
This additional check lets the optimizer eliminate most of the append-code in specializations where the appended sequence is also an Array.
For example, when "adding" arrays, e.g. arr += other_arr
2020-01-15 15:27:25 +01:00
Cory Benfield
c6dfea6fc4 [stdlib] Re-add withContiguousStorageIfAvailable to SubString.UTF8View
This is a second pass at the original patch, which broke an OS test.

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-14 14:01:06 +00:00
Arnold Schwaighofer
1386af04a2 Revert "stdlib: Add custom .first to Array"
This reverts commit 3e932c075d.

The compiler does not support @_alwaysEmitIntoClient properties
specially wrt property descriptors. The revert commit would introduce an
ABI incompatability when a keypath to Array.first is formed:

    let greetings = ["hello", "hola"]
    let count = greetings[keyPath: \[String].first?.count]

Runmning on an older runtime would lead to linker errors against $sSa5firstxSgvpMV
the property descriptor for Array.first.

rdar://58484319
2020-01-13 13:07:00 -08:00
Michael Ilseman
70e6db81f1 Revert "[stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View" 2020-01-10 13:28:03 -08:00
eeckstein
3f71bb864c Merge pull request #29121 from eeckstein/fix-array-remove
stdlib: annotate Array's remove functions with semantic attributes.
2020-01-10 20:23:21 +01:00
Michael Ilseman
6209c97bf7 Merge pull request #29094 from Lukasa/cb-substring-fast-access
[stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View
2020-01-10 11:16:46 -08:00
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