Commit Graph

7908 Commits

Author SHA1 Message Date
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
Slava Pestov
0cfb11b1f5 Merge pull request #84690 from valeriyvan/minor-typos
Fix some typos in doc comments
2025-10-05 15:10:59 -04:00
Valeriy Van
c53d71bb2a Fix typos 2025-10-04 12:53:44 +02:00
Alex Martini
94de6427b6 Merge pull request #84477 from amartini51/docs_cleanup
Fixes: rdar://115730302
Fixes: rdar://158722889
2025-10-03 11:56:09 -07:00
Alejandro Alonso
6017659337 Merge pull request #83161 from Azoy/keypath-overaligned-arguments
[stdlib] Handle arguments with alignment larger than a word in KeyPath
2025-10-02 07:25:55 -07:00
Alejandro Alonso
8fdde43ff8 Merge pull request #84623 from valeriyvan/UTF8SpanIterators1
Address 3 TODOs adding examples to UTF8SpanIterators
2025-10-01 15:48:51 -07:00
Valeriy Van
593188f051 Add examples to UTF8SpanIterators 2025-10-01 18:30:37 +02:00
Alejandro Alonso
7502c76228 Merge pull request #84563 from swiftlang/fix/move_subranges_documentation
Fix moveSubranges documentation issue
2025-09-30 10:18:50 -06:00
Tim Kientzle
7d85d75f78 Revert "Merge pull request #82750 from tbkka/tbkka-swift-floatingpointtostring"
This reverts commit 54627fb49b, reversing
changes made to dda4608a84.
2025-09-29 15:13:19 -07:00
Guillaume Lessard
e0a703b3df Merge pull request #84369 from valeriyvan/MutableSpan 2025-09-29 10:39:24 -07:00
Tim Kientzle
54627fb49b Merge pull request #82750 from tbkka/tbkka-swift-floatingpointtostring
Reimplement floating-point description implementation in Swift.
2025-09-29 07:55:25 -07:00
Ebuka Ezike
dda4608a84 [Debug] Renable DebugDescription macro on linux (#84485)
(cherry picked from commit b2fda7ffe6)

<!--
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-09-29 15:32:17 +01:00
Anthony Latsis
1281f669b7 Merge pull request #84293 from minguking/main
[stdlib] Fix typo in doc comment: change "One" to "Once"
2025-09-29 14:12:32 +01:00
Kyle
43cf2368e7 Fix moveSubranges documentation issue 2025-09-29 19:17:23 +08:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Alejandro Alonso
ac376e97f2 Don't use SIMD because it may not exist 2025-09-24 09:55:12 -07:00