Commit Graph

153 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
Doug Gregor
7088022eef [Standard library] Eliminate ABI-only rethrows versions from Embedded
Where we have rethrowing versions of functions that have typed-throws
counterparts that are only retained for ABI compatibility, wrap them
in `#if !$Embedded` so they aren't compiled into the Embedded version
of the standard library. This eliminates warnings about this code,
which cannot actually be used with arbitrary errors anyway.
2025-09-17 13:09:49 -07:00
Arnold Schwaighofer
0b5233fa63 stdlib: Mark UnsafeRawBufferPointer's withContiguousStorageIfAvailable as @inline(__always)
The body seems to only reinterpret pointer types (`withMemoryRebound`).
Inlining it should not lead to code size gains and has shown to reduce code size.
2025-08-20 09:19:56 -07:00
Guillaume Lessard
ada94db18c [stdlib] internal UnsafeRawBufferPointer tweaks 2025-07-14 23:04:47 -07:00
Guillaume Lessard
5d4c445347 [stdlib] some span properties are more available 2025-06-30 17:13:35 -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
f952ca5988 [stdlib] add URMBP.mutableBytes accessor 2025-06-16 22:28:21 -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
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
02401d4bb0 Remove some workarounds 2025-02-04 15:16:39 -08:00
Alejandro Alonso
581376e86e Move variable into closure 2025-02-04 15:16:39 -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
Meghana Gupta
2f37e10674 Rewrite UnsafeRawBufferPointer.Iterator.next to avoid non natural loop in SIL
The current implementation creates a non-natural loop and none of the SIL and
LLVM loop passes will work for such loops. We have to find a way to fix this in
SIL. Until then, rewrite so we get a natural loop in SIL.
2024-09-05 15:35:39 -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
Allan Shortlidge
20d97556ae stdlib: Remove #if $TypedThrows guards.
https://github.com/swiftlang/swift/pull/72612 can be reverted because it is no
longer necessary for the interface of the stdlib to be compatible with
compilers without `$TypedThrows` support.
2024-07-08 16:52:52 -07:00
Guillaume Lessard
a707b6849c [stdlib] remove more deprecations added by SE-0426 2024-06-25 14:43:19 -07:00
Nate Chandler
b12def9c6a [BitwiseCopyable] Deprecate unbound overloads.
The unconstrained overloads of loadUnaligned and storeBytes were
deprecated in SE-0426.
2024-04-25 11:44:15 -07:00
Nate Chandler
f9ad81e106 [BitwiseCopyable] Remove #ifs. 2024-04-25 11:44:15 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Allan Shortlidge
a1dacc12d7 stdlib: Make typed throws ABI placeholders properly @usableFromInline.
Functions that are used in public `@inlinable` function bodies can't be marked
`@_spi` nor can they be made obsolete. Also, they must retain `rethrows` so
that use of these entry points from other `rethrows` functions is accepted.

Builds on https://github.com/apple/swift/pull/72365. Once we no longer have to
support pre-`$TypedThrows` compilers, all of this can be reverted.

Part of rdar://125138945
2024-03-27 14:57:56 -07:00
Karoy Lorentey
e88750eb0c [stdlib] Apply review notes from @glessard (thanks!) 2024-03-18 11:09:08 -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
3507a0cf8c [stdlib] Add support for noncopyables to withUnsafePointer(to:) family 2024-03-18 11:03:49 -07:00
Karoy Lorentey
5ae757181e [stdlib] UnsafeRawBufferPointer: new interactions with noncopyable types 2024-03-18 11:03:49 -07:00
Allan Shortlidge
20a8399488 stdlib: Guard @inlinable use of withMemoryRebound() with #if $TypedThrows.
Older compilers can no longer see the definition of `withMemoryRebound()` now
that it has adopted typed throws (https://github.com/apple/swift/pull/72036).

Resolves rdar://124540428
2024-03-13 11:38:24 -07:00
Guillaume Lessard
805dd70cfe Merge pull request #72074 from glessard/toplevel-withbytes-typed-throws
[stdlib] convert `withUnsafeBytes()` to typed throws
2024-03-08 08:55:08 -08:00
Guillaume Lessard
207ae32107 [stdlib] add _withUnprotectedUnsafeMutableBytes() 2024-03-05 02:25:52 -08:00
Guillaume Lessard
528dd0967f [stdlib] convert withUnsafeMutableBytes() to typed throws 2024-03-05 02:12:04 -08:00
Guillaume Lessard
68088bc4e1 [stdlib] convert inout-taking withUnsafeBytes() to typed throws 2024-03-05 02:10:38 -08:00
Guillaume Lessard
f2dcb2f058 [stdlib] convert withUnsafeBytes() to typed throws 2024-03-05 02:10:38 -08:00
Guillaume Lessard
8c0db3fe7e Merge pull request #72075 from Catfish-Man/this-pointer-is-raw
Make UnsafeRawBufferPointer.loadUnaligned inlinable to match other pointer load methods
2024-03-04 23:57:21 -08:00
David Smith
df8485fe87 Make UnsafeRawBufferPointer.loadUnaligned inlinable to match other pointer load methods 2024-03-04 16:00:15 -08:00
Guillaume Lessard
6befe66181 [stdlib] convert U[M]R[B]P.withMemoryRebound() to typed throws 2024-03-01 19:07:46 -08:00
Guillaume Lessard
4e36f5616d [stdlib] operator precedence strikes again 2024-01-14 17:13:24 -08:00
Stephen Canon
c7d50087b0 Check the base address against the element alignment rather than stride
Stride is the gap between elements, not the alignment that each element must satisfy (stride need not even be a power of two).
2024-01-13 16:59:51 -05:00
Nate Chandler
b7f5171b83 [stdlib] BitwiseCopyable loadUnaligned overloads.
The new overloads will make use the new BitwiseCopyableArchetypeTypeInfo
to avoid the extra copy that is currently done.
2023-12-05 17:21:05 -08:00
Nate Cook
2c244b9698 Fix precondition in UMRBP.initialize(as:fromContentsOf:)
This precondition checks to make sure that the content-providing
collection isn't larger than the allocated buffer, but was preventing
using a buffer that is the exact same size as the collection.
2023-10-25 17:17:36 -05: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
Cory Benfield
9cb3641ce8 Remove checks in UR[M]BP.Iterator.next() (#62965)
Swift tends to emit unnecessary checks and traps when iterating unsafe
raw buffer pointers. These traps are confirming that the position
pointer isn't nil, but this check is redundant with the bounds check
that is already present. We can safely remove it.
2023-01-12 11:04:42 -05:00
Guillaume Lessard
2689b6044b Merge pull request #41608 from glessard/se-pointer-family-initialization 2022-09-13 22:00:59 -06:00
Guillaume Lessard
1152347699 [stdlib] remove primary associated type from copyBytes
- this caused an unexpected test failure, will change separately.
2022-09-12 14:18:47 -06:00
Guillaume Lessard
ffa7b0e78c [se-0370] add notes regarding overlapping memory regions 2022-09-08 18:23:45 -06:00
Erik Eckstein
9c1e7cac0f stdlib: fix compilation error when compiling with an old compiler
Fix wrong/missing check for `$BuiltinUnprotectedAddressOf` around the new "unprotectedAddressOf" builtins.

rdar://99713099
2022-09-08 23:05:17 +02:00
Erik Eckstein
0f8dd3a551 stdlib: opt out of stack protection in places where there can't be buffer overflows.
We trust the internal implementation of the stdlib to not cause any unintentional buffer overflows.
In such cases we can use the "unprotected" address-to-pointer conversions.
This avoids inserting stack protections where it's not needed.
2022-09-08 08:42:25 +02:00
Erik Eckstein
ba135dc493 stdlib: add underscored "withUnprotected..Pointer" functions
Those functions work the same way as their "unprotected" counterparts, except that they don't trigger stack protection for the pointers.

* `_withUnprotectedUnsafeMutablePointer`
* `_withUnprotectedUnsafePointer`
* `_withUnprotectedUnsafeBytes` (two times)
2022-09-08 08:42:25 +02:00