Commit Graph

136 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
Eric Miotto
988531cc3b CMake: ensure we can build compatibility libraries with macOS 14.0 SDK
In particular, fix the Apple Silicon benchmark job by do not
propagating the flag added in #83399.

Addresses rdar://157188603
2025-07-31 13:12:54 -07:00
Guillaume Lessard
31235db588 [stdlib] add OutputSpan to backdeployment library 2025-07-16 17:15:28 -07:00
Doug Gregor
3594ea12fc Fix minimum deployment versions for Span back-deployment dylib 2025-07-07 22:22:00 -07:00
Valeriy Van
d22a24744f Fix bug making ~0x1 mask in stdlib/toolchain/CompatibilityDynamicReplacements/DynamicReplaceable.cpp (#82264)
Solves #62665.
2025-06-17 09:03:16 -04: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
Slava Pestov
4c8c3aab4f CompatibilitySpan: Add MutableRawSpan.swift, MutableSpan.swift 2025-04-07 21:32:44 -04:00
Slava Pestov
1d25522ceb cmake: Add NO_SWIFTMODULE option to add_swift_target_library() 2025-04-07 21:32:14 -04:00
Mike Ash
ecdcb82b97 Merge pull request #80316 from mikeash/lock-record-begone
[Concurrency] Eliminate StatusRecordLockRecord.
2025-03-28 17:18:40 -04:00
Slava Pestov
51face17da Merge pull request #80282 from Steelskin/fabrice/define-swift-stdlib-build-types-missing
Disable CompatibilitySpans outside of stdlib build
2025-03-26 20:08:09 -04: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
Mike Ash
ed3e6356ec Merge pull request #80243 from mikeash/ignore-constructor-warnings
[Runtime] Ignore some global constructor warnings.
2025-03-25 17:42:16 -04:00
Fabrice de Gans
ec503e7ee7 Disable CompatibilitySpans outside of stdlib build 2025-03-25 12:49:03 -07:00
Fabrice de Gans
9505d55c96 Build CompatibilitySpan as STATIC for build tools
In some cases, like when building the Swift toolchain build tools,
`SWIFT_STDLIB_LIBRARY_BUILD_TYPES` is not defined. This causes a
configuration failure when the `CompatibilitySpan` library is being
added.

This commit sets a default value of `STATIC` to work around this
problem.
2025-03-25 12:06:11 -07:00
Slava Pestov
5c1b20d2bc stdlib: Build libswiftCompatibilitySpan.dylib compatibility shim
This dynamic library contains a copy of the standard library's
exported entry points for the Span and RawSpan types. This will
allow backward deployment of code that uses those new types.
2025-03-24 17:56:44 -04:00
Mike Ash
6a383b270e [Runtime] Ignore some global constructor warnings.
We have a few constructor functions that aren't wrapped in SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN/SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END and which have started to produce warnings in a new clang version. Explicitly allow these constructors by adding those.

rdar://147703947
2025-03-24 12:43:03 -04:00
Mike Ash
e4e2b23a71 [Compatibility50] Silence warning about taking the address of objc_setHook_getClass.
Add a & so the compiler doesn't think it always evaluates to true.

rdar://144465537
2025-02-11 17:11:12 -05: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
Alastair Houghton
0302944988 [Build] Add compatibility library deps to target executables.
We need to make sure that we add the compatibility libraries as
dependencies for target executables, otherwise we can end up with
a race condition in the build where the build will fail if the
compatibility libraries haven't been built by the time e.g.
`swift-backtrace` is linked.

rdar://128197532
2024-05-16 15:46:09 +01:00
Daniel Rodríguez Troitiño
a7ff8159f1 [cmake] Check correctly for different flags. Don't check twice -Wall (#73144)
check_cxx_compiler_flag caches its results for the same variable, since
all the flags were using the same variable, only the first check was
done, and the rest of the flags were just using the result of the first
flag.

Make each of the check_cxx_compiler_flag use a different variable (by
interpolating the flag name) and reorder the list of compiler flags to
check. -Wall was added twice, and in the case of MSVC, the equivalent
was added last.

It doesn't really seem to affect a lot of things.
2024-04-22 08:40:57 -07: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
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Konrad `ktoso` Malawski
cad608eb81 [Discarding] Don't leak retained "first error" task when retaining it 2023-05-24 18:03:28 +02:00
Slava Pestov
9c195631ea Fix assert build of CompatibilityPacks shim 2023-05-19 15:32:56 -04:00
Slava Pestov
c2338aa0f6 Backward deployment shim for swift_allocate{Metadata,WitnessTable}Pack() 2023-05-12 15:44:12 -04: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
Rose
8d06ca7f4e Prefer std::copy_n over std::copy where appropriate.
std::copy_n saves us from having to do the addition manually.
2023-03-16 16:25:51 -04:00
Dario Rexin
96d988a431 [Runtime] Move bytecode layout handling into runtime (#63901)
rdar://105904548
2023-02-25 10:18:45 -08:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08: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