Commit Graph

209 Commits

Author SHA1 Message Date
David Smith
7b78a1d4b4 Avoid StringUTF16View dispatch overhead for some bridged String methods (#83529)
This removes a bunch of overhead on the UTF16 paths in String, as well
as consolidating the complicated bits of the logic in one file.
2025-09-22 17:03:24 -07:00
Stephen Canon
de8c4cd4d5 Mark U[M]BP.baseAddress transparent (#84097)
As well as a few other trivial API, since apparentely these do not reliably get inlined as-is.

Addresses rdar://159801610
2025-09-04 08:21:16 -04:00
Guillaume Lessard
a2ae072430 [stdlib] alignment-checking functions for pointers
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2025-07-14 23:04:45 -07:00
Guillaume Lessard
36b5090a98 Merge pull request #82598 from glessard/rdar153654652-now-available
[stdlib] add `span` properties to the backdeployment library
2025-07-07 02:46:10 -07:00
Guillaume Lessard
5d4c445347 [stdlib] some span properties are more available 2025-06-30 17:13:35 -07:00
Alex Martini
3928ddfeb4 Fix repeated text 2025-06-30 09:36:37 -07:00
Guillaume Lessard
c8092f50d1 [stdlib] simplify borrowing accessors 2025-06-26 14:57:21 -07:00
Guillaume Lessard
bbfe648c54 [stdlib] improve accessor declarations 2025-06-26 14:57:21 -07:00
Guillaume Lessard
0433cd292c [stdlib] add UMBP.mutableSpan accessor 2025-06-16 22:28:21 -07:00
Doug Gregor
fe6856726e [Strict memory safety] Remove now-extraneous "unsafe" from the standard libraries
Now that we aren't propagating "unsafe" to nested types, remove
unnecessary "unsafe" keywords from the standard library.
2025-04-19 08:13:05 -07:00
Alex Martini
0bd4ee3ca6 Merge pull request #80359 from amartini51/doc_fixes
Documentation fixes
2025-03-28 15:33:40 -07:00
Alex Martini
84a4a849e2 Fix indentation - move prose out of code listing
Fixes: rdar://145075268
2025-03-27 16:49:48 -07:00
Karoy Lorentey
480f87027d [stdlib] Mark Unsafe*BufferPointer.indices as safe 2025-03-24 12:16:15 -07:00
Karoy Lorentey
cf35c65863 [stdlib] Generalize Unsafe[Mutable]BufferPointer.indices 2025-03-24 12:15:55 -07:00
Guillaume Lessard
940628a23a [stdlib] add newly-required unsafe annotations 2025-03-10 15:20:51 -07:00
Guillaume Lessard
9cdd83b469 [stdlib] add span properties to UnsafeBufferPointer family 2025-03-10 08:51:56 -07:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Andrew Trick
fe59764f31 Make Unsafe[Mutable]BufferPointer conform to BitwiseCopyable.
The Span interface requires this. It needs to be able to create dependencies on
UBP values without creating extra temporary copies.

This is only a temporary workaround for:

rdar://140291657 (ASTPrinter: print synthesized conformances on the type
definition, not as an extension)

Until that ASTPrinter bug is fixed, .swiftinterface files drop BitwiseCopyable
conformance on types that have conditionally ~Copyable generic parameters.
2024-11-20 12:27:23 -08:00
Guillaume Lessard
a50260b181 [stdlib] Avoid unnecessary null-pointer checks in UM[R]BP bulk-copy functions 2024-11-11 23:57:47 -05:00
Guillaume Lessard
a35dea18c5 [gardening] remove obsolete annotations 2024-09-19 12:56:31 -07:00
Doug Gregor
8378562e12 Adopt @unsafe throughout the standard library
Annotate all of the `Unsafe*` types and `unsafe` functions in the standard
library (including concurrency, synchronization, etc.) as `@unsafe`. Add a
few tests to ensure that we detect uses of these types in clients that
have disabled unsafe code.
2024-08-19 14:33:09 -07:00
Karoy Lorentey
9d947e4de0 [stdlib] Add missing overload of extracting for UnboundedRange
I keep forgetting that `some RangeExpression<Element>` does not cover the `UnboundedRange` form.
2024-06-17 15:03:12 -07:00
Karoy Lorentey
ab51f1630c [stdlib] API additions for basic noncopyable primitives
- Add `exchange(_:with:)`
- Add `Optional.take()`
- Add `Unsafe[Mutable]BufferPointer.extracting(_:)`
- Finish generalizing `withExtendedLifetime`
- Radically simplify the implementation of `swap(_:_:)`
2024-06-07 14:09:53 -07:00
Karoy Lorentey
cafc99369b [stdlib] Round out ~Copyable generalizations in stdlib primitives
- `Optional.map`, `.flatMap`: Allow noncopyable results. Implement typed throws.

- `Result.map`, `.flatMap`: Allow noncopyable types for the new success.
- `Result.flatMapError`: Generalize for noncopyable Success.

- `Unsafe[Mutable][Buffer]Pointer.withMemoryRebound`: Alllow typed throws.
- `Unsafe[Mutable]BufferPointer: Generalize CustomDebugStringConvertible conformance for noncopyable `Element`s.

- `OpaquePointer.init(_: UnsafeMutablePointer)`, `.init(_: UnsafeMutablePointer?)`: Allow noncopyable pointee types.

- `ManagedBuffer.withUnsafeMutablePointerToHeader`, `.withUnsafeMutablePointerToElements`, `.withUnsafeMutablePointers`: Generalize for typed throws and noncopyable return types. Avoid `@_preInverseGenerics`.
- `ManagedBufferPointer`: Ditto.

- `withExtendedLifetime`: Use typed throws. Stop using `@_preInverseGenerics`.

rdar://117753275
2024-04-16 01:15:33 -07:00
Allan Shortlidge
37034282a1 stdlib: Adopt @_disallowFeatureSuppression(NoncopyableGenerics).
This prevents some re-declaration errors when building the standard library
from its `.swiftinterface` with older compilers.
2024-03-27 22:20:50 -07:00
Karoy Lorentey
38001ae739 [stdlib] Apply @Azoy’s remaining review notes (thanks!) 2024-03-18 11:03:49 -07:00
Karoy Lorentey
d70f197c24 [stdlib] Update SwiftStdlibLegacyABI convention to use @available(swift, obsoleted: 1)
Using version `2` here is just weird for no reason.
2024-03-18 11:03:49 -07:00
Karoy Lorentey
d15d5004c8 [stdlib] Unsafe[Mutable]BufferPointer: Add support for non-copyable Pointee types 2024-03-18 11:03:49 -07:00
Nate Chandler
367d71d74f Revert "[stdlib] Uncheck pointers' conf to BitwiseCopyable"
This reverts commit 4dc9713a7a.
2024-01-31 17:11:54 -08:00
Nate Chandler
4dc9713a7a [stdlib] Uncheck pointers' conf to BitwiseCopyable
The pitch calls for such types to obstruct inference of _BitwiseCopyable
in aggregates containing them.
2024-01-30 14:38:07 -08:00
Guillaume Lessard
3e73445a3e Merge pull request #61093 from glessard/se0370-primary-associated-types
[stdlib] use a primary associated type
2024-01-03 10:59:57 -08:00
Pavel Yaskevich
a0dfab9ab2 [SE-0331] Mark unsafe pointer conformances to Sendable as explicitly unavailable
This is a preferred way to make sure that Sendable inference doesn't
happen for these types because they are marked as @frozen.
2023-10-10 21:42:46 -07:00
Kuba Mracek
92b075b518 [embedded] Drop several #ifs and fatalError()s by adding an unavailable ExpressibleByStringInterpolation String conformance 2023-09-16 13:40:25 -07:00
Kuba Mracek
ae2e903574 [embedded] Build an initial embedded Swift standard library
This isn't a "complete" port of the standard library for embedded Swift, but
something that should serve as a starting point for further iterations on the
stdlib.

- General CMake logic for building a library as ".swiftmodule only" (ONLY_SWIFTMODULE).
- CMake logic in stdlib/public/core/CMakeLists.txt to start building the embedded stdlib for a handful of hardcoded target triples.
- Lots of annotations throughout the standard library to make types, functions, protocols unavailable in embedded Swift (@_unavailableInEmbedded).
- Mainly this is about stdlib functionality that relies on existentials, type erasure, metatypes, reflection, string interpolations.
- We rely on function body removal of unavailable functions to eliminate the actual problematic SIL code (existentials).
- Many .swift files are not included in the compilation of embedded stdlib at all, to simplify the scope of the annotations.
- EmbeddedStubs.swift is used to stub out (as unavailable and fatalError'd) the missing functionality.
2023-09-16 12:38:46 -07:00
Kyle Murray
1f0b2e59fa Remove a stale fixme comment.
Per Ben's feedback in the PR.
2023-01-30 10:42:42 -05:00
Kyle Murray
15ebec6e23 [stdlib] NFS: Restore documentation comment for Unsafe[Mutable]BufferPointer
Moves a `//` comment up above a `///` documentation comment, since the latter needs to be attached directly to the declaration or it won't be picked up as documentation.
2023-01-28 12:57:41 -05:00
Guillaume Lessard
03d37a9538 [stdlib] use _copyContents after all
- originally had avoided `_copyContents` because all the standard library fast paths were already covered.
- however Swift Collections piecewise-contiguous collections still rely on `_copyContents` to accelerate copies.
2022-09-14 16:23:21 -06:00
Guillaume Lessard
4f4bfba61c [stdlib] use a primary associated type 2022-09-14 02:27:18 -06:00
Guillaume Lessard
7f4caede90 [stdlib] avoid primary associated type for the time being 2022-09-13 13:31:44 -06:00
Guillaume Lessard
ffa7b0e78c [se-0370] add notes regarding overlapping memory regions 2022-09-08 18:23:45 -06:00
Guillaume Lessard
559e5ed54b [stdlib] use the internal precondition calls 2022-09-07 16:47:08 -06:00
Guillaume Lessard
44a349f8e0 [se-0370] edit doc-comments for consistency 2022-09-07 15:22:49 -06:00
Guillaume Lessard
805da6d8ad [stdlib] improve note about subscripts and initialization 2022-08-31 17:24:23 -06:00
Guillaume Lessard
99505d0819 [stdlib] simplify update(from:)
- one fewer variable, one fewer return point
- thanks @benrimmington
2022-08-31 11:49:06 -06:00
Guillaume Lessard
aabf2e2843 Update stdlib/public/core/UnsafeBufferPointer.swift.gyb
Co-authored-by: YR Chen <stevapple@icloud.com>
2022-08-31 10:50:25 -06:00
Guillaume Lessard
285984e3ae [stdlib] simplify update(fromContentsOf:)
- one fewer variable, one fewer return point
2022-08-31 10:46:36 -06:00
Guillaume Lessard
d24b749ac2 [se-0370] improve silgen names for renamed symbols 2022-08-30 18:44:03 -06:00
Guillaume Lessard
c2c432c9d2 [se-0370] re-implement in accordance with updated proposal 2022-08-30 11:05:41 -06:00
Guillaume Lessard
f5ffe09c53 [se-0370] fix editing errors 2022-08-26 17:36:40 -06:00
Guillaume Lessard
0a78756bf4 [se-0370] add element labels to a returned tuple
- this is technically source-breaking,
  but the risk seems to be very low.
2022-08-26 17:36:40 -06:00