Commit Graph

78 Commits

Author SHA1 Message Date
Stephen Canon
a25f72b574 Attempt to clarify the deallocation rules for UMBP. (#85101)
resolves rdar://162944521

---------

Co-authored-by: Guillaume Lessard <glessard@tffenterprises.com>
2025-10-24 13:29:57 -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
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
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
Guillaume Lessard
dabd99d798 Revert "[stdlib] Mark some UnsafePointer APIs as transparent" 2024-06-03 09:40:37 -07:00
Alejandro Alonso
d5f67eb479 Mark some UnsafePointer APIs as transparent 2024-05-30 10:32:14 -07:00
Erik Eckstein
15acfbb268 stdlib: improve debug performance of UnsafePointer.pointer(to:)
Making those functions transparent enables to completely remove the creation of keypaths, even with -Onone.
rdar://127793797
2024-05-16 10:15:53 +02:00
Erik Eckstein
fb036e9019 stdlib: more efficient pointer overflow checks in the UnsafePointer.pointer(to:) functions
Saves the optional nil check for unwrapping the pointer and one condition
2024-05-16 10:15:42 +02: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
Alejandro Alonso
07eb52a80d Merge pull request #72636 from Azoy/destroy-array-opt
[IRGen] Optimize Builtin.arrayDestroy when count is 1
2024-03-28 11:32:43 -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
Alejandro Alonso
8ea3426273 Update comment about arrayDestroy in pointer 2024-03-27 14:02:06 -07:00
Kuba (Brecka) Mracek
89cd62604b Merge pull request #72472 from kubamracek/embedded-keypaths
[embedded] Compile-time (literal) KeyPaths for Embedded Swift
2024-03-25 10:58:51 -07:00
Kuba Mracek
595ea991ce [embedded] Guard @_transparent in UnsafePointer APIs with #if 2024-03-24 18:12:23 -07:00
Kuba Mracek
b642d771be [embedded] Compile-time (literal) KeyPaths for Embedded Swift
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but
for compile-time use only:

- Add keypath optimizations into the mandatory optimizations pipeline
- Allow keypath optimizations to look through begin_borrow, to make them work
  even in OSSA.
- If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics
- Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization
  to happen in the callers of UnsafePointer.pointer(to:).
2024-03-20 15:35:46 -07:00
Karoy Lorentey
e88750eb0c [stdlib] Apply review notes from @glessard (thanks!) 2024-03-18 11:09:08 -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
78270e1e4e [stdlib] UnsafePointer: Resolve most of the symbol mismatches 2024-03-18 11:03:49 -07:00
Karoy Lorentey
5ceb055e29 [stdlib] UnsafePointer: Don’t let the compiler synthesize hashValue 2024-03-18 11:03:49 -07:00
Karoy Lorentey
deda7d6865 [stdlib] UnsafePointer: Add @_preInverseGenerics to _Pointer conformance 2024-03-18 11:03:49 -07:00
Karoy Lorentey
209c66cf74 [stdlib] UnsafePointer: Add @_preInverseGenerics to stored properties 2024-03-18 11:03:49 -07:00
Karoy Lorentey
56ddafb0a0 [stdlib] UnsafePointer: Adopt @_preInverseGenerics 2024-03-18 11:03:49 -07:00
Karoy Lorentey
d0b39ac8db [stdlib] Unsafe[Mutable]Pointer: Add support for non-copyable Pointee types
[stdlib] Pull back @_aeic on pointer → integer conversions

[stdlib] UnsafeMutablePointer.allocate: Fix thinko

[stdlib] Disable support for noncopyable pointees on some pointer operations

We have to temporarily pull back support for noncopyable pointees for UnsafeMutablePointer.initialize(to:), .moveInitialize, .moveUpdate, as the builtins they’re calling are no longer accepting such types.

These will return following a builtin audit.

[stdlib] Remove workarounds for certain builtins not supporting noncopyable use

https://github.com/apple/swift/pull/71733 fixed this!

[stdlib] Update FIXME

[stdlib] UnsafePointer: Update Swift version numbers

[stdlib] UnsafePointer: Actually hide legacy ABI

[stdlib] Remove workaround for U[M]BP.withMemoryRebound
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
Kyle
f96ae2f2db [Documentation] Fix UnsafeMutablePointer's documentation 2023-10-20 10:54:44 +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
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
Guillaume Lessard
1ccc36cbd2 Merge pull request #61082 from glessard/source-equals-destination 2022-10-03 14:50:25 -07:00
Guillaume Lessard
2689b6044b Merge pull request #41608 from glessard/se-pointer-family-initialization 2022-09-13 22:00:59 -06:00
Guillaume Lessard
874cd336ab [stdlib] avoid work when source and destination are the same 2022-09-13 16:15:42 -06:00
Guillaume Lessard
805da6d8ad [stdlib] improve note about subscripts and initialization 2022-08-31 17:24:23 -06:00
Guillaume Lessard
1f4ed8d976 Update stdlib/public/core/UnsafePointer.swift
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2022-08-31 14:19:26 -06:00
Guillaume Lessard
d24b749ac2 [se-0370] improve silgen names for renamed symbols 2022-08-30 18:44:03 -06:00
Guillaume Lessard
d63747f13d [stdlib] remove the single-element update functions
- as per an update to the proposal
2022-08-26 17:36:40 -06:00
Guillaume Lessard
831a87fd36 [stdlib] make additions non-abi 2022-08-26 17:36:40 -06:00
Guillaume Lessard
cc16a9f997 [stdlib] assign → update 2022-08-26 17:36:40 -06:00
Guillaume Lessard
a7326d0353 [gardening] improve doc-comments in UnsafeMutablePointer 2022-08-26 17:36:39 -06:00
Guillaume Lessard
304a422c3e [stdlib] add single-element assign to UnsafeMutablePointer 2022-08-26 17:36:39 -06:00
Guillaume Lessard
1bba62ec13 Merge pull request #60613 from glessard/pointer-arithmetic-overflow-checks
[stdlib] add overflow checks for some pointer arithmetic
2022-08-25 14:37:44 -06:00
Guillaume Lessard
45b81f6456 [stdlib] add overflow checks for some pointer arithmetic
- Overflow checks added for recent additions to pointer arithmetic (rounding and property pointers).
- The basic `advanced(by:)` functions will need to be dealt with separately.
2022-08-22 09:51:10 -06:00
Guillaume Lessard
92087a8f62 [stdlib] add explanations to _debugPrecondition calls 2022-08-18 15:37:25 -06:00
Guillaume Lessard
a74f22dadf [docs] fix a repeated typo 2022-06-29 18:19:34 -06:00
Guillaume Lessard
e353e2f568 [stdlib] document compatibility entry point silgen names better 2022-06-29 16:21:55 -06:00
Guillaume Lessard
6d36a36dd9 [stdlib] improve silgen names and better document intention 2022-06-29 16:20:34 -06:00
Guillaume Lessard
ce7d8134a6 [stdlib] remove preconditions from compatibility entry point
- The old implementation of `UnsafePointer.withMemoryRebound` had no preconditions.
- When implementing SE-0333, we forwarded the old entry point to the new implementation, which has preconditions.
- This change removes the precondition from the compatibility entry point, reverting it to its previous behaviour.
- This resolves rdar://90462471
2022-03-28 18:30:11 -06:00
Guillaume Lessard
f4d56d3734 Merge pull request #41679 from amartini51/trailing_double_tab
Remove trailing double tabs
2022-03-05 13:16:24 -07:00