Commit Graph

4464 Commits

Author SHA1 Message Date
Andrew Trick
e8c65b37ef Remove the optimize.sil.preserve_exclusivity attribute. 2018-05-09 23:10:35 -07:00
swift-ci
c82c4cd4e7 Merge remote-tracking branch 'origin/master' into master-next 2018-05-09 18:09:07 -07:00
swift-ci
0eb5131669 Merge pull request #15519 from jckarter/key-path-offset 2018-05-09 18:00:21 -07:00
Karoy Lorentey
54b3b8be5e [stdlib] Random: don't randomize FixedWidthIntegers by overwriting their raw memory
Custom FixedWidthInteger types may not support this.

Introduce a new (non-public) FixedWidthInteger requirement for generating random values; implement it using &<</+ in the generic case, and specialize it using RandomNumberGenerator._fill(bytes) for the builtin types.
2018-05-09 18:02:34 +01:00
Karoy Lorentey
12a2b32644 [stdlib] Add & implement Random._fill(bytes:) requirement 2018-05-09 17:51:36 +01:00
swift-ci
02710ad6fe Merge remote-tracking branch 'origin/master' into master-next 2018-05-09 08:09:20 -07:00
Dave Abrahams
ec9b402605 Slightly clarify removeAll(where:) (#16459)
* Slightly clarify removeAll(where:)

Improve parameter naming, use "guard" to reduce nesting
2018-05-09 07:57:28 -07:00
Ben Rimmington
b65d0c1d11 Consolidate _stdlib_random functions (#2)
* Use the `__has_include` and `GRND_RANDOM` macros

* Use `getentropy` instead of `getrandom`

* Use `std::min` from the <algorithm> header

* Move `#if` out of the `_stdlib_random` function

* Use `getrandom` with "/dev/urandom" fallback

* Use `#pragma comment` to import "Bcrypt.lib"

* <https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp>
* <https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions>

* Use "/dev/urandom" instead of `SecRandomCopyBytes`

* Use `swift::StaticMutex` for shared "/dev/urandom"

* Add `getrandom_available`; use `O_CLOEXEC` flag

Add platform impl docs

Update copyrights

Fix docs

Add _stdlib_random test

Update _stdlib_random test

Add missing &

Notice about _stdlib_random

Fix docs

Guard on upperBound = 0

Test full range of 8 bit integers

Remove some gyb

Clean up integerRangeTest

Remove FixedWidthInteger constraint

Use arc4random universally

Fix randomElement

Constrain shuffle to RandomAccessCollection

warning instead of error

Move Apple's implementation

Fix failing test on 32 bit systems
2018-05-09 00:21:44 -05:00
swift-ci
17045afe85 Merge remote-tracking branch 'origin/master' into master-next 2018-05-08 16:09:15 -07:00
Erik Eckstein
b519d1d873 stdlib: Speed up UTF8View -> Array conversion by using _copyContents 2018-05-08 13:52:05 -07:00
swift-ci
545a6e97bc Merge remote-tracking branch 'origin/master' into master-next 2018-05-08 10:49:30 -07:00
Karoy Lorentey
d1fb8e2683 Merge pull request #16310 from koher/fast-keys-contains
Improve Dictionary.Keys.contains(_:)
2018-05-08 18:31:41 +01:00
swift-ci
477630546a Merge remote-tracking branch 'origin/master' into master-next 2018-05-07 17:09:15 -07:00
Erik Eckstein
f430738b6e stdlib: fix performance regression for long string appends.
Re-wrote the inner memcpy loops so that they can be vectorized.
Also added a few inline(__always).

Since we removed some @inlineable attributes this string-append code is not code generated in the client anymore.
The code generation in the stdlib binary is different because all the precondition checks are not folded away.
Using explicit loop control statements instead of for-in-range removes the precondition-overhead for those time critical memcpy loops.
2018-05-07 14:48:04 -07:00
swift-ci
886c954d97 Merge remote-tracking branch 'origin/master' into master-next 2018-05-07 10:09:22 -07:00
Ben Cohen
f421ec6082 [stdlib] Undeprecate Countable*Range (#16360)
* Undeprecate Countable*Range

* Remove check for deprecation warnings
2018-05-07 09:52:52 -07:00
Nate Cook
f146d17214 Revise documentation, add benchmarks (#3)
* [stdlib] Revise documentation for new random APIs

* [stdlib] Fix constraints on random integer generation

* [test] Isolate failing Random test

* [benchmark] Add benchmarks for new random APIs

Fix Float80 test

Value type generators

random -> randomElement

Fix some docs

One more doc fix

Doc fixes & bool fix

Use computed over explicit
2018-05-04 21:03:50 -05:00
Ben Rimmington
a5df0ef83d Add _stdlib_random for more platforms (#1)
* Remove refs to Countable ranges

* Add `_stdlib_random` for more platforms

* Use `getrandom` (if available) for Android, Cygwin

* Reorder the `_stdlib_random` functions

* Also include <features.h> on Linux

* Add `#error TODO` in `_stdlib_random` for Windows

* Colon after Fatal Error

Performance improvement for Random

gybify ranges

Fix typo in 'basic random numbers'
Add _stdlib_random as a testable method

Switch to generic constraints

Hopefully link against bcrypt

Fix some implementation details

1. Uniform distribution is now uniform
2. Apply Jens' method for uniform floats

Fix a lineable attribute
2018-05-04 21:03:38 -05:00
Azoy
d23d219e95 Add shims for stdlib random
Initial random api

Use C syscall for I/O

1. Fixed an issue where integers would would result in an infinite loop if they were unsigned, or signed integers always returning negative numbers.
2. Fixed an issue with Bool initialization

Add shuffle functions

Add documentation to Random API

Fix a few typos within the documentation

Fixes more typos

Also states that the range for floating points is from 0 to 1 inclusive

Update API to reflect mailing list discussions

Remove unnecessary import

Make sure not to return upperBound on Range

Use SecRandomCopyBytes on older macOS

Update API to match mailing list discussion, add tests

Added pick(_:) to collection
Added random(in:using:) to Randomizable
Added tests

Fix typo in Randomizable documentation

Rename pick to sampling

Move sampling below random

Update docs

Use new Libc naming

Fix Random.swift with new Libc naming

Remove sampling

gybify signed integer creation

Make FloatingPoint.random exclusive

Refactor {Closed}Range.random

Fix FloatingPoint initialization

Precondition getting a random number from range

Fix some doc typos

Make .random a function

Update API to reflect discussion

Make .random a function
Remove .random() in favor of .random(in:) for all numeric types

Fix compile errors

Clean up _stdlib_random

Cleanup around API

Remove `.random()` requirement from `Collection`

Use generators

Optimize shuffle()

Thread safety for /dev/urandom

Remove {Closed}Range<BinaryFloatingPoint>.random()

Add Collection random requirement

Refactor _stdlib_random

Remove whitespace changes

Clean linux shim

Add shuffle and more tests

Provide finishing tests and suggestions

Remove refs to Countable ranges

Revert to checking if T is > UInt64
2018-05-04 21:02:57 -05:00
swift-ci
8ee09ae579 Merge remote-tracking branch 'origin/master' into master-next 2018-05-04 11:09:35 -07:00
eeckstein
2335396b5e Merge pull request #16358 from eeckstein/stdlib-string-no-inlinable
stdlib: remove some @inlineables from String API functions.
2018-05-04 10:56:48 -07:00
swift-ci
55f1c866c0 Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 19:09:31 -07:00
Michael Ilseman
cd32463fa2 Merge pull request #16320 from milseman/identity_crisis
[string] Only bridge tagged NSStrings to small string form.
2018-05-03 19:06:33 -07:00
swift-ci
98343b57ac Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 17:49:33 -07:00
Michael Ilseman
c25188bafd Merge pull request #16140 from milseman/never_inlin
[stdlib] Drop @inlinable if @inline(never).
2018-05-03 17:43:24 -07:00
Erik Eckstein
9a961208ec stdlib: remove some @inlineables from String API functions.
Beside the general goal to remove inlinable functions, this reduces code size and also improves performance for several benchmarks.
The performance problem was that by inlining top-level String API functions into client code (like String.count) it ended up calling non-inlinable internal String functions eventually.
This is much slower than to make a single call at the top-level API boundary into the library. Inside the library all the internal String functions can be specialized and inlined.

rdar://problem/39921548
2018-05-03 14:37:11 -07:00
Nathan Lanza
9815368788 Configure the swiftImageInspectionShared to generate arch & sdk specific libraries
Previously, swiftImageInspectionShared generated one specific library at
`lib/libswiftImageInspectionShared.a` for only the main arch and sdk.
Generic cross compilation and various changes to the build system to get
cross compilation to work will require swiftImageInspectionShared to
generate libraries at the proper subdirectory. Change the outputs to
agree with paths such as `lib/swift/linux/x86_64`
2018-05-03 12:33:45 -07:00
Michael Ilseman
5f1ba83e8d [String] Only bridge tagged NSStrings to small string form.
Non-tagged NSStrings carry identity separate from their
value. Continue to bridge them lazily, even if they could fit in small
form, to respect this and avoid potential information loss.

Temporarily disable invariant that all natives strings that could be
small, are.
2018-05-03 10:45:19 -07:00
Lance Parker
851274df30 [stdlib] Restore @inlinable on _arrayOutOfPlaceReplace (#22)
Temporarily for https://bugs.swift.org/browse/SR-7588
2018-05-02 14:00:58 -07:00
Yuta Koshizawa
2da85ecc16 [stdlib] Make dictionary.keys.contains(key) O(1) even when wrapping a NSDictionary 2018-05-03 01:22:31 +09:00
swift-ci
2b9a333674 Merge remote-tracking branch 'origin/master' into master-next 2018-05-02 05:29:47 -07:00
Karoy Lorentey
b1a64e8303 Merge pull request #16177 from lorentey/hashable-docs
[SE-0206] Update Hashable docs for hash(into:)
2018-05-02 13:19:29 +01:00
swift-ci
b0428cef66 Merge remote-tracking branch 'origin/master' into master-next 2018-05-01 10:49:10 -07:00
eeckstein
c2cc3ee6cf stdlib: replace an obsolete initialize function in UnsafeBufferPointer.swapAt with the new one. (#16270)
This brings back performance on stdlib sort because the obsoleted function in UnsafePointer is not inlinable.
2018-05-01 10:48:32 -07:00
swift-ci
d9213aa780 Merge remote-tracking branch 'origin/master' into master-next 2018-05-01 10:29:52 -07:00
Michael Ilseman
17b0ed4708 [String] Define _copyContents for UTF8View
Define _copyContents on String.UTF8View, which allows it to
efficiently memcpy bytes when the String is already in UTF-8 (or
ASCII).
2018-04-30 17:08:12 -07:00
swift-ci
b80f58cbcf Merge remote-tracking branch 'origin/master' into master-next 2018-04-30 13:29:16 -07:00
Michael Gottesman
0d1f98a4ef Merge pull request #16259 from gottesmm/pr-aab473d24268b0934ac216bf2683f0a2c8e3be0f
[+0-all-args] Make _bridgeAnythingNonVerbatimToObjectiveC() take its …
2018-04-30 13:14:46 -07:00
swift-ci
9d81e603c3 Merge remote-tracking branch 'origin/master' into master-next 2018-04-30 12:29:27 -07:00
Michael Gottesman
161ffdaa77 Merge pull request #16257 from gottesmm/pr-a2ac5bea56b734ec3f97b29f6069bda20ffa3a15
[+0-all-args] Change _swift_stdlib_bridgeErrorToNSError to take its p…
2018-04-30 12:21:30 -07:00
Michael Gottesman
c31033c525 [+0-all-args] Make _bridgeAnythingNonVerbatimToObjectiveC() take its parameter at +1.
This hoists out the retain into Swift code from the casting runtime and along a
few paths in the runtime allows us to eliminate a dynamic retain release.

rdar://38196046
rdar://38771331
2018-04-30 11:05:00 -07:00
swift-ci
11c5a6b220 Merge remote-tracking branch 'origin/master' into master-next 2018-04-30 10:29:45 -07:00
Michael Gottesman
87681375e2 [+0-all-args] Change _swift_stdlib_bridgeErrorToNSError to take its parameter at +1.
This is truly a consuming operation. This can be seen since we always would need
to retain the argument here. This makes guaranteed -> owned less transformation
effective. Instead represent it taking a +1 argument so that the retain happens
outside the builtin instead of inside the builtin.

This also allows me to remove an extra copy from dynamicCastValueToNSError

rdar://38771331
2018-04-30 10:16:41 -07:00
Karoy Lorentey
5b80cf1d59 [stdlib]: Set,Dictionary: Fix subtle cross-collection hash collision issue
When Set/Dictionary is nested in another Set, the boundaries of the nested collections weren’t correctly delineated in commutative hashing.

For example, these Sets all hashed the same:

[[1, 2], [3, 4]]
[[1, 3], [2, 4]]
[[1, 4], [2, 3]]

Hash collisions could thus be systematically generated.

To fix this, remove collection-level support for one-shot hashing and revert to the previous method of generating hash values. (Set is still able to support one-shot hashing for its members, though.)
2018-04-30 15:40:16 +01:00
Karoy Lorentey
a274a0c92a [stdlib] Implement top-level hashing for stdlib types 2018-04-30 15:40:16 +01:00
Karoy Lorentey
3a162d225a [stdlib] Hashable, Hasher: Add non-public top-level hashing interface
The new _rawHashValue(seed:) requirement allows stdlib types to specialize their hashing when they’re hashed on their own (i.e., not as a component of some composite type).

This makes it possible to get rid of discriminator/terminator values and to eliminate most of Hasher’s resiliency overhead, leading to a measurable speedup, especially for tiny keys.
2018-04-30 15:16:47 +01:00
swift-ci
6e4b355297 Merge remote-tracking branch 'origin/master' into master-next 2018-04-30 04:49:57 -07:00
swift-ci
5f9bf115b3 Merge pull request #16154 from lorentey/hash-into-everywhere 2018-04-30 04:40:19 -07:00
Karoy Lorentey
bae6f529e1 [stdlib] Make Character.hash(into:) explicitly not inlinable
The @inlinable attribute was left off by accident, but this turned out to be a measurable performance boost for Character hashing.

Also add @effects(releasenone), for good measure.
2018-04-30 10:17:09 +01:00
Karoy Lorentey
0342ce3b96 [SE-0206][stdlib] Remove obsolete hashValue implementations
These are now synthesized by the compiler.
(Inlinability will be different, but that seems fine.)
2018-04-30 10:17:09 +01:00