Commit Graph

120 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
Evan Wilde
e88e947272 Merge pull request #62712 from etcwilde/ewilde/zipping-zippers-zip
Add zippering support
2023-01-03 21:45:33 -08:00
Yuta Saito
76981b4234 stdlib: repair 32bit non-Darwin build for TypeLayout
glibc's `uintptr_t` and `uint64_t` are both `unsigned long int`, but `uint32_t`
is `unsigned int`, so BitVector overloads cannot be resoled on 32-bit
platforms by following compilation error:

error: call to member function 'add' is ambiguous
  bv.add(heap_object_abi::SwiftSpareBitsMask);

darwin 32-bit platforms use stdint types defined in SwiftStdint.h, so
they are identical
2022-12-27 06:07:48 +00: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
Saleem Abdulrasool
bf37f358a0 build: disable bytecode layout library without stdlib
This directory is directly added from the top-level CMake which bypasses
the compiler swapping dance.  When cross-compiling or building the
toolchain with a non-clang compiler, the forced flags for the standard
library directory will result in build failures.  Avoid building the
library unless the standard library is being built (which will require
that the compiler-swap occurs).
2022-11-30 18:15:58 -08:00
Eric Miotto
e71eb3322a watchOS: don't target arm64/arm64e for Compatibility50/51 (#62278)
Those architectures were not supported when Swift 5.0/5.1 shipped, so it
makes little sense building those.

Addresses rdar://91128579
2022-11-30 08:41:33 -08:00
Dario Rexin
3cf40ea504 [IRGen] Re-introduce TypeLayout strings (#62059)
* Introduce TypeLayout Strings

Layout strings encode the structure of a type into a byte string that can be
interpreted by a runtime function to achieve a destroy or copy. Rather than
generating ir for a destroy/assignWithCopy/etc, we instead generate a layout
string which encodes enough information for a called runtime function to
perform the operation for us. Value witness functions tend to be quite large,
so this allows us to replace them with a single call instead. This gives us the
option of making a codesize/runtime cost trade off.

* Added Attribute @_GenerateLayoutBytecode

This marks a type definition that should use generic bytecode based
value witnesses rather than generating the standard suite of
value witness functions. This should reduce the codesize of the binary
for a runtime interpretation of the bytecode cost.

* Statically link in implementation

Summary:
This creates a library to store the runtime functions in to deploy to
runtimes that do not implement bytecode layouts. Right now, that is
everything. Once these are added to the runtime itself, it can be used
to deploy to old runtimes.

* Implement Destroy at Runtime Using LayoutStrings

If GenerateLayoutBytecode is enabled, Create a layout string and use it
to call swift_generic_destroy

* Add Resilient type and Archetype Support for BytecodeLayouts

Add Resilient type and Archetype Support to Bytecode Layouts

* Implement Bytecode assign/init with copy/take

Implements swift_generic_initialize and swift_generic_assign to allow copying
types using bytecode based witnesses.

* Add EnumTag Support

* Add IRGen Bytecode Layouts Test

Added a test to ensure layouts are correct and getting generated

* Implement BytecodeLayouts ObjC retain/release

* Fix for Non static alignments in aligned groups

* Disable MultiEnums

MultiEnums currently have some correctness issues with non fixed multienum
types. Disabling them for now then going to attempt a correct implementation in
a follow up patch

* Fixes after merge

* More fixes

* Possible fix for native unowned

* Use TypeInfoeBasedTypeLayoutEntry for all scalars when ForceStructTypeLayouts is disabled

* Remove @_GenerateBytecodeLayout attribute

* Fix typelayout_based_value_witness.swift

Co-authored-by: Gwen Mittertreiner <gwenm@fb.com>
Co-authored-by: Gwen Mittertreiner <gwen.mittertreiner@gmail.com>
2022-11-29 21:05:22 -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