Commit Graph

4494 Commits

Author SHA1 Message Date
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
Ben Cohen
cdcbd1b32a Fix incorrect rename 2018-06-21 17:12:00 -07:00
Ben Cohen
2eec236f13 Move two more Iterators into nested types 2018-06-21 16:28:20 -07:00
swift-ci
ce3d5ff1a1 Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 07:29:58 -07:00
Tony Arnold
8b9dd25337 Don’t use an error for flow control in Sequence.first(where:) (#17387) 2018-06-21 07:22:11 -07:00
swift-ci
f636e469b1 Merge remote-tracking branch 'origin/master' into master-next 2018-06-20 17:08:52 -07:00
Stephen Canon
ff89fce7df Make FloatingPoint require that Self.Magnitude == Self (#17323)
* Make FloatingPoint require that Self.Magnitude == Self

We didn't have the where clause to express this constraint at the time that the FloatingPoint protocol was implemented, but we do now. This is not a semantic change to FloatingPoint, which has always bound IEEE-754 arithmetic types, for which this constraint would necessarily hold, but it does effect the type system.

For example, currently the following function does not type check:
~~~~
func foo<T>(x: T) -> T where T: FloatingPoint {
  var r = x.remainder(dividingBy: 1)
  return r.magnitude
}
~~~~
with this change, it compiles correctly.

Having done this, we no longer need to have a separate `abs` defined on FloatingPoint; we can use the existing function defined on `SignedNumeric` instead. Additionally mark the global `fabs` defined in the platform C module deprecated in favor of the Swift `abs`; we don't need to carry two names for this function going forward.
2018-06-20 19:56:22 -04:00
Bob Wilson
ea055fcbdc Merge remote-tracking branch 'origin/master' into master-next 2018-06-19 22:47:54 -07:00
Joe Groff
46cd1b786b stdlib: Make data structure protocols ready for future move-only types.
We would like to eventually extend Array, Dictionary, and Set to support move-only element types when the language does. To that end, we need to get the `consuming`-ness of protocol requirements on Sequence, Collection, and related protocols right for forward compatibility so that a future version of Swift that extends these types to support move-only data structures remains ABI- and API-compatible with older versions of the language. Mark requirements as `__consuming` where it would be necessary for a move-only implementation of one of these types.
2018-06-19 14:23:24 -07:00
swift-ci
293bd1d0cc Merge remote-tracking branch 'origin/master' into master-next 2018-06-19 12:09:50 -07:00
Michael Ilseman
26af64d78c Merge pull request #17292 from ikesyo/remove-string-_core
[String] Remove `_core` which is not used in swift-corelibs-foundation anymore
2018-06-19 12:03:45 -07:00
swift-ci
9b7a0d6542 Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 13:28:59 -07:00
Slava Pestov
88d305cade Merge pull request #17296 from lorentey/usableFromInline-typealiases
[stdlib] Add @usableFromInline to internal typealiases that need it
2018-06-18 13:21:31 -07:00
swift-ci
2a0e83dc0d Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 11:00:19 -07:00
Max Moiseev
c16d9ce746 Merge pull request #17262 from moiseev/characterview-warning
[stdlib] Eliminate some warnings while building the stdlib
2018-06-18 10:48:16 -07:00
Karoy Lorentey
23c630ac92 [stdlib] Add @usableFromInline to internal typealiases that need it
This fixes 3659 warnings in the standard library.
2018-06-18 16:34:19 +01:00
Sho Ikeda
6d95b8f3a2 [String] Remove _core which is not used in swift-corelibs-foundation anymore 2018-06-18 22:03:02 +09:00
Max Moiseev
baaa4a9ac3 Eliminate some warnings while building the stdlib
- Move deprecated declarations into a separate deprecated extension
(suppresses tghe warning)
- Mark an initializer from CharacterView as deprecated

Addresses: <rdar://problem/40625231>
2018-06-15 15:29:47 -07:00
Michael Ilseman
fd1c861415 [string] ASCII/UTF-8 fast paths for String.init(decoding:as:)
Add some fast paths to String.init(decoding:as:) for inputs of
contiguously stored UTF-8 code units. Dramatically speeds up creation
when the String happens to be ASCII and we can form more small
strings.
2018-06-15 14:41:26 -07:00
Bob Wilson
5df3d1f100 Merge remote-tracking branch 'origin/master' into master-next 2018-06-14 20:51:48 -07:00
swift-ci
6dc658ff21 Merge pull request #17109 from natecook1000/nc-fixes-86-1 2018-06-14 18:24:18 -07:00