Commit Graph

41 Commits

Author SHA1 Message Date
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
6397e30856 [Concurrency] Eliminate StatusRecordLockRecord.
Move to a recursive lock inline in the Task. This avoids the need to allocate a lock record and simplifies the code somewhat.

Change Task's OpaquePrivateStorage to compute its size at build time based on the sizes of its components, rather than having it be a fixed size. It appears that the fixed size was intended to be part of the ABI, but that didn't happen and we're free to change this size. We need to expand it slightly when using pthread_mutex as the recursive lock, as pthread_mutex is pretty big. Other recursive locks allow it to shrink slightly.

We don't have a recursive mutex in our Threading support code, so add a RecursiveMutex type.

rdar://113898653
2025-03-26 14:52:37 -04:00
Allan Shortlidge
e45f671e5f Compatibility56: Suppress some -Wcast-function-type-mismatch warnings. 2025-01-20 20:25:40 -08:00
Allan Shortlidge
a549d0144e stdlib: Resolve -Wmissing-designated-field-initializers warnings. 2024-11-13 09:51:29 -08:00
Allan Shortlidge
4ab3aae7c5 Gardening: Suppress -Winvalid-offsetof warnings in static asserts.
There cannot be undefined behavior at compile time, so these warnings can be
ignored when `offsetof` is used in a static assert:

```
warning: offset of on non-standard-layout type 'AsyncTask' [-Winvalid-offsetof]
```
2024-10-29 15:52:53 -07:00
Michael Gottesman
cb8e8b505a Fix syntax highlighting by changing how we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH.
The way that we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH freaks out the
syntax highlighting of editors like emacs. It causes the whole file to be
highlighted like it is part of the include string.

To work around this, this patch creates a separate file called
CompatibilityOverrideIncludePath.h that just includes
COMPATIBILITY_OVERRIDE_INCLUDE_PATH. So its syntax highlighting is borked, but
at least in the actual files that contain real code, the syntax highlighting is
restored.
2024-10-01 16:17:16 -07:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Konrad `ktoso` Malawski
dfcf1054dd [Concurrency] Remove _unsafeInheritExecutor from public APIs, use #isolation (#72578) 2024-04-05 03:57:54 -07:00
Eric Miotto
0ff811a8fa Ensure that proper default visibility is set for compatibility archives
This is set to hidden in `stdlib/CMakeLists.txt`, but in some Apple
internal configurations we build the compatibility archives by directly
importing `stdlib/toolchain`, thus skipping these directives and
 causing some symbols to become unexpected visible.

Addresses rdar://73709695
2024-02-29 15:23:41 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Allan Shortlidge
ca555c8aac NFC: Ignore -Wexit-time-destructors warning in TaskAlloc.cpp. 2024-01-19 15:43:35 -08:00
Allan Shortlidge
4eacb4d4cb NFC: Suppress -Wdeprecated-declarations warnings in Mutex.h.
The `is_literal` trait is deprecated in C++17.
2024-01-12 17:42:21 -08:00
Priyansh Prajapat
dd11cc5e13 fix: typo in Task.h from intialized to initialized 2023-10-31 12:59:46 +05:30
Konrad `ktoso` Malawski
cad608eb81 [Discarding] Don't leak retained "first error" task when retaining it 2023-05-24 18:03:28 +02:00
Doug Gregor
fc9d97fe68 Perform OS version checkout without __builtin_available.
`__builtin_available` requires linking compiler-rt, which
is not easier to do within the backward compatibility libraries.
Instead, use an API that's been in the standard library since before
Swift 5.0 for the version check.
2023-05-08 09:41:28 -07:00
Doug Gregor
3a06a51316 Account for back-deployed concurrency library
The back-deployed concurrency library, which is used on OS versions
prior to the introduction of concurrency, has a Swift 5.6-era
concurrency library that supports vouchers.
2023-05-08 07:06:39 -07:00
Doug Gregor
554925d0fe Fix crash when back-deploying concurrency to iOS 15.0/15.1-era OSs
The introduction of the library providing back-deployment fixes for
Swift 5.6 concurrency libraries (and older) introduced a concurrency
crash in the following OS version ranges

  - macOS [12.0, 12.1)
  - iOS [15.0, 15.1)
  - tvOS [15.0, 15.1)
  - watchOS [8.0, 8.2)

Neither older nor newer versions of the listed OSs were affected.

The actual bug involved a miscommunication between the code in the
library that back-deploys fixes (`libswiftCompatibility56.a`) and the
concurrency library in the OS itself. Specifically, the OS versions at
the end of the ranges above introduced voucher support into the
concurrency runtime in the OS (an important feature for performance).
The code in `libswiftCompatibility56.a` that back-ports concurrency fixes
also included the voucher support, which provides a consistent state
for those OS versions and anything newer.

OS versions that predate the introduction of concurrency in the OS are
similarly unaffected, because the embedded
`libswift_Concurrency.dylib` matches that of Swift 5.6, which includes
voucher support.

The OS versions in the affected range include a concurrency library in
the OS that does not manage vouchers. The `libswiftCompatibility56.a`
back-deployed fixes library has code that works on the same data
structures but does manage vouchers, leading to crashes when (say) a
job allocated by the OS version didn't set the "voucher" field, but
the `libswiftCompatibility56.a` tried to free it, essentially a form of
overrelease.

The fix is to teach the voucher-handling code in
`libswiftCompatibility56.a` to first check what version of the OS it
is executing on. If it's in the affected range, all handling of
vouchers is disables so it acts like the concurrency library in the
OS. For both earlier OS versions and later OS versions the
voucher-handler code executes unchanged. This entirely library is
disabled when running on OS versions containing the Swift 5.7
concurrency library (or newer), so those don't need to pay for the
extra check when dealing with vouchers.

Fixes rdar://108837762, rdar://108864311, rdar://108958765.
2023-05-08 03:01:01 -07:00
Rokhini Prabhu
ee98c1c6f4 Remove dead code around the Deadline Task Status record from the
compatibility library

Radar-Id: rdar://problem/88093007
2023-02-14 14:09:45 -08:00
John McCall
74de34c1c2 Round the initial context size of tasks up to 32 on 64-bit <=5.6 runtimes
Fixes issue 63420
2023-02-08 18:32:26 -05:00
Evan Wilde
c67e22e6aa Merge pull request #63192 from etcwilde/ewilde/fix-backdeploy-compat56-crash
Fixes for the compat56 library
2023-02-07 10:22:50 -08:00
Evan Wilde
97806c9c32 Hide more symbols
Apparently `-fvisibility=hidden` is not sufficient to hide some of the
symbols in this library. I've explicitly marked the symbols that were
flagged as being incorrectly exported as "hidden" so hopefully no one
drags them out again.

This is a statically linked library, so the symbols shouldn't need to be
exported for this work work. To ensure that this is the case and that
we're still hitting the overridden API with all of the hidden symbols, I
added a debug log line to the fixed `AsyncTask::waitFuture`
implementation and have verified that we see the compat56 log message
emitted from executables that need the compat56 library.
2023-01-24 10:15:12 -08:00
Evan Wilde
4f7f786ee3 Fix SWIFT_TASK_DEBUG_LOG macro
The threading library changed in the BackDeployConcurrency library
resulting in the `SWIFT_TASK_DEBUG_LOG` macro not compiling. Fixing
that. Also adding the logging pieces to the Compatibility 56 library.
2023-01-24 10:15:12 -08:00
Evan Wilde
7ad89fe394 Replace Task.h with right (5.6) version
I seem to have copied over the wrong version of Task.h. There is an ABI
mismatch in the size of AsyncContext due to the removal of Flags. This
resulted in programs crashing when running against the backdeploy
library and should have crashed when running on the swift 5.6 runtime.

The successResultPointer pointer was set in AsyncTask::waitFuture, but
with the wrong layout. When the pointer was read in the concurrency
backdeploy library, it was at a different offset, and thus contained a
nullptr.

I pulled the AsyncContextKind and AsyncContextFlags from the old
MetadataValues.h into Task.h as they were removed in commit
aca744b211, but are necessary with the
flags included.
2023-01-23 13:34:47 -08:00
Evan Wilde
188c7bd626 Break link against compiler-rt
This patch replaces the platform version check with a dlsym to grab the
symbol we need. If we're on a new enough platform, the symbol should be
available and we can use it. Otherwise, it will be empty and we should
return true. This breaks the link requirement for the platform version
symbol.
2023-01-19 14:37:10 -08:00
Alastair Houghton
21ac6149e3 Don't use tsd_private.h in compatibility libraries for ARMv7k.
If we include this file, it generates inline assembly, which would be fine
except that when apps are being built with bitcode, that isn't allowed.

rdar://103274667
2023-01-19 16:48:42 +00:00
Konrad `ktoso` Malawski
6991319a3d [Concurrency] uncomment isCancelled override decl (#63007) 2023-01-16 09:43:16 +09:00
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
Evan Wilde
6ab641e95d Add zippering support
Upstream build system zippering support.

Setting the `SWIFT_ENABLE_MACCATALYST` flag will build the compatibility
libraries with zippering enabled.

Note that AppleClang and LLVM Clang use different flags to write
zippered files. The Swift stdlib build doesn't know what clang we're
using, so we can't ask it for the compiler ID to determine which whether
we're using AppleClang or LLVM clang, hence the nasty `execute_process`
trick to figure out whether the compiler that's actually compiling the
stdlib knows about the flag or not.
2022-12-20 11:05:26 -08:00
Evan Wilde
801e090507 Add note to stop trying to fix compat tsan syms
I keep trying to fix the tsan symbol dance, avoiding duplicate symbols
for initializing the tsan acquire and release function pointers. The
idea this time was to expose an API from the runtime to return the
function pointers for the compatibility library. This won't work because
the compatibility library would need to backdeploy to a version of the
library that doesn't have those symbols, so it would fail to link.

Now, if I really wanted to increment the counter again, an idea might be
to pull the swift_tsan_acquire/swift_tsan_release symbols out of the
Swift concurrency runtime and make them into a toolchain static library
which would get linked by the driver when doing an ASAN build. The
sanitizer libraries are already shipped like this, so it wouldn't be
too weird to do this.
2022-11-08 17:10:32 -08:00
John McCall
7f737d235d Synchronize with cancellation when removing a task from a task group
We were detaching the child by just modifying the list, but the cancellation path was assuming that that would not be done without holding the task status lock.

This patch just fixes the current runtime; the back-deployment side is complicated.

Fixes rdar://88398824
2022-10-29 00:10:28 -04:00
Evan Wilde
5b6c8147ec Merge pull request #61643 from etcwilde/ewilde/backdeploy56-remove-unused
Remove unused functions from 5.6 backdeploy
2022-10-20 09:23:06 -07:00
Evan Wilde
543c6a6bdc Remove unused functions from 5.6 backdeploy
Removing
 - swift_task_localValueGetImpl
 - swift_task_localValuePopImpl
 - swift_task_localsCopyToImpl
 - swift_task_reportIllegalTaskLocalBindingWithinWithTaskGroupImpl

These static functions are not used or exported from the 5.6 backdeploy
library.
2022-10-19 22:59:09 -07:00
Evan Wilde
c329bf6c4a [Backdeploy5.6] Hide task_future_wait[_throwing]
Symbols from the backdeploy libraries shouldn't be exported by dylibs.

Also found an undefined declaration (asyncMainDrainQueue) and a
duplicate declaration for `swift_task_getCurrent`, so those were cleaned
up.
2022-10-12 16:23:40 -07:00
Evan Wilde
64b19f7f45 Backdeploy task_wait_future fix to Swift 5.6 (#61254)
* Backdeploy swift_task_future_wait

This patch adds the implementation for `swift_task_future_wait`
entrypoint to the backdeploy library.

This involves pulling in `AsyncTask::waitFuture`, which relies on a fair
bit.

Please note, this pulls in the `StaticMutex` implementation from Swift
5.6. There are some challenges here. The concurrency version of the
`StaticMutex` involves a fairly nasty set of ODR violations in the
normal setup. See `public/Concurrency/Mutex.cpp`, which includes the
Mutex implementations cpp files directly, while defining a single macro
to replace the implementation of swift::fatalError with
swift_concurrency_fatalError. We only need the concurrency mutex (at
least for now), so I have hard-coded the `swift_concurrency_fatalError`
version into this library. If we should need the other implementation,
we are forced to include ODR-related undefined behavior.

We need symbols from C++, so I've added an implicit linker flag whenever
the static library is used, namely, it passes `-lc++` to the linker.
Since we only backdeploy on Apple platforms, this should be fine.

Some of the platform runtimes we need to backdeploy to have the
enter/exitThreadLocalContext functions defined, while others don't. We
define our own backdeploy56 shim function that dlsym's the function
pointer for these symbols if we have exclusivity checking available.
Otherwise, it doesn't do anything. If concurrency exclusivity checking
is available, we'll use it, otherwise we wont'.

The same dlsym check is done for `swift_task_escalate`. Not all
platforms we need to backdeploy to have a concurrency runtime. The
symbols that do need to use pieces of the concurrency runtime should not
be getting hit when deploying to systems that don't have concurrency. In
the event that you've gotten around the language blocking you from
calling these symbols and you've managed to call concurrency pieces
without using concurrency, we'll abort because something is seriously
wrong.

* Backdeploy swift_task_future_wait_throwing

Drop the remaining pieces in for adding
`swift_task_future_wait_throwing`.

* Apply task_wait_future fix

Actually apply the fix from ef80a315f8.

This deviates slightly from the original patch.

AsyncTask::PrivateStorage::_Status() does not exist in the Swift 5.6
library. Instead I am using `AsyncTask::PrivateStorage::Status`.

* Workaround missing compiler-rt linking

Working around the missing link against compiler-rt in these test.
They are a bit brittle as if anything in them uses compiler-rt, they
will start failing. The backdeploy 5.6 library uses some symbols from
compiler-rt, thus causes them to fail to link.

Disabling the runtime compatibility version checking to avoid these
symbols. This should be fine for the MicroStdlib test, but we should fix
'%target-ld' to handle this better in the future.
rdar://100868842
2022-10-07 09:36:17 -07:00
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +01:00
Evan Wilde
e237d09010 [Swift 5.6 compat] use compat threading library 2022-09-08 13:23:33 -07:00
Evan Wilde
f7810ada24 Revert "Merge pull request #60459 from etcwilde/ewilde/revert-backdeploy56"
This reverts commit 93387f8a0b, reversing
changes made to 88304c327f.
2022-09-01 10:07:44 -07:00
Evan Wilde
15b3659484 Revert "Merge pull request #60368 from etcwilde/ewilde/backdeploy56"
This reverts commit a3941bf215, reversing
changes made to b39302a585.
2022-08-09 07:16:02 -07:00
Evan Wilde
09f39b8112 Removing task_future_wait impls
This patch removes the implementation implementations and just calls the
original symbol without the fixes. This allows the library to build and
for binaries to link against it without breaking anything with missing
symbols.
2022-08-02 15:59:53 -07:00
Evan Wilde
2ac2249801 Stubbing out backdeploy library
This patch gets everything to the point of building the library, but it
doesn't run yet since I have missing symbols.

Unlike previous compatibility libraries and the concurrency
compatibility library, I'm organizing the headers a bit more. This is
because we're merging the two libraries into one. They share some common
header names, and while I could rename them for namespacing purposes,
it's easier to just use a directory structure for this.

The `include/Runtime` and corresponding `Runtime/` directories are for
backdeployed changes to the stdlib itself.

The `include/Concurrency` and corresponding `Concurrency/` directories
are for backdeployed changes to the concurrency runtimes.
2022-08-02 14:47:26 -07:00