Commit Graph

104 Commits

Author SHA1 Message Date
Mike Ash
fa5888fb3f [Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names.
Old Swift and new Swift runtimes and overlays need to coexist in the same process. This means there must not be any classes which have the same ObjC runtime name in old and new, because the ObjC runtime doesn't like name collisions.

When possible without breaking source compatibility, classes were renamed in Swift, which results in a different ObjC name.

Public classes were renamed only on the ObjC side using the @_objcRuntimeName attribute.

This is similar to the work done in pull request #19295. That only renamed @objc classes. This renames all of the others, since even pure Swift classes still get an ObjC name.

rdar://problem/46646438
2019-01-15 12:21:20 -05:00
Luciano Almeida
2bc5623bdf [stdlib] Resolving some FIXME comments on Set type. (#20631)
* Fixing some fixmes on stdlib Set

* Adding @inline attr

* Fixing spaces

* Adding isEmpty as fast path in other places where is possible.

* Quotes on variable name on comment.

* Update stdlib/public/core/Set.swift

Co-Authored-By: LucianoPAlmeida <passos.luciano@outlook.com>

* Adding benchmark for isDisjoint Set method

* Adding empty sets to benchmark

* Fixing the factor on benchmarks and naming warnings for empty 5 words
2018-12-14 22:11:12 -06:00
Karoy Lorentey
ce96f1e528 [stdlib] _modify: Use defer to ensure invariants are restored when yield throws
_modify mustn’t leave Collection storage in an inconsistent state when the code to which we’re yielding happens to throw. In practice this means that any cleanup code must happen in defer blocks before the yield.

Fix Dictionary to do just that and add tests to cover this functionality (as well as some other aspects of _modify).
2018-12-05 17:35:24 +00:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Karoy Lorentey
4f8eeae64e [stdlib] Make _NSSetCore, _NSSet internal
These shadow protocols don’t add any real type safety, and exposing them in the ABI seems unnecessary.
2018-11-15 09:54:25 +00:00
Ben Cohen
dbc2e21522 Remove customization points from Sequence and Collection (#19995) 2018-10-31 18:58:00 -07:00
Karoy Lorentey
803a43c537 [stdlib] Set, Dictionary: Change second word in Cocoa indices to an integer offset
_BridgeObject turned out not to be a great choice, because it doesn’t support tagged values on 32-bit platforms. Extracting the offset from index storage is a good idea anyway!
2018-10-27 01:11:59 +01:00
Karoy Lorentey
697ad69d24 [stdlib] Set, Dictionary: Reorganize equality checks to fix Linux builds 2018-10-05 12:33:25 +01:00
Karoy Lorentey
64d19f44db [stdlib] Set, Dictionary: Switch to using a _BridgeObject instead of an enum 2018-10-05 12:33:25 +01:00
Karoy Lorentey
e24f2ba6e5 [stdlib] Set, Dictionary: Flatten switch statements
The optimizer dislikes nested switch statements; flatten them out to simplify optimization and to hopefully speed things up a little.
2018-10-05 12:33:25 +01:00
Karoy Lorentey
2f0f43a869 [stdlib] Dictionary, Set: Force-inline hidden Sequence/Collection customization points
This should eliminate a branch, which should probably lead to a tiny overall code size improvement, as well as a tiny performance boost.
2018-10-03 13:14:48 +01:00
Karoy Lorentey
1529d37301 [stdlib] Implement formIndex(after:) in all hashed collections 2018-09-29 02:30:08 +01:00
Karoy Lorentey
526162f706 [stdlib] Set, Dictionary: Fix uniqueness checking for Cocoa indices 2018-09-29 02:29:32 +01:00
Karoy Lorentey
41bedbe42b [stdlib] Set, Dictionary: Remove inappropriate @_effects from Index hashing 2018-09-28 20:15:55 +01:00
Karoy Lorentey
eb69682f77 [stdlib] Turn _CocoaSet.Index into a COW value type with opaque storage
This enables making the struct @_fixed_layout, which should win us back some of the performance lost by hiding Cocoa indexing internals.
2018-09-28 17:57:20 +01:00
Karoy Lorentey
d477420ee4 [stdlib] Set, Dictionary: Make Cocoa indices resilient for now 2018-09-28 15:18:15 +01:00
Karoy Lorentey
7a8b34a499 [stdlib] Set, Dictionary: Make reserveCapacity non-inlinable
This allows us to record the reserved capacity in storage later, which will enable removals to resize the hash table.
2018-09-28 04:59:33 +01:00
Karoy Lorentey
46475d03d0 [stdlib] Supplying a native index to a bridged set/dictionary is not an internal error 2018-09-27 19:11:57 +01:00
Karoy Lorentey
e687464154 [stdlib] Set: Allow limited use of Cocoa indices in native sets
Affected operations:

subscript(index:)
remove(at:)

Note that index(after:) is intentionally not on this list.
2018-09-27 19:11:43 +01:00
Karoy Lorentey
c765b59b2a [stdlib] Set: Embed & check the mutation count in native indices 2018-09-27 01:49:51 +01:00
Karoy Lorentey
231fbc6218 [stdlib] Fix platforms with a non-ObjC runtime 2018-09-27 00:31:02 +01:00
Karoy Lorentey
e78635119a [stdlib] _NativeSet.Index: Rename to “Bucket”
Update code to reflect the new name, including in method and variable names.
2018-09-27 00:12:20 +01:00
swift-ci
aca00505d9 Merge pull request #19496 from lorentey/hashing-consuming-audit 2018-09-25 11:27:59 -07:00
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
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
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
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
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
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
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
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
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
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
Ben Cohen
75018155ff Kill old set/dictionary-specific bridging entrypoints (#18930) 2018-08-25 07:27:26 -07:00
Karoy Lorentey
d1ec3b9b9b [stdlib] Make Set.isSubset(of:) self-contained; remove standalone function for same 2018-08-16 21:35:24 +01:00
Karoy Lorentey
d2d3c0cb21 [stdlib] Implement Set.contains without retrieving the stored value 2018-08-16 21:35:24 +01:00
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