Commit Graph

67 Commits

Author SHA1 Message Date
Doug Gregor
457eb4cc64 [Strict memory safety] Update standard library for nested safe/unsafe types
Use this to mark a few internal types @safe now that it works properly.
2025-04-19 19:54:32 -07:00
Allan Shortlidge
87db90c0da stdlib: Address StrictMemorySafety warnings in Dictionary related code. 2025-03-31 16:45:08 -07:00
Doug Gregor
0d296b5f89 [Standard library] Address remaining memory-safety warnings 2025-03-25 10:57:17 -07:00
Guillaume Lessard
fab65890fb [stdlib] remove now-unnecessary unsafe annotations 2025-03-01 20:29:11 -08:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Kuba Mracek
642a8f9762 [embedded] #ifdef the Dictionary.init(uniqueKeysWithValues:) changes only to Embedded Swift 2025-01-28 16:22:46 -08:00
Kuba Mracek
c99e9e4922 [embedded] Support Dictionary.init(uniqueKeysWithValues:) in Embedded Swift 2025-01-25 14:55:19 -08:00
Alejandro Alonso
f9f640b141 Sendablize the standard library
oops dont add this flag

no more nonisolated
2024-03-05 15:02:09 -08:00
Kuba Mracek
392f2c36eb [embedded] Add Dictionary to embedded stdlib 2024-01-16 13:40:13 -08:00
Lily Lin
a56e658df9 Fix ABI issue in NativeDictionary 2022-06-03 16:49:50 -07:00
Lily Lin
fbd70fe6eb Fix build error for linux builds and add basic validation test 2022-06-03 15:26:06 -07:00
Lily Lin
261216969b Optimize Dictionary.filter for native dictionaries 2022-06-02 16:07:44 -07:00
Alex Martini
1186fc7f13 Remove "iff" from doc comments.
This abbreviation for "if and only if" is confusing to those not coming
from a background in formal mathematics, and is frequently reported as a
type by developers reading the documentation.

This commit also changes doc comments in internal and private members,
which don't become part of the public documentation, because omitting
"iff" everywhere makes it much easier to check for any later changes
that reintroduce it.
2021-10-29 10:16:27 -07:00
David Smith
97073fb5a8 Fast-path contains() for empty Dictionaries 2021-07-26 17:12:00 -07:00
eeckstein
7b12c2efbf Merge pull request #29353 from eeckstein/dict-code-size
stdlib: move Dictionary's find functions into __RawDictionaryStorage.
2020-01-24 22:37:14 +01:00
Erik Eckstein
78728d8df5 stdlib: extract the common code of _NativeDictionary.resize and copyAndResize into a separate function
For code size reduction.
2020-01-24 10:40:41 +01:00
Erik Eckstein
ef007519b1 stdlib: move Dictionary's find functions into __RawDictionaryStorage.
The find functions do not require the generic Value parameter. Moving them to __RawDictionaryStorage allows to define them with only one generic parameter: the Key.
This allows the optimizer to share specializations for dictionaries which have the same Key, but a different Value.
Also, prevent inlining of the find-functions to save some additional code size.
2020-01-22 15:29:32 +01:00
Karoy Lorentey
d7e57347ee [stdlib] Unify _NativeDictionary.subscript._modify’s two yields to work around SR-10604 2019-08-07 17:15:04 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Karoy Lorentey
1ddf99a9da [stdlib] Set, Dictionary: Unify casting operations 2019-04-02 13:10:55 -07:00
Karoy Lorentey
2bd5da539e [stdlib] Fix Set/Dictionary casting issues
- Fix Set/Dictionary up/downcasting with String keys.
- Improve error handling.
2019-03-29 19:15:09 -07:00
David Smith
bf32e78737 Make bridged empty NSDictionary and NSSet instances bridge to the empty singletons 2019-02-11 15:54:19 -08:00
David Smith
2a9aa16b3f Make empty dictionary literals use the singleton 2019-02-11 15:38:22 -08:00
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
Karoy Lorentey
9d61bad1e5 [stdlib] Keep the first duplicate key instead of the last 2018-12-18 09:49:58 -08:00
Karoy Lorentey
f1f5e0f2bf [stdlib] Dictionary: Add unsafe bulk-loading initializer
Interface inspired by this Array pitch:
https://forums.swift.org/t/array-initializer-with-access-to-uninitialized-buffer/13689
2018-12-18 09:49:58 -08:00
Erik Eckstein
aae60ff271 stdlib: Code size improvements for Dictionary for -Osize
The first change is to remove some @inline(__always) attributes. Those were added before we had the guaranteed-by-default calling convention. They are not necessary anymore.

The second change is to not specialize some slow-path functions. This results that no specialization code for these functions is generated at the client side. Instead those functions are directly called in the libSwiftCore.
Note that Key-related hash and equality comparisons are still specialized, because otherwise the performance hit for Osize would be too big.

Some Dictionary benchmarks regress a bit with -Osize, but the code size wins are big.

rdar://problem/46534453
2018-12-13 16:59:19 -08: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
Karoy Lorentey
d32fd283b0 [stdlib] Refactor Dictionary.subscript._modify for better layering
This may also reduce ARC traffic by a little bit.
2018-11-30 17:47:08 +00:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Maxim Moiseev
cbf83ac04f [NFC][stdlib] Add FIXME markers to simplify audit 2018-11-14 11:58:42 -08:00
Slava Pestov
f6c2caf64b stdlib: Add @inlinable to @inline(__always) declarations
These should be audited since some might not actually need to be
@inlinable, but for now:

- Anything public and @inline(__always) is now also @inlinable
- Anything @usableFromInline and @inline(__always) is now @inlinable
2018-11-13 15:15:07 -05:00
Karoy Lorentey
bb2cb064ae [stdlib] Eliminate more overflow checks
This is a tiny code size improvement.
2018-10-05 12:33:25 +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
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
a2e21667eb Merge pull request #19694 from lorentey/values-isnt-really-a-mutablecollection
[stdlib] Allow native dictionaries to advance Cocoa indices
2018-10-04 11:45:22 +01:00
Karoy Lorentey
6e671b6631 [stdlib] Allow native dictionaries to advance Cocoa indices 2018-10-03 21:05:46 +01:00
Karoy Lorentey
6cb546534e [stdlib] Dictionary: Force-inline native iterators 2018-10-03 13:23:47 +01:00
Karoy Lorentey
d6e31a80f1 [stdlib] Mark _NativeDictionary._delete(at:) non-releasing
This eliminates a retain/release pair around calls to it when it doesn’t get inlined.

_delete is responsible for restoring hash table invariants after a removal. It moves around elements in complicated patterns, but it doesn’t release them.
2018-10-02 15:38:39 +01:00
Karoy Lorentey
2b7ef24990 [stdlib] Dictionary.merge: Don’t leave storage in an inconsistent state when closure throws 2018-10-01 15:40:14 +01:00
Karoy Lorentey
ee4ad7a014 Merge pull request #19589 from lorentey/prepare-for-per-instance-seeds
[stdlib] Set, Dictionary: Prepare for per-instance hash seeds
2018-09-28 11:38:02 +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
e080bab5e5 Merge pull request #19602 from lorentey/dict-iterators
[stdlib] Dictionary.Keys, .Values: Implement custom iterators
2018-09-28 04:18:15 +01:00
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
a05a66cdce [stdlib] Dictionary.Keys, .Values: Implement custom iterators 2018-09-28 02:10:17 +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
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