1140 Commits

Author SHA1 Message Date
Kavon Farvardin
54e71d086a OpaqueValues: provide stdlib build option
Should allow testing with preset:
```
extra-cmake-options=-DSWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS=TRUE
```
2025-11-20 14:27:48 -08:00
Eric Miotto
7f32fb0ef6 CMake: allow to build SwiftDirectRuntime when stdlib build is disabled
Addresses rdar://164174444
2025-11-10 06:54:45 -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
Saleem Abdulrasool
9d5b509472 build: default to Android API 28
Set the default value for Android API level to 28 which is the current
recommendation as per the Android workgroup.
2025-11-02 11:05:56 -08:00
Eric Miotto
535f83a527 Pass SDK paths explicitly when building Runtimes in macOS smoketest
As per 7b19531291
CMake 4.0 does not pass `-sdk` to compiler invocations if the user does
not provide `CMAKE_OSX_SYSROOT` -- this in turn causes failures in
linking.

Addresses rdar://163672815
2025-10-29 15:47:49 -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
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
Eric Miotto
72bf8526ab Build Runtime in macOS PR testing
For this to work, add the dependency on Darwin and start building the
Cxx Interop libraries.

Addresses rdar://160774928
2025-10-20 15:34:52 -07:00
Eric Miotto
51e5202ffa Runtimes: build Observation when running macOS smoketest
Piggyback the addition of a flag to specify the path of the
CMakeConfig.h header needed to compile Observation (needed when
consuming SwiftCore through the fine module), and the declaration of
SwiftShims as a dependency.

Addresses rdar://149241712
2025-08-12 12:41:43 -07:00
Eric Miotto
48fd452cd6 macOS smoketest: enable Distributed and Synchronization in runtimes
To make this work:
* expose SwiftCMakeConfig.h from the Core build
system, to support scenarios in which the downstream Distributed build
is leveraging the config files generated by CMake itself.
* adjust how SwiftShims is defined in `FindSwiftCore.cmake`, so that the
shims are found from C++ and that we don't get redefinition errors
when multiple module maps are in the search paths.

Fixes #83449
Addresses rdar://149241603, rdar://157165530
2025-08-08 13:17:19 -07:00
Eric Miotto
4de714fa51 Merge pull request #83464 from edymtt/edymtt/separate-deployment-version-for-tests
Test: allow different deployment target versions for tests on Darwin
2025-08-04 12:13:30 -07:00
Eric Miotto
0869919eca Test: allow different deployment target versions for tests on Darwin
Currently we are using the same versions we use to build compiler and
standard library. This is an unnecessary coupling especially when
testing the generation of backdeployed executables for macOS -- here
we have interest in being able to run the tests on previous OSes, not
the compiler itself.

To support this, add new `--darwin-test-deployment-version-<platform>`
flags to build-script, which by default take the same value as the
matching `--darwin-deployment-version-<platform>` ones.

Addresses rdar://156724078
2025-07-31 08:19:13 -07:00
Anthony Latsis
b09b622078 Merge pull request #82358 from AnthonyLatsis/no-warnings-asserts
[presets] Actually make https://github.com/swiftlang/swift/pull/81284 work
2025-07-31 07:02:11 +01:00
Anthony Latsis
e99f3e887e [presets] Actually make https://github.com/swiftlang/swift/pull/81284 work 2025-07-29 22:02:28 +01:00
Saleem Abdulrasool
07da452a2b build: check and add -fsized-deallocation
We use C++17 for the Swift compiler and IRGen uses the sized
deallocation for releasing memory it creates with over-allocation. That
triggers ASAN warnings due to the mismatched
`operator new`/`operator delete`.
2025-07-29 10:01:26 -07:00
Eric Miotto
17db23bad9 [Runtimes] Enable overlay builds in macOS smoketest
Take the chance to match the flags used in the existing build system,
and adjust code ownership to cover the file I added to track the
experimental flags for the overlays.

Addresses rdar://155882420
2025-07-15 12:59:52 -07:00
Eric Miotto
41e48f867e [CMake] Ensure incremental builds invokes the Runtimes build system...
...when using `--enable-new-runtime-build`

When building changes incrementally the runtime build system is not
invoked -- the configure and build steps generated by `ExternalProject_Add`
are effectively triggered only if the `CMAKE_ARGS` argument changes.
We should instead delegate to the the Runtime build system to figure out
if it needs to regenerate the `build.ninja` file and/or trigger any
rebuild -- this can be done by passing `BUILD_ALWAYS 1` to
`ExternalProject_Add`.

Addresses rdar://155559208
2025-07-10 14:45:02 -07:00
(null)
d6811260a9 Merge commit '665515c781999a81094bbe4f8302a7cb1a6a6b39' into mchiu/freebsd 2025-06-17 15:12:23 -04:00
Hamish Knight
8f4fbe3d9a [cmake] Remove remaining XCODE checks
I missed these when ripping out support for CMake Xcode project
generation.
2025-06-09 22:16:12 +01:00
Alastair Houghton
19dba09424 [Build] Disable Concurrency if the deployment version is too low.
For the new runtime build only (and only when triggered from the old
build system), turn Concurrency off if the deployment target is less
than 10.15.
2025-06-04 17:01:00 +01:00
Alastair Houghton
d5ed335339 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-06-03 15:01:22 +01:00
Michael Chiu
7bbafc599d Merge branch 'main' into mchiu/freebsd 2025-06-02 13:33:18 -04:00
Ben Barham
b0d5e0e8f1 Merge pull request #81697 from bnbarham/use-toolchain-version
Add the distribution tag to `-print-target-info`
2025-05-30 09:51:03 -07:00
Ben Barham
3c098782b4 Add the distribution tag to -print-target-info
Ideally this would also update the `--version` output to be overridden
by `SWIFT_TOOLCHAIN_VERSION`, but unfortunately various tools rely on
the current format (eg. swift-build).
2025-05-28 17:29:17 -07:00
michael-yuji
8738e722bd Merge branch 'main' into mchiu/freebsd 2025-05-28 14:44:11 -07:00
michael-yuji
9a948a9c3b Merge branch 'main' into mchiu/freebsd 2025-05-21 16:29:16 -07:00
Eric Miotto
58a782b98b [Runtimes][CMake] use config mode first in Supplemental build in CI
In this configuration we want to pull dependencies from the current
build, not from the underlying SDK.

Addresses rdar://151784135
2025-05-21 12:20:13 -07:00
Alastair Houghton
28f96e64ab [Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
2025-05-12 12:07:24 +01:00
Justice Adams
2eaa0e93ad [Runtimes][CMake] Supplemental super-build (#81179)
Continue with https://github.com/swiftlang/swift/pull/81006/

Will land the common Cmake modules next before implementing
Synchronization build
2025-04-30 14:23:04 -07:00
Doug Gregor
e49afc8797 Merge pull request #80389 from 3405691582/nobtcfi
Add a build flavor to opt-out of BTCFI on OpenBSD.
2025-04-03 13:29:04 -07:00
3405691582
a341ce5570 Add a build flavor to opt-out of BTCFI on OpenBSD.
To work-around #80059, we need to stop return address signing and
opt-out of BTCFI enforcement via enabling a platform linker option.

We don't want to completely undo the BTCFI work in the rare case that
we later figure out how to properly address the above issue, or allow
users who might want to benefit from BTCFI enforcement and won't use
Concurrency. To do this, condition the existing BTCFI flag enforcement
into a configuration option that defaults to off for now.

Because the new swift-driver needs to "know" whether the frontend is
configured to opt-out or not, and since the new driver communicates with
the frontend via the target info JSON to begin with, we add a field
that emits the build flavor to signal the right behavior.
2025-03-29 10:47:23 -04:00
Evan Wilde
d36b06747a [CMake] StringProcessing: Disable CMake compiler check (#80364)
The CMake compiler checks depend on StringProcessing being implemented.
The old build system may not have rebuilt the module, which will cause
the compiler check to fail. Disable the CMake compiler verification.
2025-03-28 09:05:56 -06:00
Evan Wilde
ecc90933a2 Merge pull request #80328 from etcwilde/ewilde/stdlib-string-processing
[CMake] [Stdlib] Build StringProcessing with new stdlib build
2025-03-27 15:06:47 -07:00
Evan Wilde
7a71441219 [CMake] Enable StringProcessing build
Enable building the regex parser as part of the new runtime build steps.
2025-03-26 17:19:43 -07:00
Max Desiatov
eb1a2960b6 Enable _Concurrency for Embedded Swift with WASI (#79292)
WASI with Embedded Swift provides WASI-libc and libc++ headers necessary to build the `_Concurrency` module for Wasm. We now add `wasm32-unknown-wasip1-wasm` triple to `EMBEDDED_STDLIB_TARGET_TRIPLES` when `SWIFT_WASI_SYSROOT_PATH` is set, which builds the necessary stdlib slice.

---------

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2025-03-26 21:14:05 +00:00
Michael Chiu
7f0f2ac4dd Merge swiftlang#38335 2025-03-14 02:15:15 -04:00
Evan Wilde
eeee0dfddd CMake: option to disable swift in swift
Adding `SWIFT_ENABLE_SWIFT_IN_SWIFT` option to enable or disable the
parts of Swift that require a Swift compiler to build. This is meant for
bootstrapping compilers on new platforms and is not guaranteed to result
in a compiler that will pass the test suite.

This option is on by default so that folks won't forget.
If the option is off, the resulting compiler does not include the Swift
optimizer sources in SwiftCompilerSources nor does the resulting
compiler have swift macro support.
2025-03-06 13:32:49 -08:00
Evan Wilde
abc02192f3 Enable Concurrency Build Testing
Enabling building the concurrency runtimes for build-testing purposes.
2025-02-24 16:31:41 -08:00
Yuta Saito
9d4e5b6911 [build] Add initial support for Emscripten SDK
This patch adds initial support for Emscripten SDK alongside the existing
support for WASI SDK. This is a first step towards building a part of
Swift compiler for Emscripten target (which will be used to build LLDB
with Swift to WebAssembly target).
2025-02-13 00:53:45 +00:00
Hamish Knight
d260bd8ddb [build-script] Remove Xcode generation support
This was quite brittle and has now been superseded
by swift-xcodegen. Remove the CMake/build-script
logic for it, leaving the option behind to inform
users to switch to using xcodegen instead.
2025-02-12 12:19:21 +00:00
Rintaro Ishizaki
6f6742f060 Merge pull request #78622 from rintaro/sanitizer-rdar142516855
[CMake] Globally set sanitizer options for Swift targets
2025-01-28 04:56:44 -08:00
Alastair Houghton
ab8e561583 Merge pull request #78516 from al45tair/eng/PR-124913332
[Backtracing] Implement API per SE-0419
2025-01-28 10:48:33 +00:00
Evan Wilde
489833d957 CMake: Stdlib: Set deployment target
Pass the minimum deployment target into the builds when appropriate.
Fixes the clang warning about mismatched minimum deployment targets
passed via flag and compiler target.
2025-01-26 08:40:51 -08:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00
Alastair Houghton
18496c5626 [Backtracing] Remove support for implicit import of _Backtracing.
We're going to rename the module to Runtime, and it isn't going to be an
implicit import, so we don't need any of this.

rdar://124913332
2025-01-17 10:09:36 +00:00
Rintaro Ishizaki
84a09071cb [CMake] Globally set sanitizer options Swift targets
For C/CXX targets, sanitizer options are set by 'CMAKE_{C|CXX}_FLAGS' in
HandleLLVMComfig.cmake. However for Swift targets, they are set for each
target. That caused some mismatch issues. Instead set them globally for
Swift targets too.

rdar://142516855
2025-01-13 15:54:39 -08:00
Evan Wilde
e0e418f5d3 Enable new stdlib build in macOS smoke tests
Fixed an issue in the convenience wrapper that resulted in building all
copies of the standard library for the default compiler architecture
instead of the desired architecture. To fix this, we pull the desired
target triple and deployment target from the existing variables and pass
that into the CMake invocation.
2025-01-08 16:23:02 -08:00
Eric Miotto
afdfeefabe [CMake] use same generator for compiler and stdlib builds
This will  support configurations where ninja is not the search path,
and will avoid problems that can arise from the stdlib build detecting
and using a different generator.

Addresses rdar://142268599
2025-01-02 07:51:35 -08:00
Henrik G. Olsson
ef9d2b744d Rename pointer bounds (#78210)
* Make pointer bounds non-experimental

* Rename @PointerBounds to @_SwiftifyImport

* Rename filenames containing PointerBounds

* Add _PointerParam exception to stdlib ABI test

* Add _PointerParam to stdlib API changes

* Rename _PointerParam to _SwiftifyInfo
2024-12-20 11:36:01 +01:00