Commit Graph

5263 Commits

Author SHA1 Message Date
Ben Cohen
df995de0d6 [stdlib] Make KeyValuePairs fully inlinable (#19502)
* Move KVP into its own Swift file. Make it fully inlineable.

* Make _makeCollectionDescription an extension. Add KeyValue equivalent.
2018-09-24 17:46:32 -07:00
Michael Ilseman
e3ee12c746 Merge pull request #19498 from linux-on-ibm-z/s390x-smallstring-fix
[string] Fix small string implementation for big endian platforms
2018-09-24 15:50:25 -07:00
Karoy Lorentey
cc3db35f76 Merge pull request #19497 from lorentey/dictionary-values-accessor
[stdlib] Dictionary.values: Replace setter with _modify
2018-09-24 21:46:33 +01:00
Karoy Lorentey
6cef0beff9 Merge pull request #19495 from lorentey/simplify-rawHashValue
[stdlib] Finalize one-shot hashing interface
2018-09-24 21:44:36 +01:00
Mike Ash
8fa3a41a84 Merge remote-tracking branch 'origin/master' into rename-conflicting-classes-and-methods 2018-09-24 12:31:49 -04:00
Karoy Lorentey
547cfa44ca [stdlib] Mark Set.isSubset<S>(of:) and similar queries as having a borrowed argument
This matches SetAlgebra, and seems to make the most sense, intuitively.
2018-09-24 16:51:34 +01:00
Stephen Canon
c88d4e407f Remove unsafe arithmetic operations deprecated in 4.2 (#19426) 2018-09-24 11:00:28 -04:00
Karoy Lorentey
a293ce15a6 [stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key
Replacing the old key with the new is unnecessary and somewhat surprising. It is also harmful to some usecases.

rdar://problem/32144087
2018-09-24 15:44:43 +01:00
Karoy Lorentey
8372fb3b0c [stdlib] Variant(_variant:) doesn’t exist on this timeline yet 2018-09-24 15:22:55 +01:00
Mike Ash
098884da95 Merge branch 'master' into rename-conflicting-classes-and-methods 2018-09-24 10:20:01 -04:00
Mike Ash
1fb165a0ea Merge branch 'master' into rename-conflicting-classes-and-methods 2018-09-24 10:17:22 -04:00
Karoy Lorentey
fd5bc0ffd4 [stdlib] Dictionary.values: Replace setter with _modify
This should enable in-place modification of the Values view, which should greatly improve the performance of code like this:

dictionary.values[index] = newValue
2018-09-24 14:40:42 +01:00
Karoy Lorentey
f59fd89e3c [stdlib] SetAlgebra: __consuming/__owned audit
Subtraction and intersection don’t need to consume their input parameter — the result value will only include elements from self.
2018-09-24 14:31:35 +01:00
Karoy Lorentey
c3bc84e680 [stdlib] Set, Dictionary: __consuming/__owned audit
Add __consuming and __owned to Set and Dictionary members where applicable.

Ignore compiler intrinsics for casting for now — their ARC behavior is covered by unit tests that need to be updated.
2018-09-24 13:46:40 +01:00
Karoy Lorentey
6d81663716 [stdlib] Make Hashable._rawHashValue(seed:) safer and more convenient
- Don’t expose the raw execution seed to _rawHashValue.
- Change the type of _rawHashValue’s seed from (UInt64,UInt64) to a single Int. Working with a pair of UInt64s is unwieldy, and overkill in practice. Int as a seed also integrates nicely with Int as a hash value.
- Remove _HasherCore._generateSeed(). Instead, simply call finalize() on a copy of the hasher to get a seed suitable for _rawHashValue.
- Update Set and Dictionary to store a single Int as the seed value.

Note that this doesn’t affect the core hasher, which still mixes in the actual 128-bit execution seed during its initialization. To reduce the potential of confusion, use the name “rawSeed” to refer to an actual 128-bit seed value.
2018-09-24 13:30:05 +01:00
Michael Munday
2866b4a30d [string] Fix small string implementation for big endian platforms
Exclusively store small strings in little-endian byte order. This
will insert byte swaps when accessing small strings on big endian
platforms, however these are usually extremely cheap.

This approach means that the layout of the code points and count
in memory will be the same on both big and little endian machines
simplifying future development. Prior to this change this code
was broken on big endian machines because the memory layout was
different (the count ending up in the middle of the string).
2018-09-24 13:10:09 +01:00
Karoy Lorentey
188074d391 [stdlib] Set: Inlinability audit for AnyHashable extensions 2018-09-23 01:38:37 +01:00
Karoy Lorentey
e9186000d0 [stdlib][NFC] Break Set/Dictionary implementation into smaller files
This has long been overdue; splitting the Dictionary.swift/Set.swift monoliths makes for a far less confusing editing experience.
2018-09-23 01:38:37 +01:00
Karoy Lorentey
9ae572f83f [stdlib] Dictionary: Remove workaround for rdar://problem/44612356 2018-09-22 13:36:05 +01:00
Karoy Lorentey
ff882f4a06 [stdlib] Set, Dictionary: Sanitize @objc-ness for NSEnumerator members 2018-09-22 13:36:05 +01:00
Karoy Lorentey
430a9f3064 [stdlib] _BridgingHashBuffer: Fix memory management
- Have the hash buffer include a reference to the original hash storage instance, along with a copy of its _HashTable, so that its lifetime can be independent from the deferred bridging object.
- Convert _BridgingHashBuffer to a ManagedBuffer so that we can easily put reference-counted properties in its header.
2018-09-22 13:36:05 +01:00
Karoy Lorentey
b2d4e801a4 [stdlib] Discourage CoW copying / rehashing from getting inlined 2018-09-22 02:04:11 +01:00
Karoy Lorentey
3c8ac88778 [stdlib] Remove _Bitset type for now
It is currently unused, but it’s causing issues with the SIL/parse-stlib.sil test.
2018-09-22 02:04:10 +01:00
Karoy Lorentey
a84ece7a26 [stdlib] Bitset: Eliminate a trap that wasn’t optimized away
Signed/unsigned integer conversions check for unrepresentable values; this wasn’t recognized as impossible, so a trap got compiled into the Dictionary lookup path.

Note to self: next time just use bitwise operations.
2018-09-22 02:04:10 +01:00
Karoy Lorentey
e41a6f9f81 [stdlib] Dictionary.removeValue(forKey:): Fix typo. 2018-09-22 02:04:10 +01:00
Karoy Lorentey
9b7ba7d477 [stdlib] Temporary workaround for issue fixed in #19444 2018-09-22 02:04:10 +01:00
Karoy Lorentey
4e64931b77 [stdlib] Set.Iterator.next(): Work around compiler crash in non-ObjC builds 2018-09-22 02:04:10 +01:00
Karoy Lorentey
2094581c5c [stdlib] Add missing calls to cocoaPath()
This should reduce code size and perhaps trigger more optimizations.
2018-09-22 02:04:10 +01:00
Karoy Lorentey
778defac93 [stdlib] Set, Dictionary: Speed up insert/remove when there’s nothing to do
Moving the uniqueness check before the first lookup was a bad idea. Revert it.
2018-09-22 02:04:09 +01:00
Karoy Lorentey
4421d1ea2d [stdlib] Dictionary: Speed up Keys.subscript for bridged dictionaries
There is no need to fetch the value corresponding to the given key.
Also implement the same for Values.subscript, although the impact there is marginal.
2018-09-22 02:04:09 +01:00
Karoy Lorentey
8366edd93d [stdlib] Set, Dictionary: Simplify variant processing
Don’t duplicate native paths — make the cocoa case conditionally unreachable instead.
2018-09-22 02:04:09 +01:00
Karoy Lorentey
c19e20b464 [stdlib] Set, Dictionary: Make _HashTableDelegate implementations inlinable 2018-09-22 02:04:09 +01:00
Karoy Lorentey
c3540de864 [stdlib] Fix performance regression in Dictionary.Keys.contains(_:)
Previously it called index(forKey:) to implement the test, but that method is O(n) for dictionaries bridged over from Cocoa.
2018-09-22 02:04:09 +01:00
Karoy Lorentey
ea6ffd3d91 [stdlib] Dictionary: Fix compilation on non-ObjC platforms 2018-09-22 02:04:08 +01:00
Karoy Lorentey
7e5c6517ab [stdlib] Dictionary: Attempt to work around ClosureSpecializer crash
rdar://problem/44612356
2018-09-22 02:04:08 +01:00
Karoy Lorentey
b4ab5a05f3 [stdlib] Dictionary: Don’t use the allKeys property of bridged indices directly 2018-09-22 02:04:08 +01:00
Karoy Lorentey
39d0ef17a2 [stdlib] Dictionary: prepareForMutation(at:) ⟹ ensureUniqueNative(preserving:)
Also describe it in a doc comment.
2018-09-22 02:04:08 +01:00
Karoy Lorentey
30805120e6 [stdlib] Dictionary: Describe mutatingFind(_:) 2018-09-22 02:04:08 +01:00
Karoy Lorentey
098275f3c7 [stdlib] Clean up Set and Dictionary
- Use _HashTable to unify low-level hashing operations across Set and Dictionary.
- Store the capacity directly inside the storage header. This allows the maximum load factor to be controlled by non-inlinable code.
- Introduce a dedicated class for the empty singleton.
- Add _BridgingHashBuffer, a standalone flat hash buffer for use in deferred bridging. Use it to eliminate the need to support non-hashable storage/wrapper variants and to improve memory use in cases where Key or Value are verbatim bridged.
- Eliminate the “TypedNative*Storage” class and _NativeSet/_NativeDictionary’s support for non-hashable keys.
- Rename storage classes as follows:

_RawNativeSetStorage ⟹ _RawSetStorage
_RawNativeDictionaryStorage ⟹ _RawDictionaryStorage
_TypedNativeSetStorage ⟹ (removed)
_TypedNativeDictionaryStorage ⟹ (removed)
_HashableTypedNativeSetStorage ⟹ _SetStorage
_HashableTypedNativeDictionaryStorage ⟹ _DictionaryStorage

The new names make it obvious which ivar layout is in use.
2018-09-22 02:04:07 +01:00
Karoy Lorentey
86f64f552c [stdlib] GroupInfo.json: Make a Hashing group 2018-09-22 02:04:06 +01:00
Karoy Lorentey
18ad79378f [stdlib] _stdlib_NSObject_isEqual: Make internal 2018-09-22 02:04:06 +01:00
Karoy Lorentey
546c829491 [stdlib] _makeCollectionDescription: Make internal 2018-09-22 02:04:06 +01:00
Karoy Lorentey
19a6ca9ad2 [stdlib] Remove _UnsafeBitMap
Use _UnsafeBitset instead.
2018-09-22 02:04:05 +01:00
Karoy Lorentey
edb8a73203 [stdlib] Set, Dictionary: New storage classes for the empty singletons
This allows us to move the empty NSSet/NSDictionary overrides out of the root storage class; they don’t really belong there. More importantly, it makes empty sets/dictionaries super obvious to lldb and other runtime tools.
2018-09-22 02:04:05 +01:00
Karoy Lorentey
b95ba2507d [stdlib] Add _HashTable implementing low-level hash table operations
_HashTable implements low-level hash table operations that are common between Set and Dictionary. It is a non-generic struct, dealing with maintaining hash table metadata rather than any actual elements.

_HashTable is intended as a mostly transparent abstraction. Most operations are inlinable, except for the ones related to the maximum load factor.
2018-09-22 02:04:05 +01:00
Karoy Lorentey
376753e3a0 [stdlib] Hasher._Seed: Add internal typealias
This is intended to improve readability.
2018-09-22 02:04:05 +01:00
Karoy Lorentey
1848b37300 [stdlib] Add bitset constructs
Bitsets implement sorted sets over nonnegative integers up to a predetermined maximum value.

These are intended to replace _UnsafeBitMap. The latter will be removed once its usages are eliminated.

- _UnsafeBitset.Word is the underlying abstraction, implementing a bitset using a single UInt value.
- _UnsafeBitset is a view over a contiguous range of words.
- _Bitset is a COW value type implementing the same construct.
2018-09-22 02:04:04 +01:00
Michael Ilseman
fee089ccbb Merge pull request #19458 from milseman/text_local_storage
[TLS] Add a uText to our TLS
2018-09-21 13:27:53 -07:00
Mike Ash
49c3547449 Merge remote-tracking branch 'origin/master' into rename-conflicting-classes-and-methods 2018-09-21 15:52:38 -04:00
Ben Cohen
ae6f5dd604 [stdlib] Add consuming/owned annotations to Collection implementations (#19360)
* Add consuming/owned annotations to Collection implementations

* Update SILOptimizer tests

* Fix access_marker_verify test

* XFAIL reconstruct_type_from_mangled_name
2018-09-21 12:06:56 -07:00