Commit Graph

21434 Commits

Author SHA1 Message Date
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
Doug Gregor
8b514ec029 Merge pull request #70902 from DougGregor/isolation-macro
Implement `#isolation` macro to produce the isolation of the current context
2024-01-16 14:27:00 -08:00
Doug Gregor
255009dddb Implement #isolation macro to produce the isolation of the current context
Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
2024-01-16 14:25:51 -08:00
Kuba Mracek
392f2c36eb [embedded] Add Dictionary to embedded stdlib 2024-01-16 13:40:13 -08:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Allan Shortlidge
d3305af80a NFC: Ignore -Wreceiver-forward-class warning in SwiftObject.mm. 2024-01-16 13:27:55 -08:00
Allan Shortlidge
5add794b82 NFC: Ignore -Wobjc-root-class warning in SwiftObject.h.
SwiftObject intentionally does not inherit from `NSObject`.
2024-01-16 13:27:55 -08:00
Allan Shortlidge
582c0de28c NFC: Add _Null_unspecified _swift_stdlib_getEnviron() declaration.
Makes the BSD and `__APPLE__` branches consistent and suppresses the following
warning:

```
warning: pointer is missing a nullability type specifier
```
2024-01-16 13:27:55 -08:00
Allan Shortlidge
11165f3ef1 NFC: Ignore some -Wcast-qual warnings in swift-reflection-test.c. 2024-01-16 13:27:55 -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
Alastair Houghton
888668ac33 Merge pull request #70789 from al45tair/eng/PR-109667503
[Backtracing] Test Developer Mode before allowing interactivity.
2024-01-16 14:51:36 +00: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
Alastair Houghton
7e4bfc995e [Backtracing] Test Developer Mode before allowing interactivity.
On systems where Developer Mode is disabled, we should not allow
interactivity.

rdar://109667503
2024-01-15 17:56:56 +00:00
Konrad `ktoso` Malawski
9d3540fd75 [docs] TaskLocal APIs from non-Task code (#70622) 2024-01-15 11:38:01 +09: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
Allan Shortlidge
8ae3c9ed00 Merge pull request #70912 from tshortli/suppress-concurrency-deprecation-diags-in-stdlib
Sema: Suppress unavoidable deprecation diagnostics in _Concurrency
2024-01-14 08:47:18 -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
Allan Shortlidge
1680d5733d Concurrency: Remove superfluous trys in ExecutorAssertions.swift. 2024-01-13 16:23:55 -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
Allan Shortlidge
478dc96aed Merge pull request #70904 from tshortli/resolve-warnings
NFC: Resolve a bunch of warnings
2024-01-12 21:20:21 -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
Allan Shortlidge
4eacb4d4cb NFC: Suppress -Wdeprecated-declarations warnings in Mutex.h.
The `is_literal` trait is deprecated in C++17.
2024-01-12 17:42:21 -08:00
Allan Shortlidge
3a3a2460df NFC: Resolve -Wformat warning in ProtocolConformance.cpp. 2024-01-12 17:41:50 -08:00
Allan Shortlidge
272a1a4b18 NFC: Resolve -Wauto-var-id warning in ErrorObject.mm. 2024-01-12 17:40:46 -08:00
Allan Shortlidge
333b7b6a46 NFC: Resolve unused variable warnings in BytecodeLayouts.cpp. 2024-01-12 17:39:00 -08:00
Allan Shortlidge
a3286c59e9 Merge pull request #70784 from tshortli/swift3-no-more
Remove `-enable-swift3-objc-inference`
2024-01-12 17:05:53 -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
Allan Shortlidge
e5c6bb649c Remove support for Swift 3 @objc inference.
Obsolete the `-enable-swift3-objc-inference` option and related options by
removing support for inferring `@objc` attributes using Swift 3 rules.
Automated migration from Swift 3 has not been supported by the compiler for
many years.
2024-01-11 15:40:04 -08:00
Allan Shortlidge
c1a4e29f87 Merge pull request #70851 from tshortli/async-discarding-task-builtin
[Concurrency] Fix more missing builtin guards for DiscardingTaskGroup
2024-01-11 14:57:14 -08:00
Mike Ash
feae5f1914 Merge pull request #70771 from mikeash/generic-metadata-builder
[Runtime] Create an external generic metadata builder.
2024-01-11 16:16:50 -05:00
Allan Shortlidge
100e5ee797 [Concurrency] Fix more missing builtin guards for DiscardingTaskGroup.
Follow-up to https://github.com/apple/swift/pull/70837.
2024-01-11 10:22:55 -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
Mike Ash
29c350e813 [Runtime] Create an external generic metadata builder.
Create a version of the metadata specialization code which is abstracted so that it can work in different contexts, such as building specialized metadata from dylibs on disk rather than from inside a running process.

The GenericMetadataBuilder class is templatized on a ReaderWriter. The ReaderWriter abstracts out everything that's different between in-process and external construction of this data. Instead of reading and writing pointers directly, the builder calls the ReaderWriter to resolve and write pointers. The ReaderWriter also handles symbol lookups and looking up other Swift types by name.

This is accompanied by a simple implementation of the ReaderWriter which works in-process. The abstracted calls to resolve and write pointers are implemented using standard pointer dereferencing.

A new SWIFT_DEBUG_VALIDATE_EXTERNAL_GENERIC_METADATA_BUILDER environment variable uses the in-process ReaderWriter to validate the builder by running it in parallel with the existing metadata builder code in the runtime. When enabled, the GenericMetadataBuilder is used to build a second copy of metadata built by the runtime, and the two are compared to ensure that they match. When this environment variable is not set, the new builder code is inactive.

The builder is incomplete, and this initial version only works on structs. Any unsupported type produces an error, and skips the validation.

rdar://116592420
2024-01-11 09:15:02 -05:00