Commit Graph

4464 Commits

Author SHA1 Message Date
swift-ci
559eaf8de2 Merge remote-tracking branch 'origin/master' into master-next 2018-07-06 10:29:01 -07:00
Alejandro
79cb33fa78 [SR-8178] Fix BinaryFloatingPoint.random(in:) open range returning upperBound (#17794) 2018-07-06 13:13:19 -04:00
Tony Allevato
d0e93acb00 Various fixes to Unicode.Scalar.Properties.
- numericValue returns nil instead of .nan for non-numerics
- Remove small-string optimizations from _scalarName that failed on 32-bit archs
- Put case mappings back into U.S.Properties
- Added more sanity tests
2018-07-05 20:42:56 -07:00
swift-ci
4861515b25 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 12:29:17 -07:00
swift-ci
003ec25cfa Merge pull request #17742 from lorentey/nsdictionary-speedup 2018-07-05 12:19:30 -07:00
swift-ci
7d38bcf09c Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 12:09:21 -07:00
Stephen Canon
86ba697151 Add constraints to FixedWidthInteger.Stride and .Magnitude (#17716)
* Add constraints to FixedWidthInteger.Stride and .Magnitude

Add the constraint that these associatedtypes themselves conform to FixedWidthInteger and to SignedInteger and UnsignedInteger, respectively. These are effectively part of the semantic requirement of the protocol already, because the requirements on .min and .max effectively force FixedWidthInteger to be twos-complement, which requires Magnitude not be Self for signed types. Also, in practice it's generally necessary to have these two constraints in order to effectively use the FixedWidthInteger protocol anyway; witness that by adding them to the protocol, we eliminate them as constraints from a number of extensions.

This also resolves https://bugs.swift.org/browse/SR-8156
2018-07-05 15:04:33 -04:00
Karoy Lorentey
cf7e4385de [stdlib] Dictionary: Optimize loops in getObjects:andKeys:count: implementations
This breaks out of the loop immediately when the last slot has been filled in the output buffer, skipping a final sequence of iterations over empty buckets.
2018-07-05 18:22:43 +01:00
Karoy Lorentey
93ab7677e6 [stdlib] _NSDictionary: Replace getObjects:andKeys: with getObjects:andKeys:count: 2018-07-05 15:53:43 +01:00
Karoy Lorentey
a951cf2cf2 [stdlib] Dictionary: Fix getObjects:andKeys:count: implementations 2018-07-05 15:52:45 +01:00
swift-ci
dec37b0fc7 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 05:29:46 -07:00
Xiaodi Wu
47f13ec9ff [stdlib] Align behavior of generic NaN conversion to that of concrete types (#17746) 2018-07-05 08:28:51 -04:00
Tony Allevato
8eef50f6a9 Merge branch 'master' into unicode-properties 2018-07-04 08:42:35 -07:00
Karoy Lorentey
6aec05aa44 [stdlib] Dictionary: Override getObjects:andKeys:count:
Dictionary’s native storage classes and _SwiftDeferredNSDictionary override -[NSDictionary getObjects:andKeys:] instead of its safer replacement, -[NSDictionary getObjects:andKeys:count:].

Overriding the correct method will considerably speed up some Cocoa operations on bridged dictionaries.

rdar://problem/39285882
2018-07-04 16:35:46 +01:00
swift-ci
e689a0dc91 Merge remote-tracking branch 'origin/master' into master-next 2018-07-02 11:29:09 -07:00
Lance Parker
78e9e9062b Merge pull request #17636 from lancep/specialize_remaining
[stdlib]Specialize `remaining` on _CollectionSource
2018-07-02 11:16:45 -07:00
swift-ci
3f31f6cc3c Merge remote-tracking branch 'origin/master' into master-next 2018-07-02 04:28:59 -07:00
Karoy Lorentey
9286b3627d Merge pull request #17604 from Azoy/moar-random-improvements
[stdlib] Remove _random() customization point
2018-07-02 12:28:07 +01:00
swift-ci
5a31f3bdd8 Merge remote-tracking branch 'origin/master' into master-next 2018-07-01 04:49:04 -07:00
David Zarzycki
75b0d3c70b [stdlib] NFC: Fix var to let warning 2018-06-30 18:53:39 -04:00
swift-ci
65198342c7 Merge remote-tracking branch 'origin/master' into master-next 2018-06-29 17:09:11 -07:00
Joe Groff
04b5174b33 stdlib: Remove Collection.randomElement customization point.
As proposed and accepted in amendment https://github.com/apple/swift-evolution/pull/863. rdar://problem/41067949
2018-06-29 13:49:45 -07:00
Lance Parker
6c5ad1cfba Specialize remaining on _CollectionSource 2018-06-29 11:52:12 -07:00
swift-ci
f551a7075d Merge remote-tracking branch 'origin/master' into master-next 2018-06-29 09:49:20 -07:00
Karoy Lorentey
a4e9109618 Merge pull request #17396 from lorentey/anyhashable-is-not-hashable
[stdlib] Fix AnyHashable's Equatable/Hashable conformance
2018-06-29 17:38:08 +01:00
Stephen Canon
6ebdefb790 Make upperBound != 0 a precondition for RNG.next(upperBound:) (#17627)
The function's definition is "Returns a random value that is less than the given upper bound," which cannot possibly be satisfied with upperBound == 0; previously the function returned zero, which was a bug.
2018-06-29 12:35:39 -04:00
swift-ci
017d10d2d1 Merge remote-tracking branch 'origin/master' into master-next 2018-06-29 06:29:24 -07:00
Ben Cohen
a4230ab2ad [stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
2018-06-29 06:26:52 -07:00
Azoy
04a16df3c2 Remove _random cp 2018-06-28 15:31:39 -05:00
Karoy Lorentey
2f4ad7982d [stdlib] Eliminate _AnyHashableBox._asSet() & ._asDictionary()
_canonicalBox can perform essentially the same job, so there is no reason to have these requirements.
2018-06-28 18:48:56 +01:00
swift-ci
1dd0c2158b Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 20:09:50 -07:00
Ben Cohen
92b6d8cb8f Remove inlineability from mirrors (#17476) 2018-06-25 19:54:13 -07:00
swift-ci
383ca7ce7d Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 18:09:46 -07:00
Slava Pestov
084698da88 Merge pull request #17489 from slavapestov/stdlib-usable-from-inline
stdlib: Update for stricter enforcement of @usableFromInline
2018-06-25 17:59:51 -07:00
swift-ci
ab9a0b64e1 Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 17:49:47 -07:00
Alex Martini
612b49db41 Fix spelling of init?(exactly:) in prose. (#17483) 2018-06-25 19:41:12 -05:00
Slava Pestov
5d1f48e3ae stdlib: Update for stricter enforcement of @usableFromInline 2018-06-25 16:26:56 -07:00
swift-ci
e679106ce9 Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 13:29:04 -07:00
Ben Cohen
a51cc89b11 Replace _CharacterView with a typealias (#17472) 2018-06-25 13:22:09 -07:00
Karoy Lorentey
bf872ec157 [stdlib][SE-0206] Use distinct hash encodings for standard integer types
Fix Hashable conformance of standard integer types so that the number of bits they feed into hasher is exactly Self.bitWidth.

This was intended to be part of SE-0206. However, it would have introduced additional issues with AnyHashable. The custom AnyHashable representations introduced in the previous commit unify hashing for numeric types, eliminating the problem.
2018-06-25 20:14:17 +01:00
Karoy Lorentey
ff91f36a9d [stdlib] Fix AnyHashable's Equatable/Hashable conformance
AnyHashable has numerous edge cases where two AnyHashable values compare equal but produce different hashes. This breaks Set and Dictionary invariants and can cause unexpected behavior and/or traps. This change overhauls AnyHashable's implementation to fix these edge cases, hopefully without introducing new issues.

- Fix transitivity of ==. Previously, comparisons involving AnyHashable values with Objective-C provenance were handled specially, breaking Equatable:

    let a = (42 as Int as AnyHashable)
    let b = (42 as NSNumber as AnyHashable)
    let c = (42 as Double as AnyHashable)
    a == b // true
    b == c // true
    a == c // was false(!), now true

    let d = ("foo" as AnyHashable)
    let e = ("foo" as NSString as AnyHashable)
    let f = ("foo" as NSString as NSAttributedStringKey as AnyHashable)
    d == e // true
    e == f // true
    d == f // was false(!), now true

- Fix Hashable conformance for numeric types boxed into AnyHashable:

    b == c // true
    b.hashValue == c.hashValue // was false(!), now true

  Fixing this required adding a custom AnyHashable box for all standard integer and floating point types. The custom box was needed to ensure that two AnyHashables containing the same number compare equal and hash the same way, no matter what their original type was. (This behavior is required to ensure consistency with NSNumber, which has not been preserving types since SE-0170.

- Add custom AnyHashable representations for Arrays, Sets and Dictionaries, so that when they contain numeric types, they hash correctly under the new rules above.

- Remove AnyHashable._usedCustomRepresentation. The provenance of a value should not affect its behavior.

- Allow AnyHashable values to be downcasted into compatible types more often.

- Forward _rawHashValue(seed:) to AnyHashable box. This fixes AnyHashable hashing for types that customize single-shot hashing.

https://bugs.swift.org/browse/SR-7496
rdar://problem/39648819
2018-06-25 20:14:01 +01:00
swift-ci
8b01c5b635 Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 12:09:07 -07:00
Karoy Lorentey
6fc4cef671 Merge pull request #17475 from lorentey/read-only-cleanup
[gardening] Clean up gyb-related Emacs local variables
2018-06-25 19:59:43 +01:00
swift-ci
85af158d21 Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 11:50:33 -07:00
dmcyk
3620ba397e [stdlib] Key path safe type hashing.
Uses ObjectIdentifier to extract metatype pointer,
instead of unsafe pointer casting.
2018-06-25 18:48:18 +02:00
Karoy Lorentey
5d4ad4a506 [gardening][stdlib] Don't let Emacs modify gyb-generated sources 2018-06-25 17:16:39 +01:00
dmcyk
731b9b003c [stdlib] Cover type difference in key path hash.
Include type metadata pointer in hashing.
2018-06-25 00:28:22 +02:00
dmcyk
ef91e2ec40 [stdlib] Fix key path components hashing.
Removes shadowed `hasher` argument in component hashing.
2018-06-25 00:26:33 +02:00
swift-ci
4113204b2d Merge remote-tracking branch 'origin/master' into master-next 2018-06-22 12:09:03 -07:00
swift-ci
6ed6b2fd9b Merge pull request #17408 from airspeedswift/one-is-the-loneliest-iterator 2018-06-22 11:54:26 -07:00