Commit Graph

52 Commits

Author SHA1 Message Date
Guillaume Lessard 99e7f11042 [stdlib] support typed throws in Set.filter(_:) 2026-02-09 13:12:59 -08:00
Stephen Canon 337b20e8ed Remove some redundant unsafe markings (#83192)
We were getting warnings about these; remove them to cut down on noise.
2025-07-21 11:22:13 -04:00
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 b3038e6d81 stdlib: Address StrictMemorySafety warnings in Set 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
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 2f0883ab24 [embedded] Add Set to the embedded stdlib 2023-12-13 11:28:17 -08:00
Karoy Lorentey 01d7b5799c [stdlib] Fix handling of duplicate items in generic Set.intersection
If the sequence passed to `Set.intersection` has exactly as many duplicate items as items missing from `self`, then the new implementation in 5.6 will mistakenly return `self` unchanged. (It counts duplicate hits as distinct items in the result.)

rdar://94803458
2022-06-13 14:12:48 -07:00
Karoy Lorentey af06df90b6 [stdlib] Optimize Set.subtracting even more 2021-11-02 20:16:35 -07:00
Karoy Lorentey f82b2996ab [stdlib] Delete bogus assert 2021-11-02 19:30:43 -07:00
Karoy Lorentey 2e3e88cab8 [stdlib] Optimize Set.intersection(_:)
Use a temporary bitset to speed up the `Sequence` variant by roughly a factor of ~4-6, and the set/set variant by a factor of ~1-4, depending on the ratio of overlapping elements.
2021-11-01 21:38:10 -07:00
Karoy Lorentey db80c78809 [stdlib] Optimize Set.filter(_:)
This works the same way as `Set.subtracting<S>(_:)`, and has similar performance benefits.
2021-11-01 21:38:10 -07:00
Karoy Lorentey 80296bb606 [stdlib] Optimize Set.subtracting(_:)
Use a temporary bitset to avoid hashing elements more than once, and to prevent rehashings during the creation of the result set.

This leads to a speedup of about 0-4x, depending on the number of elements removed.
2021-11-01 21:38:10 -07:00
Karoy Lorentey a2540c27b7 [stdlib] Optimize Set.isStrictSuperset(of:)
- Use a temporary bitset to speed up the `Sequence` variant by roughly a factor of 4.
- Fix a logic error causing the `a == b` case for the set variant to be O(n) instead of O(1).
2021-11-01 21:38:10 -07:00
Karoy Lorentey 9043c71bd7 [stdlib] Optimize Set.isStrictSubset<S>(of: S)
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
2021-11-01 21:38:09 -07:00
Karoy Lorentey 5e642d2b8d [stdlib] Optimize Set.isSubset<S>(of: S)
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
2021-11-01 21:38:09 -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
Slava Pestov 55e3797471 Revert "Sema: Look for generic parameters first when inferring an associated type"
This breaks source compatibility a little bit more than we'd like, so
reverting it for now.

Fixes <rdar://problem/57213598>.

This reverts commit 04fbcc0149.
2019-11-15 14:32:13 -05:00
Slava Pestov 04fbcc0149 Sema: Look for generic parameters first when inferring an associated type
Previously we did this as a last resort if inference fails. The new
behavior is technically source-breaking, but I suspect nobody
relied on the old behavior.

This can help avoid cycles by eliminating some unnecessary validation work.

Fixes <https://bugs.swift.org/browse/SR-11407>, <rdar://problem/54979757>.
2019-11-13 23:42:08 -05: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 ea6ae67a9f [stlib] _NativeSet: Revert spurious change 2019-04-02 16:38:01 -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 bf09c28b39 Make empty set literals use the singleton 2019-02-11 15:45:16 -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
Ben Cohen 1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08: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 89aa80679b [stdlib] Force-inline native Set iterators 2018-10-03 13:25:51 +01:00
Karoy Lorentey f3006226f3 [stdlib] Mark _NativeSet._delete as non-releasing
Following a previous change that did this for Dictionary.
2018-10-02 20:40:38 +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 b92c301e99 [stdlib] Set, Dictionary: Clean up storage allocation 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 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 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 720f3a0a04 [stdlib] Set, Dictionary: Validate index received on native index(after:) path 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 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 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 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 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