Commit Graph

5263 Commits

Author SHA1 Message Date
Karoy Lorentey
b92c301e99 [stdlib] Set, Dictionary: Clean up storage allocation 2018-09-28 04:04:29 +01:00
Karoy Lorentey
7826c3c01b [stdlib] Dictionary.mapValues: Copy the seed over to the new dictionary 2018-09-28 04:04:29 +01:00
Karoy Lorentey
91c5a310fa [stdlib] Set, Dictionary: Prepare for per-instance hash seeds
Implement the per-instance seeding infrastructure without actually enabling per-instance seeding.
2018-09-28 04:04:28 +01:00
Karoy Lorentey
e5d711c5a1 Merge pull request #19576 from lorentey/aged-indices
[stdlib] Set, Dictionary: Radically improved index validation
2018-09-28 04:00:38 +01:00
Karoy Lorentey
c0d153505b [stdlib] Add *another* missing check for ObjC runtime 2018-09-28 02:14:10 +01:00
Karoy Lorentey
a05a66cdce [stdlib] Dictionary.Keys, .Values: Implement custom iterators 2018-09-28 02:10:17 +01:00
Karoy Lorentey
8c8f822b23 Merge pull request #19592 from lorentey/update-value-not-key2
[stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key
2018-09-28 00:42:48 +01:00
Karoy Lorentey
eb51801474 [stdlib] Add missing check for ObjC runtime 2018-09-27 22:33:53 +01:00
Karoy Lorentey
7ff82b3ba9 [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

# Conflicts:
#	stdlib/public/core/NativeDictionary.swift
2018-09-27 21:20:54 +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
9a0e303ac6 [stdlib] Dictionary: Allow limited use of Cocoa indices in native dictionaries
Affected operations:

subscript(index:)
keys.subscript(index:)
values.subscript(index:) (setter and _modify)
remove(at:)
swapAt(_:, _:)

Note that index(after:) is intentionally not on this list.
2018-09-27 19:11:50 +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
d3178a0394 [stdlib] Tighten up Cocoa index validation for native sets/dictionaries
Like before, allow the use of Cocoa indices to access native sets/dictionaries, but approximate the same mutation count-based check as we do for native indices.

- Ensure that native collections that were converted from Cocoa have an age generated from the address of the original Cocoa object.
- To get the age of a Cocoa index, regenerate one from the object embedded in it.
- Compare self.age to index.age and trap if it doesn’t match.

# Conflicts:
#	stdlib/public/core/HashTable.swift
2018-09-27 19:11:19 +01:00
Karoy Lorentey
125f31ed52 [stdlib] validate(_:) ⟹ validatedBucket(for:)
This makes it a little easier to follow validation logic.
2018-09-27 19:09:49 +01:00
Karoy Lorentey
656685777f [stdlib] Dictionary: Update remove(at:) and Values to allow Cocoa indices 2018-09-27 19:09:43 +01:00
Karoy Lorentey
4aec137789 [stdlib] Set, Dictionary: Use lowercase index in validation error messages
Capital Index seems too nitpicky, somehow
2018-09-27 19:09:33 +01:00
Karoy Lorentey
04d5ab3498 [stdlib] Native Set, Dictionary: Add index validation support for top-level indices
Native sets and (especially!) native dictionaries must support indexing with Cocoa indices — indices must be preserved when a Cocoa set/dictionary is converted to native.

This is especially the case for Dictionaries that were converted because of a mutation restricted to values — such as those done through the Values view.
2018-09-27 19:09:26 +01:00
Karoy Lorentey
f73dca8050 [stdlib] _CocoaSet.element, _CocoaDictionary.key: New properties 2018-09-27 19:08:38 +01:00
Max Moiseev
b9b568b6ec Merge pull request #19565 from moiseev/try-bang-location-info
try! error message should report the right location
2018-09-27 09:12:46 -07:00
Karoy Lorentey
6033454201 [stdlib] Dictionary.Values: Specialize swapAt 2018-09-27 01:49:51 +01:00
Karoy Lorentey
be68ede45b [stdlib] Dictionary.Values.subscript: Validate index in _modify accessor 2018-09-27 01:49:51 +01:00
Karoy Lorentey
720f3a0a04 [stdlib] Set, Dictionary: Validate index received on native index(after:) path 2018-09-27 01:49:51 +01:00
Karoy Lorentey
863e8b6373 [stdlib] Set, Dictionary: Add a message to fast enumeration state checks 2018-09-27 01:49:51 +01:00
Karoy Lorentey
e5d976de14 [stdlib] Dictionary: Embed & check the mutation count in native indices 2018-09-27 01:49:51 +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
5705582ad9 [stdlib] _HashTable.Index: New struct
Set and Dictionary will start using this shortly as their native index types.
2018-09-27 01:49:51 +01:00
Karoy Lorentey
f600426d87 [stdlib][NFC] Update comments 2018-09-27 01:49:50 +01:00
Karoy Lorentey
c3caa649d0 [stdlib] _NativeSet._delete: check that count doesn’t go below 0
(For symmetry with Dictionary, which already has this check.)
2018-09-27 01:49:50 +01:00
Karoy Lorentey
e608901eb0 [stdlib] Fill out the 24 bits currently left as padding in Set/Dictionary storage 2018-09-27 01:49:50 +01:00
Karoy Lorentey
6358294be8 [stdlib] Set, Dictionary: Add a mutation count to storage ivars
The mutation count will allow us to recognize and trap on invalid indices more reliably. (However, it won’t be foolproof — some invalid indices may pass through the checks.)

- Change _scale to Int8 to make space for an extra Int32 without enlarging the storage header.
- Add an _age field inside the new gap.
- Initialize the age to a scrambled version of the storage address.
- Generate a new counter for every newly allocated storage instance, except for identical copy-on-write copies.
- Increment the mutation counter after every removal.
2018-09-27 01:49:50 +01:00
Karoy Lorentey
231fbc6218 [stdlib] Fix platforms with a non-ObjC runtime 2018-09-27 00:31:02 +01:00
Karoy Lorentey
7cd482ed98 [stdlib] Set, Dictionary: _uncheckedInitialize should take __owned arguments 2018-09-27 00:12:35 +01:00
Karoy Lorentey
afe55f5f26 [stdlib] _NativeDictionary.init(capacity:) make inlinable 2018-09-27 00:12:35 +01:00
Karoy Lorentey
0fee12b56d [stdlib] Update _HashTable terminology
- Remove the old Index typealias for _HashTable.Bucket
- Rename _HashTable.AgedIndex to _HashTable.Index
- Rename _HashTable.Bucket.bucket to _HashTable.Bucket.offset
- Rename/update _HashTable members to adopt to new terminology
2018-09-27 00:12:35 +01:00
Karoy Lorentey
0cddeca3c4 [stdlib] _HashTable: Remove obsolete debug code 2018-09-27 00:12:20 +01:00
Karoy Lorentey
79b536fbba [stdlib] Update _BridgingHashBuffer to reflect new names 2018-09-27 00:12:20 +01:00
Karoy Lorentey
efe6f38d40 [stdlib] _NativeDictionary.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
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
Karoy Lorentey
9b63c8b1b5 [stdlib] _HashTable: Prepare for upcoming renamings 2018-09-27 00:12:20 +01:00
Maxim Moiseev
5f17e64be0 try! error message should reprt the right location
At the moment the location being reported is inside the standard
library, which is not very helpful. Instead, the location should point
at the `try!` expression in the application code.

Fixes: rdar://problem/21407683
2018-09-26 11:22:41 -07:00
Karoy Lorentey
b4e27b110a Revert "[stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key" 2018-09-26 16:08:07 +01:00
Karoy Lorentey
1ab367b262 Merge pull request #19500 from lorentey/updateValue-but-not-the-key
[stdlib] Dictionary.updateValue(_:,forKey:): Don’t overwrite the existing key
2018-09-26 14:32:04 +01:00
Ben Cohen
c690e681aa Fix typo 2018-09-25 15:25:13 -07:00
Ben Cohen
098a8919c4 Remove redundant implementations of !=(Equatable,Equatable) 2018-09-25 15:24:23 -07:00
swift-ci
aca00505d9 Merge pull request #19496 from lorentey/hashing-consuming-audit 2018-09-25 11:27:59 -07:00
Dale Buckley
62f8042206 FIxed typo 2018-09-25 17:00:27 +01:00
Karoy Lorentey
7058f48f37 [stdlib][NFC] Cosmetics 2018-09-25 16:58:12 +01:00
Dale Buckley
cca8bfba65 Renamed CodingKey raw names for better consistency 2018-09-25 16:31:27 +01:00
Dale Buckley
ac16b20a08 Codable cleanup 2018-09-25 14:45:23 +01:00
Dale Buckley
c45cdb7b7b Added Codable conformance for Range, ClosedRange, PartialRangeUpTo, PartialRangeThrough and PartialRangeFrom 2018-09-25 13:29:24 +01:00