Commit Graph

7762 Commits

Author SHA1 Message Date
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
Kuba (Brecka) Mracek
3fdec2171f Merge pull request #77657 from kubamracek/embedded-more-stdlib
[embedded] Add back lazy collection operations, collection diffing and StaticBigInt to Embedded Stdlib
2024-11-19 15:03:31 -08:00
Meghana Gupta
92782a0e08 Add an initializer for Span without lifetime dependence
Without this, supported old compilers which don't recognize LifetimeDependence feature but
recognize the NonEscapableTypes feature will run into lifetime dependence inference errors
on the implicit initializer generated for the stdlib's swiftinterface
2024-11-18 18:09:19 -08:00
Meghana Gupta
5b5acc64e0 Promote Nonescapable types to a language feature 2024-11-18 18:09:17 -08:00
Guillaume Lessard
9084af187f [span] remove the _elementsEqual() functions
We should only add them once they reach their final form.
2024-11-18 16:18:17 -05:00
Guillaume Lessard
9936393183 [span] temporarily add a feature guard 2024-11-18 15:45:07 -05:00
Guillaume Lessard
9073576e84 [span] formulate Span.withUnsafeBytes() better 2024-11-18 15:14:16 -05:00
Guillaume Lessard
2b916a10b3 [gardening] improves some comments in Span and RawSpan 2024-11-18 14:24:56 -05:00
Kuba Mracek
0d4f91f271 [embedded] Add back lazy collection operations, collection diffing and StaticBigInt to Embedded Stdlib 2024-11-16 08:16:57 -08:00
Artem Chikin
9cd689816c Revert "[NFC][CMake] Disable use of in-process 'libSwiftScan' queries when building the Standard Library" 2024-11-14 12:47:32 -08:00
Artem Chikin
201edb83f6 Merge pull request #77606 from artemcm/MoveLibSwiftScanOutOfTools
[CMake] Establish a dependency from standard library variants onto 'libSwiftScan'
2024-11-14 12:31:12 -08:00
Kuba (Brecka) Mracek
a680211a4f Merge pull request #77594 from kubamracek/embedded-int-parsing
[embedded] Enable integer parsing in Embedded Swift
2024-11-14 10:23:01 -08:00
Artem Chikin
338b9141e3 Move libSwiftScan from 'tools' to 'lib/Tooling'
'tools' should be reserved for executable tools.
2024-11-14 08:44:32 -08:00
artemcm
4deff61e11 [NFC][CMake] Disable use of in-process 'libSwiftScan' queries when building the Standard Library
Due to the ordering of our build system, we may encounter a race when building standard library variants using tools produced by Swift's 'tools' CMake build.
As a workaround, for now, ensure that the compiler building standard library variants does not rely on libSwiftScan built as part of 'tools'.
2024-11-13 23:15:08 +00:00
Kuba Mracek
b370050dd0 [embedded] Enable integer parsing in Embedded Swift 2024-11-13 11:52:37 -08:00
Artem Chikin
e96fc88e58 Merge pull request #77541 from artemcm/AddSwiftScanDepToEmbeddedStdLib
[CMake] Add a dependency on 'libSwiftScan' for 'swiftCore'
2024-11-12 15:58:33 -08:00
Guillaume Lessard
4a909c7cc8 Merge pull request #77549 from glessard/buffer-update-fromContentsOf-null-check-removal
[stdlib] Elide some null-pointer checks in UM[R]BP bulk-copy functions
2024-11-12 15:51:20 -05:00
Nate Cook
e12e968570 Add contains(_:) methods to (Closed)Range (#76891)
The _StringProcessing module provides a generic, collection-based
`contains` method that performs poorly for ranges and closed ranges.
This addresses the primary issue by providing concrete overloads
for Range and ClosedRange which match the expected performance for
these operations.

This change also fixes an issue with the existing range overlap tests.
The generated `(Closed)Range.overlap` tests are ignoring the "other"
range type when generating ranges for testing, so all overlap tests
are only being run against ranges of the same type. This fixes things
so that heterogeneous testing is included.
2024-11-12 11:47:24 -08:00
Artem Chikin
58709e58e7 [CMake] Add a dependency on 'libSwiftScan' for 'swiftCore'
It appears that 'swiftCore' and following associated 'embedded-stdlib-*' targets may begin building before the libSwiftScan library has completed building, which may cause crashes if the compiler process building 'swiftCore' attempts to load it.

Resolves rdar://137674862
2024-11-12 10:05:47 -08:00
Guillaume Lessard
54066b2562 Merge pull request #77548 from glessard/rdar139668469-not-immortal-vincible
[span] express correct lifetimes for initializers
2024-11-12 07:40:41 -05:00
Guillaume Lessard
a50260b181 [stdlib] Avoid unnecessary null-pointer checks in UM[R]BP bulk-copy functions 2024-11-11 23:57:47 -05:00
Guillaume Lessard
76d22cc675 [span] correctly express lifetimes for initializers 2024-11-11 23:31:16 -05:00
Henrik G. Olsson
0678829cf7 Add @PointerBounds macro (#76969)
Add @PointerBounds macro

@PointerBounds is a macro intended to be applied by ClangImporter when
importing functions with pointer parameters from C headers. By
leveraging C attributes we can get insight into bounds, esapability, and
(eventually) lifetimes of pointers, allowing us to map them to safe(r)
and more ergonomic types than UnsafePointer.

This initial macro implementation supports CountedBy and Sizedby, but
not yet EndedBy. It can generate function overloads with and without an
explicit count parameter, as well as with UnsafeBufferPointer or Span
(if marked nonescaping), and any of their combinations. It supports
nullable/optional pointers, and both mutable and immutable pointers.
It supports arbitrary count expressions. These are passed to the macro
as a string literal since any parameters referred to in the count
expression will not have been declared yet when parsing the macro.

It does not support indirect pointers or inout parameters. It supports
functions with return values, but returned pointers can not be bounds
checked yet.

Bounds checked pointers must be of type Unsafe[Mutable]Pointer[?]<T>
or Unsafe[Mutable]RawPointer[?]. Count expressions must conform to
the BinaryInteger protocol, and have an initializer with signature
"init(exactly: Int) -> T?" (or be of type Int).

rdar://137628612

---------

Co-authored-by: Doug Gregor <dgregor@apple.com>
2024-11-11 14:54:25 -08:00
Guillaume Lessard
20b85ed59d Merge pull request #76406 from glessard/rdar96837923-span 2024-11-07 18:25:49 -08:00
Guillaume Lessard
4fe9328b65 [span] follow the leading underscore rule
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2024-11-07 12:40:16 -08:00
Guillaume Lessard
386f041aa8 [span] fix an argument label
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2024-11-07 12:39:12 -08:00
Guillaume Lessard
0922b6b622 [span] improve argument labels for safe initializers 2024-11-07 11:19:28 -08:00
Guillaume Lessard
9a8f5a7e9d [span] update more doc-comments 2024-11-07 11:18:40 -08:00
Guillaume Lessard
6272ad66a0 [span] address review feedback 2024-11-06 22:48:28 -08:00
Christian
023590a566 Improved Error._domain calculation (#77369) 2024-11-06 15:09:55 -08:00
Allan Shortlidge
26bd056852 stdlib: Add @_disfavoredOverload to various functions for Embedded.
Functions like `fatalError()` have overloads for Embedded Swift only that take
StaticString instead of String, since String is unavailable. Unfortunately,
many of these overloads create the opportunity for ambiguity in certain
contexts. The easiest way to avoid the ambiguities is to mark each of the
overloads taking `String` as `@_disfavoredOverload`. Another approach that
could work would be to remove the default arguments from the `String` variants
in Embedded Swift only, but that would create even more duplication of source
code so it doesn't seem worth it.
2024-11-02 10:41:08 -07:00
Kuba Mracek
db94dc7d36 [Concurrency] Fix memory leak around mismatched refcounting in Concurrency 2024-10-31 21:43:02 -07:00
Kuba (Brecka) Mracek
79d8de952f Merge pull request #77240 from kubamracek/embedded-printing-types
[embedded] Make Bool string-interpolatable in Embedded Swift, clarify support in docs
2024-10-26 07:56:36 -07:00
Kuba Mracek
68e01f2249 [embedded] Make Bool string-interpolatable in Embedded Swift, clarify support in docs 2024-10-25 22:05:58 -07:00
Guillaume Lessard
c2abbbf4f6 [span] annotate lifetimes that can’t be correct 2024-10-25 18:45:10 -07:00
Guillaume Lessard
2d65dc4f41 [span] lifetime argument tweaks 2024-10-25 18:45:10 -07:00
Guillaume Lessard
c4c9383658 [span] borrow pointer or buffer initializer parameters 2024-10-25 18:45:10 -07:00
Guillaume Lessard
eaf74acbcb [span] add missing RawSpan initializers 2024-10-25 18:45:10 -07:00
Guillaume Lessard
fafd9d3690 [span] readability improvements 2024-10-25 18:45:10 -07:00
Guillaume Lessard
e37475bace [span] small ABI tweaks 2024-10-25 18:45:10 -07:00
Guillaume Lessard
57345f7f6f [span] remove _shrink functions added for review purposes 2024-10-23 18:19:21 -07:00