Commit Graph

44 Commits

Author SHA1 Message Date
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Holly Borla
e1c3781e23 [NFC] Fix IDE tests for @Sendable inference change. 2024-06-17 21:50:41 -07:00
Pavel Yaskevich
a90e5916bd [ClangImporter] Wrap compositions with Sendable protocol into existentials
Resolves: https://github.com/apple/swift/issues/65730
2024-03-18 10:43:42 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Doug Gregor
9bd950477c Using --enable-experimental-feature requires an asserts-enabled compiler.
Fixes rdar://97281993.
2022-07-21 09:31:32 -07:00
Doug Gregor
28a0f83590 Turn @Sendable completion handlers into an experimental feature.
`@Sendable` on completion handlers imported from Objective-C has been
implemented for a while, but has been disabled in production builds
due to a number of problems we've encountered with rolling it out.

Introduce an experimental feature for `@Sendable` completion handlers
so we can iterate on this more before we enable it by default.

Part of rdar://85569247, which will cover re-landing this feature.
2022-07-18 12:29:28 -07:00
Becca Royal-Gordon
a57e71ccd0 Import swift_attr(“@Sendable”) for result types
If `__attribute__((swift_attr(“@Sendable”)))` is applied to an ObjC method, ObjC property, C field, C variable, or C function, we will now make its result type `Sendable`.

For some entities, this technically had a different behavior previously, because `@Sendable` can be applied to `func`s to indicate that their interface type should be `@Sendable`. We don’t really want people to use this functionality on non-local functions, so we can safely remove it.

This isn’t quite interacting with `Unmanaged` the way we’d want, but I’ve included test cases for the current behavior with FIXME comments.

Fixes rdar://90491024.
2022-03-29 17:18:10 -07:00
Becca Royal-Gordon
51e5408eeb [ClangImporter] Allow @Sendable on more params
When `__attribute__((swift_attr(“@Sendable”)))` is applied to a clang parameter Swift now attempts to make the type `Sendable` in a more comprehensive way than before:

* If it is a function type, it adds `@Sendable` to it.
* If it is a protocol composition type, it adds `& Sendable` to it.
* If it is a class, protocol, or generic class, it inserts it into a protocol composition and adds `& Sendable`.
* If it is a typealias, it *may* desugar it to a modified version of the underlying type.
* In various other cases, it recurses into the children of the type.

This allows Objective-C methods and functions to require that their arguments have a Sendable type without specifying a particular type they must belong to.

Fixes rdar://87727549.
2022-03-10 16:03:37 -08:00
Becca Royal-Gordon
8c844126d4 [ClangImporter] Make completion handlers Sendable
If a method has an `async` variant, the non-`async` variant will now mark its completion handler parameter `@Sendable`. This shouldn't be a breaking change in Swift 5 code since these declarations are automatically `@_predatesConcurrency`.

Also adds:

• Support for `@_nonSendable` on parameters, which can be used to override this implicit `@Sendable`
• Support for `@Sendable` on block typedefs; it's generally going to be a good idea to mark completion block typedefs `@Sendable`.

Fixes rdar://85569247.
2022-01-25 15:49:54 -08:00
Becca Royal-Gordon
1695d61664 [ClangImporter] Import SwiftAttrs early
This change applies SwiftAttr attributes as soon as possible after creating an instance of a Decl, rather than waiting until the declaration is "finished". That makes sure the attributes can influence the declaration very early in its lifecycle, and in particular, before its conformance table is initialized.

Mostly NFC in this commit (other than affecting the order that attributes are printed in), but necessary for future changes in this PR.
2021-11-19 11:34:01 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00
Becca Royal-Gordon
de768e8fda [ClangImporter] Import SwiftAttrs early
This change applies SwiftAttr attributes as soon as possible after creating an instance of a Decl, rather than waiting until the declaration is "finished". That makes sure the attributes can influence the declaration very early in its lifecycle, and in particular, before its conformance table is initialized.

Mostly NFC in this commit (other than affecting the order that attributes are printed in), but necessary for future changes in this PR.
2021-11-12 23:12:38 -08:00
Ben Barham
e7e9b57051 Replace @completionHandlerAsync with @available(*, renamed:)
Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.

No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).

Resolves rdar://80612731
2021-07-29 09:14:44 +10:00
Doug Gregor
6ba26292b1 [Clang importer] Import Swift declaration modifiers from swift_attr.
In addition to importing Swift attributes spelled with the C
`__attribute__((swift_attr("...")))`, also import declaration modifiers,
including `nonisolated`.

Fixes rdar://79402200.
2021-06-17 10:25:42 -07:00
Doug Gregor
03f55d7bb4 Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e8ea.
2021-06-03 14:03:57 -07:00
Karoy Lorentey
7c0b50e8ea Revert "Remove @actorIndependent attribute." 2021-05-24 14:43:32 -07:00
Doug Gregor
d6e8fd81f5 Remove @actorIndependent attribute.
`@actorIndependent` has been superseded by `nonisolated`. Remove
the old spelling entirely.
2021-05-17 12:21:10 -07:00
Doug Gregor
2b9ca315fe [Concurrency] Remove asyncHandler attribute.
The `asyncHandler` attribute turned out to be the wrong solution
to the problem of creating a sync->async bridge. Remove it.
2021-05-13 17:01:39 -07:00
Hamish Knight
fe3dbc2fd4 Fix typo in @completionHandlerAsync printing 2021-04-30 11:14:51 +01:00
Hamish Knight
f059713a79 [test] Add -print-implicit-attrs to a couple of tests
Now that @completionHandlerAsync is implicit for
imported decls, we need to enable implicit attrs in
a couple of tests that are testing its presence.
2021-04-30 11:14:50 +01:00
Kavon Farvardin
64f6182cc7 prevent double @MainActor annotation in ClangImporter
This can lead to latent type errors for API users,
because a swiftmodule would otherwise be emitted,
without any diagnostics, containing imported decl
with two global actor annotations on it. Such
decls will always be an error to the typechecker
when its eventually encountered.

This patch drops all `@MainActor` annotations after
the first one in the ClangImporter, regardless of
whether its the safe or unsafe version, and emits
a warning when doing so.
2021-03-31 17:11:45 -07:00
Ben Barham
3de83aca66 [ClangImporter] Add @completionHandlerAsync for imported decls
Implicitly add the @completionHandlerAsync attribute for ObjCMethodDecl
that have a completion handler. Adds a link from the non-async to the
async function for use in diagnostics and refactorings.

Resolves rdar://74665226
2021-03-31 08:39:12 +10:00
Doug Gregor
c76dac7155 Banish @asyncHandler to a hidden flag.
We don't want @asyncHandler to be part of the concurrency model, so put
it behind a different flag.
2021-03-25 16:45:21 -07:00
Doug Gregor
45d3c8813c [Clang importer] Import __swift_attr__("@Sendable") as Sendable on parameters. 2021-03-24 22:35:09 -07:00
Doug Gregor
5f71e52146 [Clang import] Apply main-thread annotations from parameters to types.
Import a main-thread annotation on a function/method parameter in
(Objective-)C as a `@MainActor` function type.
2021-03-24 22:28:29 -07:00
Doug Gregor
a109736937 Make sure that imported @MainActor shows up in the interface.
... but don't show the (unsafe) part outside of Swift interfaces, because
it's messy and we don't want people to use it.
2021-03-23 17:29:58 -07:00
Doug Gregor
451e6cc1f5 [Concurrency] Add support for @GlobalActor(unsafe).
Allow us to tag declarations that are meant to be in a global actor, but
for which we don't yet want to enforce everything. This will be used for
better staging-in of global actor annotations, but for now it's a fancy
way to document @actorIndependent(unsafe).

Stages in the syntax for rdar://74241687 without really implementing it.
2021-02-25 22:41:32 -08:00
Doug Gregor
a8f91c4efa [Clang importer] Allow @UIActor as an alias for @MainActor.
We've flip-flopped on the name a bit. Accept both for now.
2021-02-15 15:29:46 -08:00
Doug Gregor
c732ba3bf9 [Clang importer] Make @actorIndependent on imported macros implicit.
This prevents it from printing in Swift interfaces, which is a bit noisy.
2021-02-15 15:18:53 -08:00
Doug Gregor
abb5fbf1ce [Clang importer] Remove @asyncHandler inference for Objective-C methods
The rule was inconsistent and required a lot of auditing, and could
cause surprises. We can consider bringing it back at another time.
2021-02-11 22:37:28 -08:00
Evan Wilde
8f81609a1b Imported macros are actor independent
Macros are thread safe. Marking them actor-independent will avoid
imported macros being reported as not concurrency safe.
2021-01-19 15:33:30 -08:00
Doug Gregor
8c123e8505 [Concurrency] Hard-code support for importing @MainActor.
Our name lookup rules for the resolution of custom attributes don't
allow for them to find MainActor within the _Concurrency library.
Therefore, hardcode @MainActor to map to _Concurrency.MainActor.

While here, make sure we drop concurrency-specific attributes that
show up in Clang attributes when we aren't in concurrency mode.
2021-01-08 17:03:50 -08:00
Doug Gregor
cd0380b646 [Clang importer] Import Clang swift_attr attribute.
The Clang swift_attr attribute allows C code to describe, via a Clang
attribute, the Swift attributes that should be applied to the given
declaration. When an

    __attribute__((__swift_attr__("@tribute")))

occurs on a Clang declaration, parse the attribute within the string
literal as a Swift attribute, then attach that to the imported Swift
declaration.

Fixes rdar://70146633.
2021-01-08 12:08:45 -08:00
Doug Gregor
d7367997d2 Merge pull request #34985 from DougGregor/import-swift-async-attr
[Concurrency] Implement support for swift_async attribute.
2020-12-10 10:09:28 -08:00
Doug Gregor
82b44fc6dd [Concurrency] Fix async throws import nullability in the presence of typedefs. 2020-12-08 14:51:03 -08:00
Doug Gregor
915afc3aa5 [Clang importer] Implement support for importing _Nullable_result.
`_Nullable_result` indicates that a parameter of a completion handler
should be imported as optional when the completion handler can fail by
throwing an error.

Implements rdar://70108088.
2020-12-08 14:49:54 -08:00
Doug Gregor
b837675910 [Concurrency] Introduce more completion-handler names to the import heuristics.
Extend the set of completion-handler names we look for to infer an
`async` import of an Objective-C method, which includes:

* (with)CompletionBlock
* (with)reply
* (with)replyTo

both as parameter names and as base name suffixes.
2020-12-07 16:47:31 -08:00
Doug Gregor
3cd115e283 [Concurrency] Implement support for swift_async attribute.
The `swift_async` attribute helps control how a method is imported as
`async` into Swift.

Implements rdar://70111787.
2020-12-06 23:21:18 -08:00
Doug Gregor
d249b5cce5 [Clang importer] Make sure we mirror protocol decls for all names.
When mirroring declarations from protocols, make sure to mirror for
all potential imported names. Otherwise, we might miss out on one or
the other of an async import or a completion-handler import of the
same method.

Fixes rdar://71429577.
2020-11-17 22:26:41 -08:00
Doug Gregor
4bcccecfda [Concurrency] Implicitly strip optionals for return type of translated "async throws".
Review over a large number of APIs has found that most of the time, the
result type of an Objective-C completion handler method that becomes
"async throws" should be optional. Change the default behavior to
match this, and replace _Nullable_on_error with _Nullable_result to
capture the case where the result should be optional.
2020-10-30 00:01:20 -07:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
9b808c67fa [Concurrency] Import "did" delegate methods as @asyncHandler.
Infer @asyncHandler on a protocol methods that follow the delegate
convention of reporting that something happened via a "did" method, so
long as they also meet the constraints for an @asyncHandler method in
Swift. This enables inference of @asyncHandler for witnesses of these
methods.
2020-09-24 14:01:08 -07:00
Doug Gregor
6ad2757bef [Concurrency] Use completion/completionHandler parameter names for async import
Extend the check for completion handler parameters to also consider the
name of the parameter (not its argument label). If it's `completion` or
`completionHandler`, we have a completion handler. This extends our
API coverage for importing Objective-C methods with completion
handlers as 'async'.
2020-08-28 13:58:02 -07:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00