Commit Graph

7923 Commits

Author SHA1 Message Date
Kavon Farvardin
f8a31c6c9d Merge pull request #85573 from kavon/document-escapable
Doc: add explainer for `Escapable`
2025-11-20 01:49:23 -08:00
Kavon Farvardin
7e9608cccc Doc: small fixes for Escapable explainer
Thanks to a review from @amartini51

Co-authored-by: Alex Martini <amartini@apple.com>
2025-11-18 15:14:38 -08:00
Kavon Farvardin
55eaed524e Doc: add explainer for Escapable
resolves rdar://146331729
2025-11-18 14:36:29 -08:00
Arnold Schwaighofer
17447a3378 Merge pull request #85551 from aschwaighofer/wip_embedded_exit
Preliminary support for existential in embedded Swift
2025-11-18 15:10:40 -05:00
Dave Lee
b6b477de58 [Debug] Add pointer based stringForPrintObject (#84742)
Adds an overload of `_DebuggerSupport.stringForPrintObject` which takes a pointer and mangled typename as arguments. This will be used to improve performance and resilience of `po` in lldb.

The pointer and mangled typename are used to construct an `Any` value, which is then passed into the primary implementation of `stringForPrintObject`.

This allows calling `stringForPrintObject` without having to first construct a context that contains all necessary Swift modules. This will improve speed, and also resilience when modules cannot be loaded for whatever reason.

rdar://158968103
2025-11-18 09:32:28 -08:00
Tim Kientzle
a271eb2bb7 Merge pull request #85544 from tbkka/tbkka-Issue85539
Properly initialize buffer when called via legacy ABI
2025-11-17 19:50:07 -08:00
Arnold Schwaighofer
02d7fe5110 Document the difference of embedded swift's swift_allocBox 2025-11-17 12:48:48 -08:00
Arnold Schwaighofer
62ac48a17e Complete support for outline existential storage
... or so I believe
2025-11-17 12:48:45 -08:00
Arnold Schwaighofer
eda5eadfd4 Start outline storage support: Add swift_allocBox/deallocBox
Code using the outline heap storage path will crash and burn because
support is incomplete. But at least inline storage existential
inhabitants should compile and run.
2025-11-17 12:46:35 -08:00
Tim Kientzle
f65358521f Properly initialize buffer when called via legacy ABI
Resolves #85539
2025-11-17 10:56:10 -08:00
Doug Gregor
8e37909131 Merge pull request #85505 from DougGregor/c-funcs-for-embedded-runtime
Use @c instead of @_cdecl in the Embedded Swift runtime
2025-11-13 23:41:03 -08:00
Meghana Gupta
4ebc087bef Merge pull request #85481 from meg-gupta/mutablespanbitwisecopyable
Update MutableSpan and OutputSpan
2025-11-13 22:51:28 -08:00
Doug Gregor
9ea8671c3f Use @c instead of @_cdecl in the Embedded Swift runtime
This change moves us toward the official feature, and eliminates the
extra level of "thunk" that was implied by `@_cdecl`. Amusingly, this
trips up the LLVM-level ARC optimizations, because we are trying to
perform ARC optimizations within the retain/release runtime functions.
Teach those optimization passes to leave swift_retainN et al alone.
2025-11-13 18:39:10 -08:00
Meghana Gupta
c93163cada Add _assumeNonNegative to OutputSpan's count as well 2025-11-13 13:48:27 -08:00
Meghana Gupta
40a2ecb57e Update subscript and count for MutableSpan and OutputSpan with @_semantics 2025-11-13 08:58:15 -08:00
Mike Ash
cc8e6fd877 Merge pull request #85260 from mikeash/client-rr-library-rename
[Runtime] Rename ClientRetainRelease library to SwiftDirectRuntime.
2025-11-08 12:40:27 -05:00
Mike Ash
1898b01ce6 [Runtime] Rename ClientRetainRelease library to SwiftDirectRuntime.
This library will likely become home to other fast-path-in-client functions, so give it a more general name.
2025-11-07 16:36:29 -05:00
Alejandro Alonso
aad6cae864 Merge pull request #84314 from valeriyvan/OutputRawSpan
Minor fixes in OutputRawSpan.swift
2025-11-06 17:51:55 -08:00
Mishal Shah
60d09fff62 Merge pull request #85315 from swiftlang/count-mixup
Make sure we don't compare too many bytes if a non-native string being compared to a native one has the same utf16 count but a different utf8 count
2025-11-05 16:35:28 -08:00
David Smith
f03c1fe16b Clarify an explanation 2025-11-04 12:43:42 -08:00
David Smith
70f4d7e6d7 Review comment 2025-11-04 12:43:23 -08:00
David Smith
e7ba16381c Make sure we don't compare too many bytes if a non-native string being compared to a native one has the same utf16 count but a different utf8 count 2025-11-04 11:43:43 -08:00
Jai
d9383e6aa5 Fix crash when accessing span of empty InlineArray (#85268)
Fix crash when creating a Span from an empty InlineArray whose storage
is only byte-aligned. #85265.

---------

Co-authored-by: Guillaume Lessard <glessard@tffenterprises.com>
2025-11-04 10:15:24 -05:00
Xiaodi Wu
591fec274a [stdlib][SR-9438] Re-implement integer-to-string conversion (redux) (#85180)
Inspired by #84826, I've dusted off and completely reworked a native
implementation of integer-to-string conversion.

Besides existing tests in this repository, the core of the
implementation has been comprehensively tested in a separate package for
all bases between 2–36 to demonstrate identical output for all 8-bit and
16-bit values, and for randomly generated 32-bit, 64-bit, and 128-bit
values.

Resolves #51902.

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-11-03 21:23:12 -05:00
Alejandro Alonso
9cd81d2065 Merge pull request #84422 from valeriyvan/UTF8SpanIterators
Fix doc comments in UTF8SpanIterators.swift
2025-10-28 17:11:12 -07:00
Alejandro Alonso
384f69b75f Merge pull request #84317 from valeriyvan/UTF8EncodingError
Fix typo in UTF8EncodingError
2025-10-28 16:57:54 -07:00
Valeriy Van
405a267585 Fix doc comment of Span (#84418) 2025-10-28 15:29:24 -07:00
Alex Martini
2a9f587256 Merge pull request #85163 from amartini51/SendableMetatype_163470972
Split SendableMetatype abstract from discussion.

Fixes: rdar://163470972
2025-10-28 10:58:21 -07:00
Mike Ash
3a0b3924df Merge pull request #85044 from mikeash/emit-into-client-retain-release
[IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
2025-10-28 12:09:01 -04:00
Valeriy Van
9bc85b74bf Merge branch 'main' into UTF8SpanIterators 2025-10-28 14:11:32 +01:00
Alex Martini
96b16af70f Split out abstract from discussion 2025-10-27 13:54:04 -07:00
Mike Ash
93fae78e04 [IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
This is currently disabled by default. Building the client library can be enabled with the CMake option SWIFT_BUILD_CLIENT_RETAIN_RELEASE, and using the library can be enabled with the flags -Xfrontend -enable-client-retain-release.

To improve retain/release performance, we build a static library containing optimized implementations of the fast paths of swift_retain, swift_release, and the corresponding bridgeObject functions. This avoids going through a stub to make a cross-library call.

IRGen gains awareness of these new functions and emits calls to them when the functionality is enabled and the target supports them. Two options are added to force use of them on or off: -enable-client-retain-release and -disable-client-retain-release. When enabled, the compiler auto-links the static library containing the implementations.

The new calls also use LLVM's preserve_most calling convention. Since retain/release doesn't need a large number of scratch registers, this is mostly harmless for the implementation, while allowing callers to improve code size and performance by spilling fewer registers around refcounting calls. (Experiments with an even more aggressive calling convention preserving x2 and up showed an insignificant savings in code size, so preserve_most seems to be a good middle ground.)

Since the implementations are embedded into client binaries, any change in the runtime's refcounting implementation needs to stay compatible with this new fast path implementation. This is ensured by having the implementation use a runtime-provided mask to check whether it can proceed into its fast path. The mask is provided as the address of the absolute symbol _swift_retainRelease_slowpath_mask_v1. If that mask ANDed with the object's current refcount field is non-zero, then we take the slow path. A future runtime that changes the refcounting implementation can adjust this mask to match, or set the mask to all 1s to disable the old embedded fast path entirely (as long as the new representation never uses 0 as a valid refcount field value).

As part of this work, the overall approach for bridgeObjectRetain is changed slightly. Previously, it would mask off the spare bits from the native pointer and then call through to swift_retain. This either lost the spare bits in the return value (when tail calling swift_retain) which is problematic since it's supposed to return its parameter, or it required pushing a stack frame which is inefficient. Now, swift_retain takes on the responsibility of masking off spare bits from the parameter and preserving them in the return value. This is a trivial addition to the fast path (just a quick mask and an extra register for saving the original value) and makes bridgeObjectRetain quite a bit more efficient when implemented correctly to return the exact value it was passed.

The runtime's implementations of swift_retain/release are now also marked as preserve_most so that they can be tail called from the client library. preserve_most is compatible with callers expecting the standard calling convention so this doesn't break any existing clients. Some ugly tricks were needed to prevent the compiler from creating unnecessary stack frames with the new calling convention. Avert your eyes.

To allow back deployment, the runtime now has aliases for these functions called swift_retain_preservemost and swift_release_preservemost. The client library brings weak definitions of these functions that save the extra registers and call through to swift_retain/release. This allows them to work correctly on older runtimes, with a small performance penalty, while still running at full speed on runtimes that have the new preservemost symbols.

Although this is only supported on Darwin at the moment, it shouldn't be too much work to adapt it to other ARM64 targets. We need to ensure the assembly plays nice with the other platforms' assemblers, and make sure the implementation is correct for the non-ObjC-interop case.

rdar://122595871
2025-10-27 12:00:28 -04:00
Allan Shortlidge
0c7d87257e stdlib: Remove an unnecessary 'unsafe' expression in StringBridge.swift.
NFC.
2025-10-24 19:47:15 -07:00
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
Henrik G. Olsson
6f1936ff73 Merge pull request #85059 from hnrklssn/swiftify-import-protocol
[Swiftify] Add _SwiftifyImportProtocol for safe overloads for protocols
2025-10-23 11:37:09 -07:00
Alejandro Alonso
74a09351d2 Merge pull request #85071 from Azoy/fix-keypath-append
[stdlib] Add the intermediate type size for every leaf component
2025-10-22 18:32:02 -07:00
Xiaodi Wu
a9df691c33 [stdlib] Revise InlineArray documentation (#84978)
Update documentation for `InlineArray` to include examples with type
sugar, reword to avoid certain jargon that may be unfamiliar to some
standard library users, and incorporate additional details mostly drawn
from the proposal text.

---------

Co-authored-by: Alex Martini <amartini@apple.com>
2025-10-22 14:18:39 -07:00
Alejandro Alonso
714fd26830 Add the intermediate result for every leaf component 2025-10-22 13:00:55 -07:00
Henrik G. Olsson
48f81c82dd [Swiftify] Add _SwiftifyImportProtocol for safe overloads for protocols
The existing _SwiftifyImport macro is a peer macro, limiting it to only
emitting function wrappers in the same scope as the original function.
Protocols cannot contain function implementations, so these need to be
placed in a separate protocol extension instead. _SwiftifyImportProtocol
is an extension macro rather than a peer macro, to enable this
functionality.

Rather than operating on a single function, like _SwiftifyImport,
_SwiftifyImportProtocol takes information about multiple methods and
creates a single protocol extension with all wrappers in a one-shot
operation.

rdar://144335990
2025-10-21 21:19:54 -07:00
Mads Odgaard
c92e5b47f3 Merge pull request #84574 from madsodgaard/android-availability 2025-10-20 10:40:37 +09:00
Allan Shortlidge
3151bcb1d8 Merge pull request #84943 from tshortli/silgen-swift-runtime-availability
stdlib/SILGen: Emit SIL for Swift runtime availability queries
2025-10-16 15:08:09 -07:00
Stephen Canon
a1e33e1917 Require that initializedCount is >= 0 in unsafeUninitializedCapacity (#84917)
Resolves: rdar://162669759
2025-10-16 09:04:01 -04:00
Allan Shortlidge
085f8ecca9 stdlib/SILGen: Emit SIL for Swift runtime availability queries.
When emitting SIL for `if #available(Swift ..., *)` queries, call the new
`_isSwiftRuntimeVersionAtLeast()` function in the stdlib to check the
condition. To support back deployment, the implementation of
`_isSwiftRuntimeVersionAtLeast()` is `@_alwaysEmitIntoClient` and performs its
comparison against the result of `_SwiftStdlibVersion.current`, which is
pre-existing ABI that the stdlib exposes for querying the Swift runtime
version.

Resolves rdar://162726037.
2025-10-15 22:42:53 -07:00
Eric Miotto
e798e9c3cc CMake: allow to specify a SDK when building a triple for Embedded Swift (#84817)
To achieve this, add a new cache variable
`SWIFT_EMBEDDED_STDLIB_SDKS_FOR_TARGET_TRIPLES` to be set like in the
following examples.
    
```
-DSWIFT_EMBEDDED_STDLIB_SDKS_FOR_TARGET_TRIPLES=aarch64-vendor-os@/usr/local/aarch64-vendor-os-sdk;aaarch-vendor-anotheros@/opt/aarch64-vendor-anotheros-sdk
```
    
We chose to use another setting instead of e.g. folding this into
`SWIFT_EMBEDDED_STDLIB_EXTRA_TARGET_TRIPLES` so it is clear this is opt
in and it does not regress existing configurations that set the SDK
directly (like it's the case for the WASM stdlib).

Addresses rdar://162368529
2025-10-15 06:37:54 -07:00
Tim Kientzle
1d23852f2c Float16 support only on Swift 5.3+ 2025-10-10 17:22:04 -07:00
Tim Kientzle
738873277c Remove availability check for internal float-to-string functions 2025-10-10 14:14:16 -07:00
Tim Kientzle
7b55ac3094 Remove availability restrictions from these internal functions
This is possible because this replaces
* `InlineArray` with `internal _InlineArray`
* `UInt128` with `internal _UInt128`

And the replacements are not availability-restricted.

We don't need to do the same thing with `MutableSpan`
because that back-deploys to Swift 5.0, which is as
far back as the stdlib builds anyway.
2025-10-10 14:07:44 -07:00
Tim Kientzle
b671f3875a Make _UInt128 a little more like UInt128 2025-10-10 14:06:43 -07:00
Tim Kientzle
b69d5fe40c Add Internal version of InlineArray with no availability limitations 2025-10-10 14:04:16 -07:00
Tim Kientzle
f0679b363e Re-apply PR #82750: Reimplement floating-point description implementation in Swift.
This reverts PR #84576, which was a revert of PR #82750
It reverts commit 4ac18aa32e, reversing
changes made to b46eddbabd.
2025-10-07 07:11:57 -07:00