Commit Graph

7182 Commits

Author SHA1 Message Date
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
Jeremy Schonfeld
e59ba66970 Un-deprecate _StringGuts._isContiguousASCII 2024-01-04 14:58:41 -08:00
Dario Rexin
65343add82 [Embedded] Enable SIMD types in embedded Swift (#70674)
* [Embedded] Enable SIMD types in embedded Swift

* Incorporate feedback and add test

* Update simd.swift
2024-01-04 07:28:36 -08:00
Guillaume Lessard
b67b2cb2c5 link to issue regarding initializer renaming 2024-01-03 14:38:05 -08:00
Guillaume Lessard
3e73445a3e Merge pull request #61093 from glessard/se0370-primary-associated-types
[stdlib] use a primary associated type
2024-01-03 10:59:57 -08:00
Kuba (Brecka) Mracek
1efcb415e9 Merge pull request #70217 from kubamracek/embedded-set
[embedded] Add Set to the embedded stdlib
2024-01-03 08:13:52 +01:00
Max Desiatov
0d35c42cf3 Fix error message typo in stdlib/public/core/StaticString.swift (#70643) 2024-01-02 08:11:52 +00:00
honghoker
2fdb8b0481 Fix typo whiteSpace between line comment 2023-12-24 00:05:57 +09:00
Guillaume Lessard
b869a3cabe [se-0405] improve readability of double-optional unwrapping 2023-12-21 10:44:52 -08:00
Guillaume Lessard
4617553ee7 [se-0405] improve slow path 2023-12-21 10:44:52 -08:00
Guillaume Lessard
0ba58de1e1 [se-0405] improve fast path 2023-12-21 10:44:52 -08:00
Guillaume Lessard
148a7e2eff [stdlib] make __SharedStringStorage able to own a pointer 2023-12-21 10:44:52 -08:00
Guillaume Lessard
566fbf4fec [se-0405] update availability to a realistic release target 2023-12-21 10:44:52 -08:00
Guillaume Lessard
92df9b4bdb Apply suggestions from code review
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2023-12-21 10:44:52 -08:00
Guillaume Lessard
f7006880c7 [se-0405] adapt implementation from staging package 2023-12-21 10:44:52 -08:00
Kuba Mracek
bde23e2c2f [embedded] Avoid using reinterpretCast in set bridging 2023-12-20 14:39:38 +01:00
Kuba Mracek
29a7c52433 [embedded] #if the entire _BridgeStorage struct instead of sprinkling a bunch of #ifs inside 2023-12-20 14:32:48 +01:00
Kuba Mracek
25f971d344 [embedded] Add explaining comment about _swiftEmptyArrayStorage/_swiftEmptySetSingleton 2023-12-20 14:08:16 +01:00
Kuba Mracek
943c7c2ee5 [embedded] Drop 'public' from forward declaration of arc4random_buf 2023-12-20 14:04:35 +01:00
Allan Shortlidge
9a0eb73302 Merge pull request #70547 from tshortli/diagnose-unreachable-cant-back-deploy
AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code
2023-12-20 00:16:29 -08:00
Stephen Canon
154454e16a Use specialized [u]int64 -> FloatingPoint conversions even on 32b platforms. (#70541)
This means that we'll end up going int32 -> int64 -> float/double sometiems, but LLVM knows how to optimize away the intermediate conversion so we end up with just a normal 32b->float conversion as desired, and we get much, much better performance on oddball platforms like arm64_32.
2023-12-19 20:29:30 -05:00
Allan Shortlidge
6d22433d0f AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code.
The `_diagnoseUnavailableCodeReached()` function was introduced in the Swift
5.9 standard library and employs `@backDeployed` to support compilation of
binaries that target OS releases aligned with earlier Swift releases.
Unfortunately, though, this backdeployment strategy doesn't work well for some
unusual build environments. Specifically, in some configurations code may be
built with a compiler from a recent Swift toolchain and then linked against the
dylibs in an older toolchain. When linking against the older dylibs, the
`_diagnoseUnavailableCodeReached()` function does not exist but the
`@backDeployed` thunks emitted into the binary reference that function and
therefore linking fails.

The idea of building with one toolchain and then linking to the dylibs in a
different, older toolchain is extremely dubious. However, it exists and for now
we need to support it. This PR introduces an alternative
`_diagnoseUnavailableCodeReached()` function that is annotated with
`@_alwaysEmitIntoClient`. Calls to the AEIC variant are now emitted by the
compiler when the deployment target is before Swift 5.9.

Once these unusual build environments upgrade and start linking against a Swift
5.9 toolchain or later we can revert all of this.

Resolves rdar://119046537
2023-12-19 16:26:56 -08:00
Alejandro Alonso
f96ed95b8a Remove some hold over in core 2023-12-18 14:01:16 -05:00
Alejandro Alonso
2c0b473b8d Add Synchronization module 2023-12-18 14:01:16 -05:00
Alejandro Alonso
87974a83af Some documentation work, some work from review, add tests 2023-12-18 14:01:16 -05:00
Alejandro Alonso
6d6e55a931 Apply feedback from pitch 2023-12-18 14:01:15 -05:00
Alejandro Alonso
f747162084 Implement the Atomic type 2023-12-18 14:01:15 -05:00
Doug Gregor
82ebc54857 Merge pull request #70520 from DougGregor/no-opaque-parameters-in-stdlib
Don't use opaque parameters in the standard library
2023-12-18 10:33:25 -08:00
Doug Gregor
3b4e37e5fe Don't use opaque parameters in the standard library
The SIL printer is printing opaque parameters as <anonymous>, which
breaks the SIL parser. Stop using opaque parameters in the standard
library for the moment to unbreak SIL parsing of the standard library.
2023-12-18 10:14:57 -08:00
Doug Gregor
6536f57ab5 Merge pull request #70516 from DougGregor/typed-throw-try-bang
[Typed throws] Terminate with an error message for typed try! failures.
2023-12-17 02:41:48 -08:00
Doug Gregor
d740965753 [Typed throws] Terminate with an error message for typed try! failures. 2023-12-16 23:58:51 -08:00