Commit Graph

18 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
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Allan Shortlidge
b1bf693f3f stdlib: Remove #if $NoncopyableGenerics guards.
The stdlib is always built with NoncopyableGenerics enabled, so `#if
$NoncopyableGenerics` guards in non-inlinable code are superfluous.
Additionally, the stdlib's interface no longer needs to support compilers
without the feature, so the guards in inlinable code can also be removed.
2024-07-08 17:44:24 -07:00
Alejandro Alonso
f9f640b141 Sendablize the standard library
oops dont add this flag

no more nonisolated
2024-03-05 15:02:09 -08:00
Kavon Farvardin
4096ca39b2 [stdlib] add missing Element type witnesses
With `NoncopyableGenerics` enabled, we currently lose some ability for
associatedtype inference to find a suitable type witness based on a
value witness. (rdar://118998138)

The stdlib accidentally uses that inference for Sequence.Element,
due to the default witness for `_customContainsEquatableElement`
mentioning `Iterator.Element` whereas the requirement only states
`Element`.
2023-11-30 15:05:20 -08:00
Guillaume Lessard
cc16a9f997 [stdlib] assign → update 2022-08-26 17:36:40 -06: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
e2415f78d7 [stdlib] _UnsafeBitset.withTemporaryBitset: New internal function 2021-11-01 21:38:09 -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
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Karoy Lorentey
be0abbbafb [stdlib] _Bitset: Reduce unnecessary overflow checking
This is mostly a code size improvement.
2018-10-05 12:33:25 +01:00
Karoy Lorentey
267b80fe07 [stdlib] _Bitset: Use &* for join and capacity
We know it won’t overflow, because the result will not exceed the capacity, which is guaranteed to fit in an integer.
2018-10-03 12:01:38 +01:00
Karoy Lorentey
18c56540d5 [stdlib] _Bitset: Revert to using division/multiplication
However, convert input values to UInts before dividing them.
2018-10-03 12:01:38 +01:00
Karoy Lorentey
a6f7af161d [stdlib] Bitset: Use explicit left/right shifts instead of multiplication/division by powers-of-two
The divisions don’t get eliminated in -Osize builds.
2018-10-03 12:01:38 +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
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