Commit Graph

17573 Commits

Author SHA1 Message Date
Nate Cook
6c29d2f64a Fix the doc formatting for FloatingPoint comparison methods (#78443)
In the documentation for the `isLess(than:)` and `isLessThanOrEqualTo(_:)`
methods, a code sample isn't being formatted correctly due to it directly
following an unordered list. This change adds an additional message that
introduces the code sample, separating it from the list and allowing
the correct formatting to be applied.
2025-01-06 15:13:42 -08:00
Gábor Horváth
6e84b8f507 Merge pull request #78352 from swiftlang/gaborh/cxx-span-overload 2025-01-03 15:32:39 +01:00
Doug Gregor
7d6e3776ba Merge pull request #78332 from DougGregor/strict-safety-improvements
Strict safety improvements
2025-01-02 08:25:02 -08:00
Egor Zhdan
52a2638b3f Merge pull request #78353 from swiftlang/egorzhdan/nfc-fix-cxx-warning
[cxx-interop] NFC: Fix a warning
2025-01-02 12:15:39 +00:00
Egor Zhdan
67da2026ea [cxx-interop] NFC: Fix a warning
This fixes a build warning:
```
swift/stdlib/public/Cxx/CxxDictionary.swift:168:9: warning: variable 'iter' was never mutated; consider changing to 'let' constant
```
2024-12-23 16:26:36 +00:00
Gabor Horvath
b0bb995209 [cxx-interop] Estend _SwiftifyImport with basic std::span support
This is a preliminary PR to transform nonescaping std::span parameters
to Swift's Span type in safe wrappers. To hook this up with
ClangImporter, we will need generalize the noescape attribute to
non-pointer types (PR is already in review). To transform potentially
escaping spans and spans in the return position, a follow-up PR will
add lifetime annotation support. This is a building block towards
rdar://139074571.
2024-12-23 14:08:10 +00:00
Doug Gregor
3ab5456eae Mark SerialExecutor.asUnownedSerialExecutor unsafe so conformances don't need to be @unsafe
What we should actually do with SerialExecutor conformances is not yet clear, though.
2024-12-20 23:16:26 -08:00
Doug Gregor
47f21592d6 Remove WarnUnsafe from the standard library build until we're ready to deal with the warnings 2024-12-20 23:15:42 -08:00
Doug Gregor
55b186c904 Diagnose uses of @unchecked Sendable conformances, not declarations
Under strict concurrency and memory safety, uses of `@unchecked
Sendable` conformances are considered unsafe. Diagnose the use sites,
not the declaration site.
2024-12-20 23:15:40 -08:00
Doug Gregor
9e09513514 Mark UnownedSerialExecutor as @unsafe 2024-12-20 07:35: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
Kuba (Brecka) Mracek
e0ccd1b4ec Merge pull request #78263 from kubamracek/embedded-stdlib-all-available
[embedded] Make stdlib APIs automatically available on older Darwin versions in Embedded Swift
2024-12-19 20:33:34 -08:00
Andrew Trick
60845673b0 Fix Span initialization from CxxSpan.
CxxSpan is trivial, but not immortal.

This initializer is diagnosed with an error after enabling trivial dependence
enforcement. Correct this with an _overrideLifetime call. This could be avoided
if we had a another way to tell the compiler that CxxSpan.__dataUnsafe()
produced a pointer with the same effective lifetime as the CxxSpan.
2024-12-18 16:58:49 -08:00
Andrew Rogers
63dd1997c0 Add comment explaining debug. propname prefix 2024-12-18 10:07:23 -08:00
Andrew Rogers
b2fb2f465c PR feedback: rename propValueString to buffer 2024-12-18 10:02:56 -08:00
Egor Zhdan
0fa65bea8a Merge pull request #77864 from CrazyFanFan/feature_cxxmap
[cxx-interop]: Enhance CxxDictionary with Merging, Initializer, and Unsafe Erasure
2024-12-18 13:37:44 +00:00
Kuba Mracek
24469238d8 [embedded] Make stdlib APIs automatically available on older Darwin versions in Embedded Swift 2024-12-17 19:40:57 -08:00
Andrew Rogers
feea6aaefe PR feedback 2024-12-17 11:54:02 -08:00
Andrew Rogers
0192aa4728 [android] also load debug env vars from system properties 2024-12-17 10:24:57 -08:00
Hamish Knight
f1e4fb27de Revert "Add an overload of append(contentsOf:) on Array that takes a Collecti…"
This reverts commit b71f768128.
2024-12-17 16:23:16 +00:00
Egor Zhdan
f2ad9f3d90 Merge pull request #78223 from swiftlang/egorzhdan/frt-as-existential-crash
[cxx-interop] Fix runtime crash when casting from an existential to a foreign reference type
2024-12-17 12:59:34 +00:00
Saleem Abdulrasool
b64c0198c9 Merge pull request #78208 from swiftlang/eng/android-ptrauth-build
[stdlib] fix android build
2024-12-16 13:17:47 -08:00
Philippe Hausler
8462f5c90b [Observation] Optimize the storage of registrar entries, provide KeyPath caching, and uniqueness notification (#78151) 2024-12-16 13:13:19 -08:00
Egor Zhdan
84ae5fbe8c [cxx-interop] Fix runtime crash when casting from an existential to a foreign reference type
When a C++ foreign reference type is conformed to a Swift protocol via a Swift extension, trying to cast `any MyProtocol` to the foreign reference type crashes the runtime.

This was because `selectCasterForDest` wasn't handling C++ foreign reference types, and we were hitting `swift_unreachable`.

This change makes sure the runtime doesn't crash for such casts.

Notably, Swift doesn't have enough metadata to determine if the conditional cast actually succeeded. This is also a problem for CF types. Casting CF types in a similar fashion triggers a typechecker diagnostic. That diagnostic will be amended in a follow-up patch to also trigger for foreign reference types.

rdar://141227849
2024-12-16 20:23:17 +00:00
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