Commit Graph

18042 Commits

Author SHA1 Message Date
Michael Gottesman
e360e8cdfc Merge pull request #85454 from al45tair/fix-windows-pr-testing-2025-11-12
[Observation] Add missing dependencies.
2025-11-12 09:11:40 -08:00
Alastair Houghton
8172fde478 [Observation] We should be importing Android, not Bionic.
Apparently the right module is `Android`, not `Bionic`.  The latter
is the Clang module, with no Swift overlay.
2025-11-12 16:54:10 +00:00
Alastair Houghton
052a1ae2fe [Observation] Add missing dependencies.
There should be additional dependencies listed for Observation,
as it's importing various platform modules.
2025-11-12 13:06:52 +00:00
Jonathan Grynspan
276706eceb Don't abort on Linux if withLockIfAvailable() is called recursively. (#85448)
On all platforms except Linux, calling `withLockIfAvailable()`
recursively just returns `nil`. However, our Linux implementation
chooses to abort the process instead. We don't need this
inconsistent/destructive behaviour and can just return `nil` as we do
elsewhere.
2025-11-11 23:34:12 -08:00
Mohamed Hegazy
86b0b2900a Address GUID type definition errors (#85196)
In https://github.com/swiftlang/swift/pull/84792 we have added
implementation to `Equatable` and `Hashable` there are two issues with
this.
1. Uses of type `GUID` would be emitted in the `swiftinterface` file as
`_GUIDDef._GUID` since it is an external type. but the type name in the
imported header file is `GUID` and not `_GUID`
2. When compiling using `-cxx-interoperability-mode=default`, there are
duplicate definition errors for `==` since the c++ header file defines
the same operator.

Proposed changes:
1. Add a type alias `typealias _GUID = GUID` to address the naming
mismatch in the generated interface file
2. Add conditional definitions of the equatable implementation to avoid
duplicate definitions.

---------

Co-authored-by: Jonathan Grynspan <grynspan@me.com>
2025-11-11 10:13:05 -05:00
Dario Rexin
a604d991d7 Merge pull request #85403 from drexin/wip-ret-rel-perf
[Runtime] Don't use write back in EIC retain/release
2025-11-10 22:24:40 +01:00
Mike Ash
662f8d4613 Merge pull request #85346 from mikeash/fix-extended-existential-copying
[Runtime] Fix copying in extended existential value witnesses.
2025-11-10 12:40:26 -05:00
Dario Rexin
defd3251d7 [Runtime] Don't use write back in EIC retain/release
The write back creates a false dependency between the first and subsequent stores when creating
and the last load and subsequent ops when destroying a stack frame.
2025-11-09 16:18:24 +01: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
f149a8bce4 Merge pull request #85259 from mikeash/task-allocator-disable-option
[Concurrency] Add environment variable for disabling async stack slab allocator.
2025-11-08 07:53:56 -05:00
Mike Ash
7bb9579434 [Runtime] Fix copying in extended existential value witnesses.
Instead of copying the data and the type and witnesses separately, use the size in the value witness table and copy everything at once.

copyTypeInto assumed the type was an ordinary existential. When it was actually an extended existential, it would do an incorrect cast and read part of a pointer as the number of witness tables to copy. This would typically result in a large buffer overflow and crash. At this point we already know the type's size, so we can use that info directly rather than essentially recomputing it.

rdar://163980446
2025-11-07 23:38:09 -05:00
Mike Ash
a62f08e050 [Concurrency] Add environment variable for disabling async stack slab allocator.
Add SWIFT_DEBUG_ENABLE_TASK_SLAB_ALLOCATOR, which is on by default. When turned off, async stack allocations call through to malloc/free. This allows memory debugging tools to be used on async stack allocations.
2025-11-07 22:48:41 -05:00
Mike Ash
05f98b2e99 Merge pull request #85341 from mikeash/fix-complex-equality-executor-bitcast
[Concurrency] Fix asSerialExecutor() for complex equality.
2025-11-07 22:45:09 -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
Michael Gottesman
a302d4e627 Merge pull request #85224 from gottesmm/pr-6cb303a9f5f15489fa44c26d00c70155a6d7cc97
[concurrency] Create builtins for invoking specific concurrency runtime functions.
2025-11-06 20:33:16 -08:00
Alejandro Alonso
aad6cae864 Merge pull request #84314 from valeriyvan/OutputRawSpan
Minor fixes in OutputRawSpan.swift
2025-11-06 17:51:55 -08:00
Anton Korobeynikov
89a7663f1d [AutoDiff] Initial support for differentiation of throwing functions (#82653)
This adds initial support for differentiation of functions that may produce `Error` result. 

Essentially we wrap the pullback into `Optional` and emit a diamond-shape control flow pattern depending on whether the pullback value is available or not. VJP emission was modified to accommodate for this. In addition to this, some additional tricks are required as `try_apply` result is not available in the instruction parent block, it is available in normal successor basic block.

As a result we can now:
- differentiate an active `try_apply` result (that would be produced from `do ... try .. catch` constructions)
- `try_apply` when error result is unreachable (usually `try!` and similar source code constructs)
- Support (some) throwing functions with builtin differentiation operators. stdlib change will follow. Though we cannot support typed throws here (yet)
- Correctly propagate error types during currying around differentiable functions as well as type-checking for `@derivative(of:)` attribute, so we can register custom derivatives for functions producing error result
- Added custom derivative for `Optional.??` operator (note that support here is not yet complete as we cannot differentiate through autoclosures, so `x ?? y` works only if `y` is not active, e.g. a constant value).

Some fixes here and there
2025-11-06 13:12:43 -08:00
Mike Ash
8fbf0e07f3 [Concurrency] Fix asSerialExecutor() for complex equality.
Complex equality is encoded in the low bit of the witness table pointer. We need to mask off the low bits when bitcasting to an `any SerialExecutor`.

rdar://164005854
2025-11-06 13:20:56 -05:00
Michael Gottesman
48b253d111 [concurrency] Use the new builtins. 2025-11-05 20:44:50 -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
John McCall
13937fdb4e Merge pull request #84528 from rjmccall/async-let-runtime-realism
Model async let begin/finish as builtins in SIL
2025-11-05 10:24:46 -08:00
Alex Martini
27a3941cbe Merge pull request #85298 from amartini51/checked_continuation_162971611
Fixes: rdar://162971611
2025-11-04 14:13:30 -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
Alex Martini
903e9c4d7c Refer to checked APIs in CheckedContinuation overview 2025-11-03 14:53:30 -08:00
John McCall
3cfda35b7c Remove the unused swift_asyncLet_{start,end,wait,wait_throwing} runtime
functions.

These were introduced in an early draft implementation of async let, but
never used by a released compiler. They are not used as symbols by any
app binaries. There's no reason to keep carrying them.

While I'm at it, dramatically improve the documentation of the remaining
async let API functions.
2025-11-03 13:45:18 -08:00
Evan Wilde
9d3a975170 Merge pull request #85229 from etcwilde/ewilde/nudge-glibc-modulemap
Modularize signal.h on FreeBSD
2025-11-03 07:25:49 -08:00
Mike Ash
b01436d67b Merge pull request #85222 from mikeash/client-retain-release-no-weak-defs
[Runtime] Avoid weak definitions for client retain/release.
2025-10-31 20:01:45 -04:00
Saleem Abdulrasool
e50f3db4c6 Merge pull request #85223 from compnerd/spawn
Platform: correct `posix_spawn` API nullability
2025-10-31 08:40:10 -07:00
Evan Wilde
ff92f9e5d3 Modularize signal.h on FreeBSD
This nudges the Glibc modulemap just enough to get SwiftPM and later
targets building. Without it, Swift tries to import the signal hander
APIs through CDispatch instead of Glibc. CDispatch shouldn't be directly
imported, so recommending that is nonsensical.

This is not a full solution for all headers, but meant to perturb the
module machinery sufficiently that it pulls signal.h into glibc
correctly.

Works around:
```
Swift-Project/swiftpm/Sources/Basics/Cancellator.swift:79:24:
error: property '__sigaction_u' is not available due to missing import of defining module 'CDispatch' [#MemberImportVisibility]
```
2025-10-30 16:35:07 -07:00
Mike Ash
cfd70d7b6e Merge pull request #85204 from mikeash/tasklocal-no-task-free-fix
[Concurrency] Fix MarkerItem::create to use malloc when there's no task.
2025-10-30 19:26:59 -04:00
Saleem Abdulrasool
04ab94d4cf Platform: correct posix_file_actions_init on Android
Adjust the API annotations to get this imported into Swift properly. The
outer pointer may be `nullptr`, but the inner pointer may not.
2025-10-30 13:49:25 -07:00
Saleem Abdulrasool
39fd9c1c6d Platform: correct posix_spawn API nullability
The `posix_spawn` API is not annotated appropriately for nullability.
Adjust the signature to allow proper usage with older NDKs.
2025-10-30 13:49:13 -07:00
Mike Ash
f3b0dbb2ad [Runtime] Avoid weak definitions for client retain/release.
Instead of using weak definitions of swift_retain_preservemost and swift_release_preservemost, use weak references and explicitly check them for NULL.

Embedded Swift uses weak definitions for its runtime symbols. If swiftCore is able to override the weak definitions of the _preservemost functions, it will also override the Embedded symbols. They are not compatible, so this ends poorly.
2025-10-30 15:11:06 -04:00
Mike Ash
fd6edb86e0 Merge pull request #85208 from mikeash/remove-weak-def-placeholder
[Runtime] Temporarily remove swift_release_preservemost_weak_placeholder.
2025-10-30 14:23:00 -04:00
Mike Ash
e1d20db8a2 [Runtime] Temporarily remove swift_release_preservemost_weak_placeholder.
This is breaking embedded due to its use of weak definitions for embedded versions of the runtime functions. The presence of a weak export in libswiftCore allows any strong symbol in libswiftCore to override a weak symbol elsewhere. Remove while we work out how to reconcile the two.

rdar://163578646
2025-10-29 22:32:43 -04:00
Mike Ash
29245e4ef2 [Concurrency] Fix MarkerItem::create to use malloc when there's no task.
Item::destroy will call free when there's no task, so the allocation needs to match, lest we free something that wasn't malloced and crash.

rdar://162589711
2025-10-29 18:17:33 -04:00
Mike Ash
a9ee814345 [Runtime] Fix the no-retain/release-overrides build.
We need a stub version of CALL_IMPL_SWIFT_REFCOUNT_CC for the !SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE case.
2025-10-29 12:22:10 -04: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
Alejandro Alonso
6c2f04d154 Merge pull request #84367 from valeriyvan/representation
Fix doc comment to make it match code
2025-10-28 16:46:25 -07:00
Valeriy Van
405a267585 Fix doc comment of Span (#84418) 2025-10-28 15:29:24 -07:00
Valeriy Van
0826d47a8b Fix bug in internal func _tryLock in OpenBSDImpl.swift (#84619)
`pthread_mutex_trylock` return `0` on success.

```
NAME
     pthread_mutex_trylock – attempt to lock a mutex without blocking

SYNOPSIS
     #include <pthread.h>

     int
     pthread_mutex_trylock(pthread_mutex_t *mutex);

DESCRIPTION
     The pthread_mutex_trylock() function locks mutex.  If the mutex is already locked,
     pthread_mutex_trylock() will not block waiting for the mutex, but will return an error
     condition.

RETURN VALUES
     If successful, pthread_mutex_trylock() will return zero, otherwise an error number will
     be returned to indicate the error.

ERRORS
     The pthread_mutex_trylock() function will fail if:

     [EINVAL]           The value specified by mutex is invalid.

     [EBUSY]            Mutex is already locked.
```
2025-10-29 00:50:47 +05:30
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