Commit Graph

7762 Commits

Author SHA1 Message Date
Alejandro Alonso
59c53b72f0 Don't do the kvc stored offset optimization on 16 bit platforms 2025-02-04 15:16:40 -08:00
Alejandro Alonso
02401d4bb0 Remove some workarounds 2025-02-04 15:16:39 -08:00
Alejandro Alonso
581376e86e Move variable into closure 2025-02-04 15:16:39 -08:00
Alejandro Alonso
25a4bbe549 Check maxSize on finish 2025-02-04 15:16:39 -08:00
Alejandro Alonso
6fdb684fd2 Optimization for single component and fix tests 2025-02-04 15:16:39 -08:00
Alejandro Alonso
00ace6695f Round up sizeWithMaxSize 2025-02-04 15:16:38 -08:00
Alejandro Alonso
4733da2744 Performance improvements for reading keypaths 2025-02-04 15:16:36 -08:00
Kuba (Brecka) Mracek
3afe8ebdf6 Merge pull request #78919 from kubamracek/embedded-dict-init
[embedded] Support Dictionary.init(uniqueKeysWithValues:) in Embedded Swift
2025-01-31 11:03:04 -08:00
Erik Eckstein
20db2a488b stdlib: add a missing fixLifetime in withVaList
If this function is inlined, the optimizer can shrink the lifetime of the `args` parameter. This would deallocate the passed arguments (e.g. `NSString`s) before the are used in the closure.
2025-01-30 17:30:22 -08:00
Gábor Horváth
8462105e29 Merge pull request #78947 from swiftlang/gaborh/lifetimebound-this 2025-01-29 09:09:53 +00:00
Kuba Mracek
642a8f9762 [embedded] #ifdef the Dictionary.init(uniqueKeysWithValues:) changes only to Embedded Swift 2025-01-28 16:22:46 -08:00
Kuba (Brecka) Mracek
53921e4c8c Merge pull request #78920 from kubamracek/embedded-wae
[embedded] Support withoutActuallyEscaping in Embedded Swift
2025-01-28 12:32:48 -08:00
Gabor Horvath
06e5ead8da [cxx-interop] Support borrowing from self in SwiftifyImport
Support adding safe wrappers for APIs returning std::span depending on
the this object. This also fixes an issue for APIs with 0 parameters.

rdar://139074571
2025-01-28 13:54:10 +00:00
Alastair Houghton
ab8e561583 Merge pull request #78516 from al45tair/eng/PR-124913332
[Backtracing] Implement API per SE-0419
2025-01-28 10:48:33 +00:00
Kuba Mracek
f4c69e1ca0 [embedded] Also allow nil in swift_isEscapingClosureAtFileLocation to match the C++ runtime 2025-01-27 10:20:23 -08:00
Kuba Mracek
8e3ee38324 [embedded] Support withoutActuallyEscaping in Embedded Swift 2025-01-25 15:24:20 -08:00
Kuba Mracek
c99e9e4922 [embedded] Support Dictionary.init(uniqueKeysWithValues:) in Embedded Swift 2025-01-25 14:55:19 -08:00
Gábor Horváth
4d24b7d888 Merge pull request #78709 from swiftlang/gaborh/span-lifetimebound-overload
[cxx-interop] Support transforming lifetimebound spans
2025-01-22 14:21:57 +00:00
Alejandro Alonso
11fbd94668 Merge pull request #78664 from Azoy/unicode-16
[stdlib] Unicode 16
2025-01-21 09:29:35 -08:00
Gabor Horvath
8c03a31d65 [cxx-interop] Support transforming lifetimebound spans
This PR adds basic support for storing lifetime dependence information,
transform Span return types, and generate lifetime annotations.

rdar://139074571
2025-01-21 10:51:04 +00:00
David Smith
600dcd0828 Expose immortal String initialization for Foundation (#78661) 2025-01-19 07:43:13 -08:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00
Garth Snyder
610d07e9ed [stdlib] Fix doc comment refs to subranges(where:), now called indices(where:) (#78512)
Doc comments for DiscontiguousSlice, MutableCollection, RangeSet, and
RangeReplaceableCollection all refer to a Collection method subranges(where:)
which is intended to return a RangeSet of matching ranges. I believe this is
likely an old or formerly-contemplated spelling of the method now known as
indices(where:). This commit changes "subranges" to "indices".
2025-01-16 13:54:02 -08:00
Alejandro Alonso
d3146e37b3 Update Scalar names for Unicode 16 2025-01-15 14:08:30 -08:00
Alejandro Alonso
1f74aa1634 Update grapheme breaking logic to support Unicode 16 2025-01-15 14:08:18 -08:00
Guillaume Lessard
c9c5253fb3 [stdlib] fix getting eager-lazy-bridged buffer 2025-01-14 16:18:24 -08:00
Evan Wilde
6f823dcebf Fix Slab availability annotation
Values in generic types are only available as part of 6.2, not 6.1.
Fix the availability annotations on the slab type to match.

rdar://142781302
2025-01-13 12:42:20 -08:00
Henrik G. Olsson
d7bd76e9f1 [Swiftify] Add return pointer support (#78571)
* Import __counted_by for function return values

Instead of simply passing a parameter index to _SwiftifyInfo, the
_SwiftifyExpr enum is introduced. It currently has two cases:
 - .param(index: Int), corresponding to the previous parameter index
 - .return, corresponding to the function's return value.

ClangImporter is also updated to pass this new information along to
_SwiftifyImport, allowing overloads with buffer pointer return types to
be generated. The swiftified return values currently return Span when
the return value is marked as nonescaping, despite this not being sound.
This is a bug that will be fixed in the next commit, as the issue is
greater than just for return values.

* Fix Span variant selection

There was an assumption that all converted pointers were either
converted to Span-family pointers, or UnsafeBufferPointer-family
pointers. This was not consistently handled, resulting in violating the
`assert(nonescaping)` assert when the two were mixed. This patch removes
the Variant struct, and instead each swiftified pointer separately
tracks whether it should map to Span or UnsafeBufferPointer.
This also fixes return pointers being incorrectly mapped to Span when
marked as nonescaping.
2025-01-13 08:08:36 -08:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Guillaume Lessard
18dd091fb8 Merge pull request #78538 from lorentey/define-availability-for-6.2
Define placeholder availability for Swift 6.2
2025-01-10 18:09:39 -08:00
Alejandro Alonso
4c5a13a63e Moar test fixes 2025-01-10 17:52:50 -08:00
Guillaume Lessard
46aa3fba1a Merge pull request #78546 from glessard/array-lazy-eager-bridge-loadfix
[stdlib] loading a reference can’t use `loadUnaligned`
2025-01-10 13:10:26 -08:00
Guillaume Lessard
9743ec9fd6 [stdlib] loading a reference can’t use loadUnaligned 2025-01-10 09:10:32 -08:00
Guillaume Lessard
d4ae6b0ce8 [gardening] move String.withCString to String.swift
- it has been at an unexpected location for unremembered reasons.
2025-01-09 22:16:58 -08:00
Karoy Lorentey
872bc6eee6 [stdlib] Define _StdlibVersion.v6_2_0 and set it as the current version 2025-01-09 18:17:46 -08:00
Alejandro Alonso
cedea94b4c Test fixes and review feedback 2025-01-09 15:54:54 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Alejandro Alonso
2823d3018f Some Vector API changes 2025-01-08 10:37:16 -08:00
Alejandro Alonso
f867d0bb05 Implement Vector 2025-01-08 10:33:13 -08:00
David Smith
26b2f7bb47 Re-land using associated objects to attach bridged Array buffers (#78452) 2025-01-07 19:38:21 -08:00
Alex Martini
57657c6d3e Clarify what "schoolbook" rounding means (#77903) 2025-01-06 16:27:47 -08:00
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
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
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 Mracek
24469238d8 [embedded] Make stdlib APIs automatically available on older Darwin versions in Embedded Swift 2024-12-17 19:40: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
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
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