Commit Graph

21434 Commits

Author SHA1 Message Date
Alex Lorenz
b3ec0ff245 [stdlib] fix android build
ptrauth isn't available when stdlib is built with NDK's clang
2024-12-15 21:33:33 -08:00
David Smith
b71f768128 Add an overload of append(contentsOf:) on Array that takes a Collection instead of a Sequence, and use it to accelerate wCSIA-compatible Sequences (#77487) 2024-12-13 23:11:35 -08:00
Konrad `ktoso` Malawski
3ea940e304 Merge pull request #77730 from nickolas-pohilets/mpokhylets/isolated-deinit-version 2024-12-14 11:00:31 +09:00
Saleem Abdulrasool
ef3f2853c1 Merge pull request #78168 from compnerd/silence
runtime: silence unhelpful warning
2024-12-13 15:22:33 -08:00
Saleem Abdulrasool
bf337a9c63 Merge pull request #78142 from compnerd/variable-environment
runtime: re-order environment variable lookup
2024-12-13 13:40:25 -08:00
Gábor Horváth
8398e693e7 Merge pull request #77700 from swiftlang/gaborh/span-conversion
[cxx-interop] Explicit conversions between Swift and C++ spans
2024-12-13 19:54:27 +00:00
Alex Lorenz
978e72cb6e Merge pull request #78161 from swiftlang/hyp/hash-bless-you-and-merry-xmas
[cxx-interop][stdlib] windows - use new hash inline functions like other platforms
2024-12-13 11:00:39 -08:00
Saleem Abdulrasool
edbdd06d71 runtime: silence unhelpful warning
This TODO has existed since the introduction of the Windows platform and
has not been addressed. The implementation at this point is well tested
in practice. Clean up the warning message and style and remove the
warning.
2024-12-13 09:27:41 -08:00
Gabor Horvath
b6cc118f71 [cxx-interop] Explicit conversions between Swift and C++ spans
A first step towards creating safe overloads for C++ APIs using span
(rdar://139074571).

Note that we need to mark span as owned because it the libc++
implementation was mistakenly recognized as owned and might now rely on
span methods like `data` being renamed as `__dataUnsafe`. We will change
it under a new interop version. But for the time being, we want
consistent behavior across stdlib versions.
2024-12-13 16:01:02 +00:00
Alex Lorenz
9c44e01e07 [cxx-interop][stdlib] windows - use new hash inline functions like other platforms
The PR https://github.com/swiftlang/swift/pull/77857 added windows-specific workaround for https://github.com/swiftlang/swift/issues/77856, that happened after https://github.com/swiftlang/swift/pull/77843. Unfortunately this caused a new issue on windows - https://github.com/swiftlang/swift/issues/78119. It looks like windows is suffering from a similar serialization issue as libstdc++, although its even more complex as the callAsFunction is not only a derived function from a base class, the base class although has a static call operator. In any case, the libstdc++ callAsFunction deserialization fix should align with the static operator () deserialization too, so for now make windows use the same workaround as other platforms to avoid the deserialization crash (77856).

This change was tested on i686 windows too, ensuring that IR verifier crash no longer happens
2024-12-12 23:17:17 -08:00
Kuba (Brecka) Mracek
7946bf7840 Merge pull request #78147 from kubamracek/embedded-cxxshim
[embedded] Include and use cxxshims in the embedded/ resource dir
2024-12-12 20:36:56 -08:00
Saleem Abdulrasool
bc8a9e40b8 Merge pull request #78140 from compnerd/duplication
runtime: use `_strdup` on Windows
2024-12-12 16:22:27 -08:00
Kuba Mracek
a02586f1f2 [embedded] Include and use cxxshims in the embedded/ resource dir 2024-12-12 12:12:11 -08:00
Saleem Abdulrasool
6716c0428e runtime: re-order environment variable lookup
Hoist the no environment case over the case with the environment. This
ensures that if no environment configuration is selected, the code still
builds. If no environment configuration is selected, `ENVIRON` may still
be defined and that results in calls to elided functions.
2024-12-12 10:39:01 -08:00
Saleem Abdulrasool
9e413bd3d2 runtime: use _strdup on Windows
Windows prefers the `_strdup` extension over `strdup`. This avoids
unnecessary warnings when building the standard library.
2024-12-12 10:36:36 -08:00
Alastair Houghton
293842a9d0 [Backtracing] Update module maps.
Now that Darwin is provided by the system, we no longer need to disable the
system module maps in favour of our own, which also resolves a few other
problems that doing that was creating.

rdar://137201928
2024-12-12 15:58:40 +00:00
Konrad `ktoso` Malawski
55603ec2d4 Use __ptrauth_swift_deinit_work_function in IsolatedDeinitJob 2024-12-12 16:41:04 +09:00
Konrad `ktoso` Malawski
9317f12bd0 Add pointer auth for isolated deinit work function 2024-12-12 16:41:03 +09:00
Mykola Pokhylets
5ac1cba8d1 Handle versioning of the IsolatedDeinit feature 2024-12-12 16:41:02 +09:00
Andrew Trick
0b7a9dd441 Make _overrideLifetime transparent. It is a compiler intrinsic. 2024-12-11 22:02:57 -08:00
Andrew Trick
b08caffc37 Rename _unsafeLifetime to @unsafe _overrideLifetime and reformat.
Also, fix the _overrideLifetime doc comments.
2024-12-11 22:02:57 -08:00
Andrew Trick
496296e503 [stdlib] Fix RawSpan initializer lifetime dependencies.
Two are fixes needed in most of the `RawSpan` and `Span` initializers. For example:

```
    let baseAddress = buffer.baseAddress
    let span = RawSpan(_unchecked: baseAddress, byteCount: buffer.count)
    // As a trivial value, 'baseAddress' does not formally depend on the
    // lifetime of 'buffer'. Make the dependence explicit.
    self = _overrideLifetime(span, borrowing: buffer)
```

Fix #1. baseAddress needs to be a variable

`span` has a lifetime dependence on `baseAddress` via its
initializer. Therefore, the lifetime of `baseAddress` needs to include the call
to `_overrideLifetime`. The override sets the lifetime dependency of its result,
not its argument. It's argument still needs to be non-escaping when it is passed
in.

Alternatives:

- Make the RawSpan initializer `@_unsafeNonescapableResult`.

  Any occurrence of `@_unsafeNonescapableResult` actually signals a bug. We never
  want to expose this annotation.

  In addition to being gross, it would totally disable enforcement of the
  initialized span. But we really don't want to side-step `_overrideLifetime`
  where it makes sense. We want the library author to explicitly indicate that
  they understand exactly which dependence is unsafe. And we do want to
  eventually expose the `_overrideLifetime` API, which needs to be well
  understood, supported, and tested.

- Add lifetime annotations to a bunch of `UnsafePointer`-family APIs so the
  compiler can see that the resulting pointer is derived from self, where self is
  an incoming `Unsafe[Buffer]Pointer`. This would create a massive lifetime
  annotation burden on the `UnsafePointer`-family APIs, which don't really have
  anything to do with lifetime dependence. It makes more sense for the author of
  `Span`-like APIs to reason about pointer lifetimes.

Fix #2. `_overrideLifetime` changes the lifetime dependency of span to be on an
incoming argument rather than a local variable.

This makes it legal to escape the function (by assigning it to self). Remember
that self is implicitly returned, so the `@lifetime(borrow buffer)` tells the
compiler that `self` is valid within `buffer`'s borrow scope.
2024-12-11 22:02:57 -08:00
Andrew Trick
df655e8fc2 [stdlib] Add unsafeLifetime APIs
Unsafely discard any lifetime dependence on the `dependent` argument. Return
a value identical to `dependent` with a new lifetime dependence on the
`borrows` argument.

This is required to enable lifetime enforcement in the standard library
build.
2024-12-11 22:02:57 -08:00
Mike Ash
991d01c048 Merge pull request #77980 from mikeash/concurrency-magic-version-fix
[Concurrency] Fix start of version ranges in install name magic symbols.
2024-12-09 22:04:04 -05:00
Alexis Laferrière
224efd72c5 Merge pull request #77964 from xymus/optional-memcmp
SwiftShims: memcmp should accept optional pointers on Darwin
2024-12-09 13:35:23 -08:00
Mike Ash
e727252733 [Concurrency] Fix start of version ranges in install name magic symbols.
The magic symbols specify a version range where clients should reference a @rpath relative path to libswift_Concurrency.dylib instead of the standard absolute path. This version range started at macOS 10.15 and aligned versions, which is the oldest target supported by Concurrency. However, clients that use Concurrency can target earlier OSes as long as they availability-check their use of Concurrency. When targeting something earlier than 10.15, they'd reference the absolute path, then fail to find the back-deployment Concurrency runtime on OS versions that need it.

Fix this by setting the start of the range to macOS 10.9 and aligned, which is the oldest target supported by Swift.

rdar://140476764
2024-12-09 15:57:46 -05:00
eeckstein
5aacff40ed Merge pull request #78010 from eeckstein/fix-drop-sequence-performance
stdlib: make  DropFirstSequence.makeIterator inline always
2024-12-09 07:47:35 +01:00
Oscar Byström Ericsson
4d43fa97b7 Fix recoverable [U]Int128 division-by-zero (#77854)
* Fix recoverable [U]Int128 division-by-zero

This patch fixes the division-by-zero case in the following methods:

- `Int128/dividedReportingOverflow(by:)`
- `Int128/remainderReportingOverflow(dividingBy:)`
- `UInt128/dividedReportingOverflow(by:)`
- `UInt128/remainderReportingOverflow(dividingBy:)`

* Add preconditions to trapping [U]Int128 division methods.

* Make consistent use of `_slowPath(_:)`.

Jumping on the `_slowPath(_:)` bandwagon like all other integer types.

* Copy existing UInt128 division comments to division operators.

* Add a comment about signed remainder overflow semantics as requested.

I have paraphrased @stephentyrone's and @xwu's review comments to the best of my ability.
2024-12-07 16:44:54 -05:00
Erik Eckstein
da925069a6 Make DropFirstSequence.makeIterator inline always
Usually this function is inlined anyway. But if it is not (and that can happen), it has a dramatic performance impact. Also, usually code size regresses if this function is not inlined.
2024-12-06 11:18:41 +01:00
Dave Lee
463b615a07 [Debug] Remove unnecessary DebugDescriptionMacro feature references (NFC) (#77738) (#77953)
The `DebugDescription` macro has been accepted. Additionally, the `DebugDescriptionMacro` feature was not providing conditional declaration as I originally intended. References to the feature are not needed and can be removed.

(cherry-picked from #77738)
2024-12-05 06:57:17 -08:00
Alexis Laferrière
0c27a4c38c SwiftShims: memcmp should accept optional pointers on Darwin
Darwin defines memcmp with optional pointers. Update SwiftShims to
define it to the same type to avoid deserialization failures where we
get one over the other and the types don't match anymore.

rdar://140596571
2024-12-04 14:58:32 -08:00
Kuba (Brecka) Mracek
dc448a62e0 Merge pull request #77941 from kubamracek/embedded-ios
[embedded] Start building embedded stdlib for arm64-apple-ios + arm64e-apple-ios
2024-12-04 07:51:57 -08:00
Konrad `ktoso` Malawski
22741dba06 Merge pull request #77943 from swiftlang/Kyle-Ye-patch-1 2024-12-04 22:30:07 +09:00
Egor Zhdan
d5f7f6f3ff Merge pull request #77927 from swiftlang/egorzhdan/bring-back-overlay-flag
[cxx-interop] Bring back `AssumeResilientCxxTypes` flag for CxxStdlib overlay
2024-12-04 13:01:44 +00:00
Konrad `ktoso` Malawski
ed5007f6b1 Merge pull request #77584 from ktoso/wip-check-array-calls 2024-12-04 21:01:36 +09:00
Kyle
7c6cc140ad Fix TaskLocal macro link issue 2024-12-04 15:17:10 +08:00
Kyle
a3e8d1068f Fix missing curly brace in TaskLocal documentation 2024-12-04 15:16:42 +08:00
Kuba Mracek
65cd10a87f [embedded] Start building embedded stdlib for arm64-apple-ios + arm64e-apple-ios 2024-12-03 16:24:12 -08:00
Egor Zhdan
b6488d3c8c [cxx-interop] Bring back AssumeResilientCxxTypes flag for CxxStdlib overlay
This fixes a CI job that is building the Swift stdlib with a recent nightly compiler.

rdar://140850172
2024-12-03 18:52:45 +00:00
Egor Zhdan
22141b1118 [cxx-interop] Lower iOS deployment target for Cxx and CxxStdlib
The iOS/watchOS/tvOS deployment targets for Cxx and CxxStdlib binaries got unintentionally bumped in b87b263.

This reverts the deployment targets to the older versions.

rdar://140823785 / resolves https://github.com/swiftlang/swift/issues/77909
2024-12-03 16:39:59 +00:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Egor Zhdan
475e5442ed Merge pull request #77897 from swiftlang/egorzhdan/allow-nonresilient-cxx-in-overlay
[cxx-interop] Allow using non-resilient C++ symbols in resilient overlays
2024-12-03 12:57:19 +00:00
Konrad `ktoso` Malawski
7189aded61 [Distributed] minor cleanups, remove dump=always from tests 2024-12-03 14:59:16 +09:00
Konrad `ktoso` Malawski
6e9224cb5d [Distributed] Introduce SWIFT_DUMP_ACCESSIBLE_FUNCTIONS 2024-12-03 14:59:15 +09:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Egor Zhdan
f420456899 [cxx-interop] Allow using non-resilient C++ symbols in resilient overlays
If a Swift module built with library evolution enabled is an overlay of a C++ module, allow referring to the non-resilient C++ symbols from the Swift code.

Overlays are usually built and shipped along with the C/C++ modules, so library evolution is less of a concern there. A developer providing a Swift overlay for a C++ library would expect to be able to refer to the symbols from the C++ library within the overlay.
2024-12-02 19:44:32 +00:00
3405691582
301a0c49fc Swift on OpenBSD supports arm64.
However, to do this, we end up changing how amd64 is supported too.
Previously, I had tried to keep some meaningful separation between
platform spelling and LLVM spelling, but this is becoming more difficult
to meaningfully maintain.

Target specifications are trivially converted LLVM triples, and the
module files are looked up by LLVM triples. We can make sure that the
targets align, but then the Glibc to SwiftGlibc import breaks. That could
also be addressed, but then we get to a point where the targets set up
by build-script and referenced by cmake begin to misalign. There are
references in build-script-impl for a potential renaming site, but it's
not quite enough.

It's far simpler to give up and rename to LLVM spellings right at the
beginning. This does mean that this commit is less constrained to just
adding the necessary parts to enable arm64, but it should mean less
headaches overall from differing architecture spellings.
2024-11-30 16:33:46 -05:00
Crazy凡
c6b10dffd7 "Enhance CxxDictionary with removeValue(forKey:), subscript(key:default:), mergemerging and init(grouping:by:)" 2024-11-28 13:11:31 +08:00
Egor Zhdan
7473eae623 [cxx-interop] Workaround a compiler crash for CxxStdlib on Windows
This is a workaround for https://github.com/swiftlang/swift/issues/77856.

rdar://140358388
2024-11-27 17:01:33 +00:00
Egor Zhdan
c57756168f [cxx-interop] Workaround a deserialization error for CxxStdlib on Linux
In certain versions of libstdc++, `std::hash<std::string>` defines `operator()` in a base class. It looks like Swift is not correctly deserializing an inherited `operator()` for inlinable functions. This change sidesteps the issue by moving the call to `callAsFunction`/`operator()` to the C++ shim layer.

rdar://140358388
2024-11-26 16:27:05 +00:00