Commit Graph

5543 Commits

Author SHA1 Message Date
Xiaodi Wu
03903ae1ea [stdlib] Fix generic floating-point conversion when two representable values are equally close 2020-03-03 18:22:47 -05:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
David Smith
eb74e71903 Merge pull request #30106 from Catfish-Man/going-public
Make String(unsafeUninitializedCapacity:initializingUTF8With:) public
2020-03-02 18:08:37 -08:00
David Smith
b9ddaa6e90 Make String(unsafeUninitializedCapacity:,initializingUTF8With:) public 2020-03-02 14:25:14 -08:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00
Valeriy Van
78fb0f7774 Removes redundant buffer zeroing 2020-02-28 23:32:05 +01:00
Valeriy Van
47acd72a6b Removes redundand buffer zeroing 2020-02-28 23:23:49 +01:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Michael Gottesman
59823811b5 [stdlib] Mark Unmanaged._withUnsafeGuaranteedRef as _transparent and add a test/comments as requested in the original PR where this landed.
rdar://59735604
2020-02-25 15:46:19 -08:00
Michael Gottesman
9e8d65fbf8 Merge pull request #30033 from gottesmm/pr-89ff0d5130b608cdfae1e68dfc8c4b10de0f78cd
[stdlib] Change _withUnsafeGuaranteedRef to use Builtin.convertUnownedUnsafeToGuaranteed.
2020-02-25 14:25:48 -08:00
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