Commit Graph

75 Commits

Author SHA1 Message Date
Karoy Lorentey
2213b4ee2d [stdlib] Set, Dictionary: Review _SwiftDeferredNS* 2018-08-16 20:05:32 +01:00
Karoy Lorentey
548f59a0e3 [stdlib] Set, Dictionary: Make internal representations conform to Sequence 2018-08-16 20:05:32 +01:00
Karoy Lorentey
5e969ce24c [stdlib] Set, Dictionary: Simplify _find(_:,startBucket:)
The startBucket argument is _bucket(key) in the vast majority of cases. Add an overload with this default value.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
b1c81e5ffe [test] Update api-digester source compatibility tests
DictionaryIterator & SetIterator have been renamed Dictionary.Iterator and Set.Iterator, with compatibility typealiases.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
3bb720c6b0 [stdlib] Set, Dictionary: Prefer collection-agnostic names for stored property names
This makes it easier to define lldb data formatters for these types.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
063d92627b [stdlib] Dictionary: Add implementation for first
This is primarily for documentation purposes, although the default implementation (based on an iterator) may not return the correct value for bridged dictionaries with exotic implementations.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
6ee9fce52c [stdlib] Set, Dictionary: Remove remaining internal typealiases 2018-08-16 20:05:32 +01:00
Karoy Lorentey
2201d0e3c8 [stdlib] Set, Dictionary: Move compatibility typealiases to end of file 2018-08-16 20:05:32 +01:00
Karoy Lorentey
791d29f422 [stdlib] Set, Dictionary: Audit one more round of inlinability attributes 2018-08-16 20:05:32 +01:00
Karoy Lorentey
ad3c970054 [stdlib] Set, Dictionary: Review builders
- Inlinability audit
- Create a _NativeSet/_NativeDictionary directly, without extracting it from a Set/Dictionary
- Swap the final result with an empty collection.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
3f9cd3fb4b [stdlib] Set, Dictionary: Review iterators
- DictionaryIterator => Dictionary.Iterator
- SetIterator => Set.Iterator

- Introduce an explicit struct for native iterators
- _CocoaDictionaryIterator => _CocoaDictionary.Iterator
- _CocoaSetIterator => _CocoaSet.Iterator
- Move representation enums under {Set,Dictionary}.Iterator as _Variant.
- Inlinability audit
2018-08-16 20:05:32 +01:00
Karoy Lorentey
e588f1a8ba [stdlib] Set, Dictionary: Audit inlinability of storage classes
- Remove @inlinable from @objc methods.
- _UnmanagedAnyObjectArray: make internal.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
fcadebc02b [stdlib] Set, Dictionary: Review indices
- Nest native/cocoa index types under their corresponding struct
- Move *IndexRepresentation enums under the corresponding Index type, renamed to _Variant.
- Rename Index._value to Index._variant.
- Remove internal typealiases.
- Remove underscore prefix from enum case names.
- _nativeIndex => _asNative, _cocoaIndex => _asCocoa
- Audit inlinability.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
ac9f29451f [stdlib] Set, Dictionary: Review enumerators
_NativeSetNSEnumerator => _SwiftSetNSEnumerator
_NativeDictionaryNSEnumerator => _SwiftDictionaryNSEnumerator
2018-08-16 20:05:32 +01:00
Karoy Lorentey
e2fb468b97 [stdlib] Set, Dictionary: Review native & cocoa representations
- Remove buffer suffix from type, property & variable names
  struct _NativeSetBuffer => _NativeSet
  struct _NativeDictionaryBuffer => _NativeDictionary
  struct _CocoaSetBuffer => _CocoaSet
  struct _CocoaDictionaryBuffer => _CocoaDictionary

- Remove internal typealiases related to these types
- Move nativeDelete, nativeMapValues from variant enum to corresponding struct
2018-08-16 20:05:32 +01:00
Karoy Lorentey
cc8e378319 [stdlib] Set, Dictionary: Remove obsolete operator definitions. 2018-08-16 20:05:32 +01:00
Karoy Lorentey
2053f74828 [stdlib] Set, Dictionary: Review variant enums
- Rename variant enum types and move them into the corresponding struct:
  _VariantSetBuffer => Set._Variant
  _VariantDictionaryBuffer => Dictionary._Variant

  I found the buffer suffix did not positively contribute to understanding these types. And the extra indirection of the typealiases wasn't exactly helpful, either.

- Remove internal typealiases that resolved to these.
2018-08-16 20:05:32 +01:00
Karoy Lorentey
c74e4daa2b [stdlib][NFC] Shorten notes about SR-6437 2018-08-16 20:05:32 +01:00
Mox Soini
c66e136c18 Improve documentation for compactMapValues() of Dictionary (#18547) 2018-08-08 00:25:49 -05:00
Nate Cook
efb0415a61 [stdlib] More documentation revisions (#18263)
- Fix error in `last(where:)` example
- Improve MemoryLayout, UnsafePointer, and integer operator discussions
- Clean up ranges and random APIs
- Revisions to overflow operators and the SignedNumeric requirements
- Standardize on 'nonoptional' in remaining uses
2018-08-08 00:25:09 -05:00
Ben Cohen
df22c3647c [stdlib] Build the standard library as Swift 5 (#18121)
* Update std lib to Swift 5.0

* Disable Unicode.* warnings for now

* Slow path to resiliently handle the case where an unknown rounding rule is passed

* Remove resilience from Encoding/DecodingError (which should only happen on slow paths anyway)

* internal typealiases now need @usableFromInline

* Force inlining on Array._owner.get
2018-07-24 20:47:58 -07:00
Karoy Lorentey
543e050702 [stdlib] Set, Dictionary: Remove _Mutable*Buffer protocols
They had but a single type conforming them, so they did not pull their weight as internal interface-enforment protocols.
2018-07-17 15:59:51 +01:00
Karoy Lorentey
5a22b9016a [stdlib] Split _HashBuffer into four different protocols
This allows Set’s internal types not to define Key, Value, SequenceElement & SequenceElementWithoutLabels typealiases.

Splitting the protocol on the mutable/immutable axis allows us to remove some obsolete method definitions.
2018-07-17 15:59:51 +01:00
Karoy Lorentey
9756677d72 [stdlib] Set, Dictionary: Remove RawStorage typealiases
These were an artifact of gybbing.
2018-07-17 15:59:51 +01:00
Karoy Lorentey
a339f88a29 [stdlib] NFC: cosmetic changes 2018-07-17 15:59:51 +01:00
Karoy Lorentey
99f348800d [stdlib] Set, Dictionary: Make Cocoa->native conversion non-inlinable 2018-07-17 15:59:50 +01:00
Karoy Lorentey
47cae81c75 [stdlib] Set, Dictionary: Make Cocoa iteration state non-inlinable. 2018-07-17 15:59:50 +01:00
Karoy Lorentey
4ac2fc7517 [stdlib] _SwiftDeferredNS*: Clean up gyb artifacts
Remove typealiases and member functions made obsolete by de-gybbing.
2018-07-17 15:59:50 +01:00
Karoy Lorentey
619db38b5d [stdlib] Make non-verbatim bridged Set and Dictionary implementations internal
There is no reason to expose these in the Swift ABI.
2018-07-17 15:59:50 +01:00
Karoy Lorentey
c72bf4cdfa [stdlib] Make Set & Dictionary enumerators internal
There is no reason to expose these in the Swift ABI.
2018-07-17 15:59:50 +01:00
Ben Cohen
b77b544cdc Remove remaining @ininable from @_transparent (#17968) 2018-07-16 08:12:52 -07:00
Daiki Matsudate
a3552f393e [stdlib] Add compactMapValues(_:) to Dictionary (#15017)
add compact map values on hashed collections
2018-07-14 22:35:16 -07:00
Ben Cohen
a6952decab [stdlib] Remove inlineable annotation from transparent functions (#17800)
* Remove inlineable annotation from transparent functions
2018-07-07 08:47:02 -07: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
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
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
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
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
Ben Cohen
92b6d8cb8f Remove inlineability from mirrors (#17476) 2018-06-25 19:54:13 -07: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
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
Nate Cook
653a4d89d2 [stdlib] Revise documentation comments
- Clarify RawValue requirement for OptionSet
- Make Bool counterexample more clearly an error
- Add clarifying note about unsafe arithmetic methods
- Add/refine complexity docs for sequence/collection
- Remove docs from obsoleted symbols
- Standardize on unicode.org for links about Unicode
- More complexity annotations
- Expand dictionary defaulted subscript docs
- Fix error in Dictionary.init(minimumCapacity:) docs
- Improve accuracy of prime number listing
2018-06-14 19:19:19 -05:00
Erik Little
863f3a19ff Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
Karoy Lorentey
07c1b74cc4 [stdlib] Audit inlinability of Hashable implementations
As a general rule, it is safe to mark the implementation of hash(into:) and _rawHashValue(seed:) for @_fixed_layout structs as inlinable.

However, some structs (like String guts, Character, KeyPath-related types) have complicated enough hashing that it seems counterproductive to inline them. Mark these with @effects(releasenone) instead.
2018-05-31 18:24:59 -07:00
Nate Cook
7a4e0a32f6 [stdlib] Revise documentation
This includes various revisions to the APIs landing in Swift 4.2, including:
- Random and other randomness APIs
- Hashable changes
- MemoryLayout.offset(of:)
2018-05-18 11:31:54 -05: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
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
Yuta Koshizawa
2da85ecc16 [stdlib] Make dictionary.keys.contains(key) O(1) even when wrapping a NSDictionary 2018-05-03 01:22:31 +09:00