Commit Graph

21434 Commits

Author SHA1 Message Date
eeckstein
89bdb311ab Merge pull request #81780 from eeckstein/optimize-enum-comparison
Optimize enum comparisons
2025-05-28 07:01:29 +02:00
Konrad `ktoso` Malawski
31b6ae2fcf Merge pull request #80984 from ktoso/task-names-update
[Concurrency][SE-review update] Task names update
2025-05-28 06:23:49 +09:00
Stephen Canon
592d72bba9 Concrete SIMD.init(repeating:) and SIMD.init(lowHalf:highHalf:) optimizations (#81766)
WIP to add more overloads to optimize SIMD codegen on concrete types.
Here we do:

- init(repeating:)
- init(lowHalf:highHalf:)

These are always inlined, even in debug, since LLVM knows how to lower
them to one or two instructions on the targets that we care about.
2025-05-27 15:15:13 -04:00
Erik Eckstein
cac594fb86 Optimizer: peephole optimization for raw-value enum comparsions
Optimize (the very inefficient) RawRepresentable comparison function call to a simple compare of enum tags.
For example,
```
  enum E: String {
    case  a, b, c
  }
```
is compared by getting the raw values of both operands and doing a string compare.
This peephole optimizations replaces the call to such a comparison function with a direct compare of the enum tags, which boils down to a single integer comparison instruction.

rdar://151788987
2025-05-27 12:11:03 +02:00
Ian Anderson
0027779029 Merge pull request #81726 from ian-twilightcoder/remove_darwin_overlay
[CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
2025-05-26 12:19:28 -07:00
Daniil Kovalev
1e403ecf5c [AutoDiff] Support custom derivatives for @_alwaysEmitIntoClient functions (#78908)
Consider an `@_alwaysEmitIntoClient` function and a custom derivative
defined
for it. Previously, such a combination resulted different errors under
different
circumstances.

Sometimes, there were linker errors due to missing derivative function
symbol -
these occurred when we tried to find the derivative in a module, while
it
should have been emitted into client's code (and it did not happen).

Sometimes, there were SIL verification failures like this:

```
SIL verification failed: internal/private function cannot be serialized or serializable: !F->isAnySerialized() || embedded
```

Linkage and serialization options for the derivative were not handled
properly,
and, instead of PublicNonABI linkage, we had Private one which is
unsupported
for serialization - but we need to serialize `@_alwaysEmitIntoClient`
functions
so the client's code is able to see them.

This patch resolves the issue and adds proper handling of custom
derivatives
of `@_alwaysEmitIntoClient` functions. Note that either both the
function and
its custom derivative or none of them should have
`@_alwaysEmitIntoClient`
attribute, mismatch in this attribute is not supported.

The following cases are handled (assume that in each case client's code
uses
the derivative).

1. Both the function and its derivative are defined in a single file in
   one module.

2. Both the function and its derivative are defined in different files
which
   are compiled to a single module.

3. The function is defined in one module, its derivative is defined in
another
   module.

4. The function and the derivative are defined as members of a protocol
extension in two separate modules - one for the function and one for the
   derivative. A struct conforming the protocol is defined in the third
   module.

5. The function and the derivative are defined as members of a struct
extension in two separate modules - one for the function and one for the
   derivative.

The changes allow to define derivatives for methods of `SIMD`.

Fixes #54445
<!--
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-05-25 09:47:15 -04:00
Ian Anderson
15345ef2d5 [CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
The SDK overlays have been provided in the Apple SDKs for many years, and the interface and implementation has diverged in more recent years such that trying to build the Swift version no longer works. Remove all of the dead code.

rdar://151889154
2025-05-23 23:38:08 -07:00
Konrad 'ktoso' Malawski
97a4904c1f [Concurrency] Correct the signing of priority escalation handler 2025-05-23 17:02:19 -07:00
Henrik G. Olsson
262a53f599 [Swiftify] Update availability for CxxSpan<->Span, fix lifetimebound on parameters with reference type (#81634)
Update availability for CxxSpan<->Span, fix lifetimebound on parameters
with reference type

Because swift-ide-test doesn't care about typechecking,
std-span-interface.swift passed despite containing 2 separate errors.
This updates the test file to properly exercise the entire compilation
pipeline for the macro expansions, by running swift-frontend
-emit-module and calling each macro expansion.

The first issue was that CxxSpan initializers taking [Mutable]Span still
had their availability set to Swift 6.2+, even after back-deploying
caused [Mutable]Span to have availability back to Swift 5.0. Since
_SwiftifyImport expansions copy the availbility of Span, this resulted
in the macro expansions calling unavailable initializers. Interestingly
enough, this manifested itself in the form of a tripped assert in SIL
verification, because although we do now typecheck the expansions from
_SwiftifyImport, the compilation can still keep going after
`shouldEmitFunctionBody` returns false: the macro expansion declaration
is still there, but is now missing its definition, despite not being
external.

The second issue was when parameters with C++ reference types were
annotated with `[[clang::lifetimebound]]`. For parameters with a type
that is `Escapable`, this is normally done using `@lifetime(borrow
foo)`. However C++ reference parameters are imported as `inout`, which
requires the `@lifetime(&foo)` syntax.

rdar://151493400
rdar://151678415
2025-05-22 15:36:19 -07:00
Evan Wilde
c99295756f Merge pull request #81366 from etcwilde/ewilde/observe-freebsd-pthread-nullability
[FreeBSD]: Optional observation pthread primitives
2025-05-22 09:27:03 -07:00
Alastair Houghton
3305e89ff9 Merge pull request #81639 from swiftlang/revert-81472-eng/PR-151147606
Revert "[Concurrency] Add underscore prefixes for not yet official API."
2025-05-22 15:36:52 +01:00
Karoy Lorentey
a7830d754a Merge pull request #80870 from lorentey/stdlib-version-6.3
[stdlib][runtime] Establish Swift Stdlib/runtime version 6.3
2025-05-21 17:48:22 -07:00
Pavel Yaskevich
a64984af45 Merge pull request #81572 from xedin/adopt-inheritActorContextAlways-in-Task-APIs
[stdlib] Adopt `@_inheritActorContext(always)` on `Task.immediate`
2025-05-20 09:05:35 -07:00
Alastair Houghton
28732f4a8b Revert "[Concurrency] Add underscore prefixes for not yet official API." 2025-05-20 15:44:26 +01:00
finagolfin
998a6769a7 Merge pull request #81601 from finagolfin/droid
Fix standalone stdlib build on Unix and make some Android CI tweaks
2025-05-20 12:13:38 +05:30
Pavel Yaskevich
0598b8c9f4 [stdlib] Task.immediate annotate operation parameter with @_implicitSelfCapture
Since the "operation" inherits the context of the actor it should
also be possible to reference its members without explicit use of
`self.`.
2025-05-19 18:01:23 -07:00
Pavel Yaskevich
8c05636e28 [stdlib] Concurrency: Add @_alwaysEmitIntoClient to add Task.*immediate* 2025-05-19 18:01:07 -07:00
Mike Ash
dfc964791b Merge pull request #81562 from mikeash/error-object-weak-reference
[Runtime] Allow weak references to ErrorObjects.
2025-05-19 13:33:59 -04:00
Alastair Houghton
54f0bf2d34 Merge pull request #81527 from al45tair/fix-static-sdk-build
[Cxx] Build the C++ interop support library for the Static SDK for Linux
2025-05-19 11:40:24 +01:00
Finagolfin
432de55622 [stdlib][cmake] Disable checking for bootstrapping if the host tools aren't being built 2025-05-19 14:39:15 +05:30
Allan Shortlidge
742a96da86 Merge pull request #81593 from tshortli/strict-memory-safety-warnings
stdlib: Resolve `-strict-memory-safety` warnings
2025-05-18 22:19:31 -07:00
Saleem Abdulrasool
c4b0e97c11 Merge pull request #81589 from compnerd/autolink
CommandLineSupport: add a directive for autolinking on Windows
2025-05-18 17:06:15 -07:00
Allan Shortlidge
f8fb99320a Embedded: Suppress spurious unused result warnings.
The results of `swift_retain(object:)` and `swift_bridgeObjectRetain(object:)`
should be discardable since it's typcial to not need the pointer returned from
these calls. Suppresses unused result warnings that were generated previously.
2025-05-18 10:40:13 -07:00
Allan Shortlidge
58af3ce541 CompatbilitySpan: Add a missing @unsafe.
The missing attribute was causing "no unsafe expressions" warnings elsewhere
when building the CompatibilitySpan library.
2025-05-18 10:37:44 -07:00
Allan Shortlidge
a85caaf296 Concurrency: Address new -strict-memory-safety warnings. 2025-05-18 10:37:19 -07:00
Saleem Abdulrasool
3b968f699a CommandLineSupport: add a directive for autolinking on Windows
We use functions from Shell32.Lib. Ensure that we indicate the
autolinking to the linker. This aides when building with a static
runtime to avoid having to specify the additional library dependency for
clients that are attempting to link against the runtime. This is
particularly important for the CMake compiler check where we would need
to list Shell32 as a required link library.
2025-05-17 18:31:31 -07:00
Karoy Lorentey
02adf95cfb Merge pull request #78799 from lorentey/note-cas-loops
[doc] Atomic.add, .subtract: Add note on atomic codegen
2025-05-16 19:05:10 -07:00
Karoy Lorentey
d98002318d [stdlib][runtime] Establish Swift Stdlib/runtime version 6.3 2025-05-16 19:01:32 -07:00
Pavel Yaskevich
c3c1b4fca0 [stdlib] Adopt @_inheritActorContext(always) on Task.immediate
This change aligns implementation with the current SE-0472 proposal.
2025-05-16 14:27:46 -07:00
Mike Ash
aea9c0c65a [Runtime] Allow weak references to ErrorObjects.
When ObjC interop is not available, Error values are represented in ErrorObject boxes. These are full HeapObjects, but unowned refcounting ops asserted that the metadata was class metadata. This assert would be hit when destroying an ErrorObject that was weakly referenced. Expand the asserts to accept ErrorObject metadata as well.

rdar://150214921
2025-05-16 14:01:29 -04:00
David Smith
e795eb0d13 Cache the last ObjC bridging conformance we looked up (#81545)
Fixes rdar://151475392
2025-05-16 11:00:13 -07:00
Alastair Houghton
7f97e8d10b Merge pull request #81472 from al45tair/eng/PR-151147606
[Concurrency] Add underscore prefixes for not yet official API.
2025-05-15 18:39:21 +01:00
Alastair Houghton
b2f0d92eaa [Cxx] Build the C++ interop support library for the Static SDK for Linux.
We need the C++ interop support library to make the build work, as
the Runtime module uses C++ interop.

(Also, we should build it, because some user programs might want to
use C++ interop.)

rdar://147201087
2025-05-15 14:30:12 +01:00
Saleem Abdulrasool
0af5839320 Merge pull request #81477 from compnerd/conwarn
Concurrency: silence warning on Windows
2025-05-14 09:45:08 -07:00
Alastair Houghton
c0ccdffeb7 [Concurrency] Add underscore prefixes for not yet official API.
Custom main and global executors work hasn't passed Swift Evolution yet,
so we need to avoid leaking it as API until it does.

To that end, underscore all the things.

rdar://151147606
2025-05-14 11:57:06 +01:00
Saleem Abdulrasool
f411fcd388 CommandLineSupport: prefer _strdup over strdup
This silences a warning on Windows as `strdup` is considered deprecated
in favour of the POSIX compliant `_strdup` spelling.
2025-05-13 13:21:01 -07:00
Saleem Abdulrasool
cab1f40218 Concurrency: silence warning on Windows
Prefer `strncpy_s` over `strncpy` which triggers a warning. This
function ensures that the copied string is null-terminated if the string
fits or simply returns an empty string (`\0`) if the string does not
fit. Prefer to use `_TRUNCATE` to copy as much of the name as fits and
ensure that it is null-terminated.
2025-05-13 09:48:33 -07:00
eeckstein
66e07f04ac Merge pull request #81441 from eeckstein/vector_base_addr
SIL: introduce the `vector_base_addr` instruction and use it in `InlineArray`
2025-05-13 06:52:42 +02:00
Alejandro Alonso
9e24563bb7 Merge pull request #81365 from Azoy/my-existentials
[AST & Runtime] Correctly mangle extended existentials with inverse requirements
2025-05-12 13:21:07 -07:00
Alastair Houghton
485b8f6888 Merge pull request #81446 from al45tair/eng/PR-150531873
[Concurrency] Remove deprecation attribute for now.
2025-05-12 20:02:03 +01:00
Erik Eckstein
e3f25d710d stdlib: make InlineArray work with the new vector_base_addr instruction
Don't unsafe-cast from the InlineArray struct itself, but from `_storage` which is the actual array buffer.
This also requires making `_storage` a var.
2025-05-12 19:25:12 +02:00
Egor Zhdan
ede6e468e0 Merge pull request #81408 from swiftlang/egorzhdan/do-not-install-swiftmodules
[cxx-interop] Do not install binary `.swiftmodule` files for the overlays
2025-05-12 17:29:52 +01:00
Pavel Yaskevich
3854e61c49 Merge pull request #81428 from xedin/rename-some-task-apis
[stdlib] SE-0472: Rename `Task` and`*TaskGroup` APIs to match the pro…
2025-05-12 09:13:11 -07:00
Alastair Houghton
c6d1969afc [Concurrency] Remove deprecation attribute for now.
This deprecation attribute is possibly a little premature.

rdar://150531873
2025-05-12 15:35:45 +01:00
Egor Zhdan
16b280862a [cxx-interop] Do not install binary .swiftmodule files for the overlays
This fixes a deserialization failure in the compiler that occurred while loading the CxxStdlib overlay module:
```
Cross-reference to module 'Swift'
... Optional
... some
... with type <τ_0_0 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable> (Optional<τ_0_0>.Type) -> (τ_0_0) -> Optional<τ_0_0>
```

This was happening because the overlays were built against a different version of the Swift stdlib than is being used. The compiler is able to rebuild the Cxx and CxxStdlib modules from their textual interfaces. Let's use that feature unconditionally in production toolchains to avoid this kind of binary incompatibilities.

rdar://150416863
2025-05-10 22:55:06 +01:00
Pavel Yaskevich
99d810aa7d [stdlib] Temporarily bring back Task.startSynchronously as deprecated 2025-05-09 23:59:36 -07:00
Pavel Yaskevich
001eab867d [stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate`
`*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`
2025-05-09 23:59:30 -07:00
Slava Pestov
10ca7f6614 Merge pull request #81299 from slavapestov/remote-mirrors-meet-packs
RemoteInspection: Support for parameter packs
2025-05-09 22:28:31 -04:00
Slava Pestov
70b413dc56 RemoteInspection: Support for parameter packs 2025-05-09 14:49:37 -04:00
Evan Wilde
1a546a9ccb [FreeBSD]: Optional observation pthread primitives
The pthread APIs on FreeBSD do not include nullability APIs so the
pthread mutex APIs are imported as pointers to optional values.
Other platforms include nullability APIs and import the pthread APIs as
pointers to the mutex. Splitting the locking primitive type based on the
OS.

Fixes: rdar://150880976
2025-05-09 10:08:35 -07:00