Commit Graph

7762 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
e06bbf79aa Merge pull request #70971 from kubamracek/tt-withunsafeptr
Adopt typed throws in one withUnsafePointer() API
2024-01-19 14:23:27 -08:00
nate-chandler
1da24ece36 Merge pull request #71009 from nate-chandler/bitwise-copyable-gating
[BitwiseCopyable] Remove gating from protocol declaration.
2024-01-19 12:39:31 -08:00
Nate Chandler
c49738eecf [BitwiseCopyable] Remove gating from protocol decl
It's harmless to have the protocol defined in the swiftinterface for
older compilers and removing the gating permits the gating to be omitted
from conformances
2024-01-19 07:25:15 -08:00
Kuba Mracek
43554c4da4 [embedded] Also enable RNG APIs on SIMD types 2024-01-17 14:53:24 -08:00
Kuba Mracek
bd5913a176 [embedded] Make RNG APIs available on embedded Swift 2024-01-17 14:53:24 -08:00
Kuba Mracek
6d2de26691 Adopt typed throws in one withUnsafePointer() API 2024-01-17 14:19:16 -08:00
Alejandro Alonso
72ad6c5c33 Merge pull request #70945 from Azoy/fix-unmanaged-opaque
[stdlib] Avoid materializing strong references in potential dangling unmanaged opaque functions
2024-01-17 09:30:50 -08:00
Kuba (Brecka) Mracek
cf440011cb Merge pull request #70947 from kubamracek/embedded-unicode-scalar
[embedded] Add Unicode.Scalar to embedded stdlib
2024-01-17 09:30:08 -08:00
Alejandro Alonso
f0a74ecb0d Apply suggestions from code review
Co-authored-by: Guillaume Lessard <glessard@users.noreply.github.com>

fix test
2024-01-16 17:14:18 -08:00
Kuba Mracek
c12d067eac [embedded] Add Unicode.Scalar to embedded stdlib 2024-01-16 16:01:48 -08:00
Alejandro Alonso
e6e87881b8 Take doc suggestion from Karoy #2
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2024-01-16 16:00:04 -08:00
Alejandro Alonso
f28ebc9668 Take doc suggestion from Karoy #1
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2024-01-16 15:58:34 -08:00
Alejandro Alonso
c384b1cfc5 Avoid materializing strong references in potential dangling unmanaged opaque functions
Add test and comments
2024-01-16 15:17:49 -08:00
Kuba Mracek
392f2c36eb [embedded] Add Dictionary to embedded stdlib 2024-01-16 13:40:13 -08:00
Kuba (Brecka) Mracek
0b19b58b68 Merge pull request #70685 from kubamracek/embedded-print-stopgap
[embedded] Add a stop-gap print() for embedded Swift
2024-01-16 10:56:01 -08:00
nate-chandler
7dd1d3f7c1 Merge pull request #70872 from nate-chandler/rdar19519745
[BitwiseCopyable] Infer and check constraint.
2024-01-16 07:01:31 -08:00
Nate Chandler
63de79c91e [stdlib] Pointers and SIMDs are bitwise copyable. 2024-01-15 17:08:32 -08:00
Nate Chandler
2133c94add [stdlib] Optional conforms to _BitwiseCopyable. 2024-01-15 17:08:32 -08:00
Guillaume Lessard
e773d9a093 Merge pull request #70911 from stephentyrone/check-alignment-not-stride 2024-01-15 11:56:03 -08:00
Doug Gregor
b5d1ecc55a Merge pull request #70917 from DougGregor/typed-throws-open-existential
Implement typed throws support in `_openExistential`.
2024-01-14 17:23:11 -08:00
Guillaume Lessard
4e36f5616d [stdlib] operator precedence strikes again 2024-01-14 17:13:24 -08:00
Doug Gregor
a30b623ee6 Implement typed throws support in _openExistential. 2024-01-14 14:32:49 -08:00
Doug Gregor
467f684a43 Merge pull request #70913 from DougGregor/typed-throws-without-actually-escaping
[SE-0413] Adopt typed throws in `withoutActuallyEscaping(_:do:)`
2024-01-14 00:47:36 -08:00
Doug Gregor
8912d4aa71 [SE-0413] Adopt typed throws in withoutActuallyEscaping(_:do:)
There is a small bug fix here in the identification of the catch node,
where the leading `{` of a closure was considered to be "inside" the
closure for code like

    { ... }()

causing us to assume that the call to the closure would catch the error
within the closure.

Other than that, introduce the thrown error type into the type checker's
modeling of `withoutActuallyEscaping(_:do:)`, and mirror that in the
library declaration.
2024-01-13 21:57:24 -08:00
Stephen Canon
c7d50087b0 Check the base address against the element alignment rather than stride
Stride is the gap between elements, not the alignment that each element must satisfy (stride need not even be a power of two).
2024-01-13 16:59:51 -05:00
Doug Gregor
0e6a913f98 Merge pull request #70907 from DougGregor/se-0413-result-typed-throws
[SE-0413] Adopt typed throws in Result
2024-01-13 13:21:05 -08:00
Kuba Mracek
43a9a80e60 [embedded] Hardcode radix=10 in embedded print() 2024-01-13 21:35:37 +01:00
Kuba Mracek
a565d1ab85 [embedded] Make embedded print() not depend on untyped throwing and allocations 2024-01-13 21:35:37 +01:00
Kuba Mracek
8dd56d495f [embedded] Use the correct standard putchar signature: func putchar(_: CInt) -> CInt 2024-01-13 21:35:37 +01:00
Kuba Mracek
75f0e3c66a [embedded] Add a stop-gap print() for embedded Swift 2024-01-13 21:35:36 +01:00
Doug Gregor
0b2cc84dbf Fix typo in mangled name for old ABI entrypoint of Result.init(catching:) 2024-01-13 10:30:15 -08:00
Doug Gregor
7d74b3ba5c [SE-0413] Adopt typed throws in Result
Make `init(catching:)` and `get()` use typed throws. The former infers
the `Failure` type from the closure provided (once full type inference
is in place) and the latter only throws errors of the `Failure` type.
2024-01-13 06:45:08 -08:00
Doug Gregor
255718307e Merge pull request #69771 from DougGregor/typed-throws-map
Replace rethrowing map with generic typed throws
2024-01-12 20:17:39 -08:00
Stephen Canon
7a0c4b5e4a Add default implementations for FixedWidthInteger.dividingFullWidth (#70823)
These are provided for FixedWidthInteger & UnsignedInteger (the base implementation, following Knuth's Algorithm D) and SignedInteger (converting to magnitudes and calling the former). Previously no default implementations were available, requiring every type to implement these operations.

These defaults will not be optimal for large fixed-width integers, so types vending Int512 or similar integers should still provide their own implementations, but they are unconditionally available as a fallback, which simplifies the process of writing such types, and work well enough as a fallback for modest fixed-width integer types like Int64 or 32b or smaller platforms or Int128 on 64b platforms.

Additionally rework the concrete implementations to guarantee that we always trap when the quotient is not representable, and to improve performance for 64b integers on arm64_32, and added some new test coverage for these operations.
2024-01-12 15:25:01 -05:00
Doug Gregor
304ce052f5 [Existential collections] Switch internal _map rethrows methods to throws
These class methods are internal, but because they are overridden and are
part of a `@usableFromInline`, `@_fixed_layout` class, we they can't be
moved over to typed throws without breaking ABI. However, they are
only ever called from typed-throws functions, which already need a
do...catch dance to downcast the error itself. Make them `throws`
instead, which is ABI-compatible, but eliminates the need for
do...catch hackery in the function itself.
2024-01-12 10:17:59 -08:00
Doug Gregor
af79dd815f Improve ABI-only rethrowing map shims based on code review
Replace the hackish use of `@_disfavoredOverload` with the more principled
use of `@_silgen_name` for the entrypoint we are maintaining, then rename
these functions in source to `__rethrows_map` to indicate what they're for.

While here, make them `throws` instead of `rethrows`. The ABI is the
same, and `throws` allows us do avoid to do/catch tricks with rethrows
functions.
2024-01-12 10:17:59 -08:00
Doug Gregor
9e4e9ea400 Replace rethrowing map with generic typed throws
Adopt typed throws for the `map` operation to propagate thrown error
types through the `map` API. This is done in a manner that is backward
compatible for almost all cases:

* The new typed-throws entrypoint is `@_alwaysEmitIntoClient` so it
can back-deploy all the way back.
* The old `rethrows` entrypoint is left in place, using
`@usableFromInline` with `internal` so it is part of the ABI but not
the public interface, and `@_disfavoredOverload` so the type checker
avoids it while building the standard library itself. The old
entrypoint is implemented in terms of the new one.

Note that the implementation details for the existential collection
"box" classes rely on method overriding of `_map` operations, and the
types are frozen, so  we don't get to change their signatures. However,
these are only implementations, not API: the actual API `map`
functions can be upgraded to typed throws.

Note that this code makes use of a known hole in `rethrows` checking
to allow calling between `rethrows` and typed throws. We'll need to do
something about this for source-compatibility reasons, but I'll follow
up with that separately.
2024-01-12 10:17:58 -08:00
Guillaume Lessard
8516275bee Merge pull request #70821 from apple/dl/stdlib-Correct-String-initializer-reference-in-print-docs
[stdlib] Correct String initializer reference in `print` docs
2024-01-11 09:56:07 -08:00
Kavon Farvardin
ac465ea8a1 Merge pull request #70548 from kavon/ncgenerics-stdlib-building-v3
[NCGenerics] Even more fixes for building the stdlib (Part 3)
2024-01-11 08:14:43 -08:00
eeckstein
6bf39cccd6 Merge pull request #70787 from eeckstein/boolean-literal-folding
Mandatory optimizations: constant fold boolean literals before the DefiniteInitialization pass
2024-01-11 11:39:44 +01:00
Kavon Farvardin
8b870e9e6c [NCGenerics] fix Copyable/Escapable declarations
When building the stdlib with noncopyable generics enabled,
requirements for Copyable and Escapable  end up being inferred on the
protocols Copyable and Escapable, themselves. So we need to opt-out
Copyable from requiring Escapable, and vice versa.
2024-01-10 19:37:21 -08:00
Guillaume Lessard
8d0991f9d0 [se-0405] improve examples in documentation 2024-01-10 14:32:26 -08:00
Guillaume Lessard
98273aa6c2 Update stdlib/public/core/StringCreate.swift
Was off by one.
2024-01-10 14:32:26 -08:00
Guillaume Lessard
fa9c80ae08 [test] round out testing for String.init?(validating:as:) 2024-01-10 14:32:26 -08:00
Alejandro Alonso
e37ecac163 Merge pull request #68857 from Azoy/atomics
[stdlib] Atomics
2024-01-10 12:03:08 -08:00
Dave Lee
b4feec6c5e [stdlib] Correct String initializer reference in print docs 2024-01-10 11:05:54 -08:00
Erik Eckstein
d4730e02ce stdlib: add a semantic attribute to Bool.init(_builtinBooleanLiteral:)
This is required for being able to constant fold boolean literals before the DefiniteInitialization pass
2024-01-10 16:12:53 +01:00
Jeremy Schonfeld
2404013f78 [SE-0270] Add Collection Operations on Noncontiguous Elements (#69766)
* Adds RangeSet/DiscontiguousSlice to the stdlib

* Remove redundant DiscontiguousSlice.Index: Comparable conformance

* Attempt to fix embedded build

* Attempt to fix macOS test failures

* Fix Constaints/members.swift failure on linux

* Add exceptions to ABI/source checker to fix macOS tests

* Fix incremental dependency test failure

* Remove inlining/unfreeze implementation for future improvements

* Simplify indices(where:) implementation

* Address review feedback

* Add test for underscored, public slice members

* Address feedback on inlining, hashing, and initializing with unordered arrays

* Fix ABI checker issues

* Remove MutableCollection extension for DiscontiguousSlice

* Make insertion return a discardable Bool

* Fix ABI checker tests

* Fix other ABI checker tests due to dropping MutableCollection subscript
2024-01-09 14:02:19 -08:00
Jeremy Schonfeld
b46adbb4d7 Merge pull request #70726 from jmschonfeld/undeprecate-iscontiguousascii
Un-deprecate _StringGuts._isContiguousASCII
2024-01-08 15:43:33 -08:00
Pavel Yaskevich
d61eac29d8 Merge pull request #70613 from honghoker/fix-typo
Fix typo whiteSpace between line comment
2024-01-08 09:17:32 -08:00