Commit Graph

7802 Commits

Author SHA1 Message Date
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
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
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
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
Doug Gregor
657adcb259 Merge pull request #77780 from DougGregor/willthrow-no-locks
Treat swift_willThrow(Typed) as not locking or performing allocation
2024-11-21 20:02:31 -08:00
Doug Gregor
eff9bacb1b Treat swift_willThrow(Typed) as not locking or performing allocation
Prior to throwing, Swift emits a call to `swift_willThrow(Typed)`,
which allows various diagnostic tools (such as debuggers and testing
libraries) to intercept errors at the point where they are initially
thrown.

Since `swift_willThrow(Typed)` can be hooked by arbitrary code at
runtime, there is no way for it to meet performance constraints like
@_noLocks or @_noAllocation. Therefore, in a function that has those
performance constraints specified, disable emission of the call to
`swift_willThrow(Typed)`.

Fixes rdar://140230684.
2024-11-21 10:18:57 -08:00
Andrew Trick
fe59764f31 Make Unsafe[Mutable]BufferPointer conform to BitwiseCopyable.
The Span interface requires this. It needs to be able to create dependencies on
UBP values without creating extra temporary copies.

This is only a temporary workaround for:

rdar://140291657 (ASTPrinter: print synthesized conformances on the type
definition, not as an extension)

Until that ASTPrinter bug is fixed, .swiftinterface files drop BitwiseCopyable
conformance on types that have conditionally ~Copyable generic parameters.
2024-11-20 12:27:23 -08:00
Andrew Trick
d7806ebb76 Span: Remove ownership modifiers and explicit copies from pointers.
Without this fix, the standard library source will break with shortly upcoming
compiler toolchain.

Never explicitly copy a pointer before passing it to an argument that is the
source of a lifetime dependency on the function's return value. That will always
raise a diagnostic error: depending on a temporary value is not the same as
depending on a variable. A temporary value's scope is only the current expression.

Also avoid using ownership modifiers for UnsafePointer. We don't want to treat
them like noncopyable types. They are simply values. Treating them like
noncopyable types creates a lot of overhead in the representation, which is
likely to interfere with diagnostics and optimization.
2024-11-20 11:44:18 -08:00