Commit Graph

105 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
703595e396 [Concurrent] Warnings/errors should use "sendable" not "concurrent"
Resolves rdar://83416205
2021-09-23 12:45:07 +09:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07: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
5bcd5a8e25 Use "isolated" parameters to check for synchronous actor access.
Rework the checking of actor member access to rely on "isolated" parameters
(and captures thereof) to determine whether one can synchronously access
an actor or not. This allows synchronous access via an "isolated" parameter
as a general notion, which subsumes the declaration-based "self" access.

Simplify the checking of and diagnostic reporting for actor member
access by collapsing a number of redundant diagnostics down into a
single, parameterized diagnostic with a single point of emission. This
normalizes the logic a bit.
2021-06-08 00:00:12 -07:00
Doug Gregor
5004a5447b [Concurrency] Make "self" parameter of actor-isolated functions 'isolated'.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
2021-06-07 23:59:38 -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
Doug Gregor
bf30b41e5b [Clang importer] Fix mirroring of protocol decls for 'async' imports.
The de-duplication checks to preventing redundant mirroring of protocol
declarations failed to consider that a given method could be
implemented as both 'async' and non-'async' declarations, and
therefore would fail to mirror the 'async' form. Account for this
distinction.

Fixes rdar://76799297.
2021-04-30 01:05:03 -07:00
Evan Wilde
3da0a540eb Update tests
This patch updates all the tests to accept the new error messages.
*Gack* so many things needed cleaning up.
2021-04-24 07:51:18 -07:00
Doug Gregor
7762cc82a9 Adjust test case for new diagnostic 2021-04-16 00:26:39 -07:00
Doug Gregor
f02a01e4f2 Add @_unsafeMainActor corresponding to @MainActor 2021-03-31 09:40:41 -07:00
Doug Gregor
ed7372b92b [Clang importer] Import @_unsafeSendable on C function/ObjC method params 2021-03-31 09:40:04 -07:00
Doug Gregor
a9d5f60310 Revert "[Actor isolation] Limit propagation of unsafe global actors to instance members"
This reverts commit 61b22f8f4f.
2021-03-29 21:24:40 -07:00
Doug Gregor
61b22f8f4f [Actor isolation] Limit propagation of unsafe global actors to instance members
Don't propagate implicit, unsafe global actor annotations from a type
to its instance members. We want the annotation to cover all of a type,
but not implicitly cover (e.g.) all of its subclasses's members except
those it gets through overrides or witnessing protocol requirements.
2021-03-27 22:37:55 -07: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
da4b28dabe Merge pull request #36512 from DougGregor/isolation-inference-fallthrough
[Concurrency] Don't let "unsafe" inference block other inference.
2021-03-22 13:29:00 -07:00
Doug Gregor
72bf30bcd6 [Isolation] Propagate global actors from witnesses. 2021-03-22 05:52:09 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
30bfe4dcc0 Update diagnostics to talk about non-isolated rather than @actorIndependent 2021-03-07 22:16:34 -08:00
Doug Gregor
74affffcb7 Propagate actor isolation freely through Objective-C declarations. 2021-03-04 22:49:57 -08:00
Doug Gregor
7496701c9f Limit ConcurrentValue inference to non-public, non-frozen structs and enums 2021-03-02 16:26:08 -08: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
9d5f631919 Update test 2021-02-15 16:19:36 -08:00
Doug Gregor
71e0b1d90c [Clang importer] Don't suppress properties due to async method imports.
The Clang importer had some logic to suppress the import of a property that
had the same name as a method with no parameters. This logic
inadvertently meant that an async import of a completion-handler method
could prevent a (non-async) property of the same name to not be
imported, breaking existing code. In such cases, don't suppress the
property import.

Fixes rdar://73326019.
2021-02-12 13:19:16 -08:00
swift-ci
e1480324ee Merge pull request #35880 from DougGregor/fixup-async-availability-test 2021-02-10 11:41:11 -08:00
Doug Gregor
c8c8f166cd Fix original test as well 2021-02-10 09:32:26 -08:00
Evan Wilde
8b80331c3d Updating tests to use actor
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
2021-02-10 08:09:13 -08:00
Doug Gregor
ae3049f4b9 [Importer] Make sure we drop "WithBlock" as a completion-handler suffix.
Fixes rdar://73641827.
2021-02-09 15:00:32 -08:00
Doug Gregor
e2893cf138 [Concurrency] Disable async imports for Apple APIs deprecated by ~2018.
Implements rdar://73620586.
2021-02-09 14:43:45 -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
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -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
c55b9cc879 Merge pull request #34984 from DougGregor/import-swift-async-name
[Concurrency] Adopt Clang swift_async_name attribute.
2020-12-09 13:05:02 -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
719e2201c8 [Concurrency] Move "extra" text from completion handler parameter to base name.
When a completion-handler parameter has text before, e.g.,
"WithCompletionHandler", put the extra text on the base name rather
than the corresponding parameter. This ensures that we don't lose the
detail from the text, but always put it into a consistent place.
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
abe0308c21 [Concurrency] Adopt Clang swift_async_name attribute.
The new `swift_async_name` attribute allows Clang declarations to specify
their Swift names only for `async` import, which may differ from those used
for importing as a completion handler.

Implements rdar://70111787.
2020-12-06 22:42:24 -08:00
Doug Gregor
18ef1869f3 [Concurrency] Diagnose "try await" with a Fix-It 2020-12-04 00:57: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
Mohammed Al-Dahleh
15d566d4ab SR-13759: FixIt - Insert await on async (#34509) 2020-11-03 08:50:08 -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
Doug Gregor
b094758bd3 Merge pull request #34394 from DougGregor/concurrency-objc-name-adjustments
[Concurrency] Don't lose name information from completion-handler arguments
2020-10-22 16:38:41 -07:00
Doug Gregor
16104d8045 [Concurrency] Don't lose name information from completion-handler arguments.
When a completion handler parameter has a selector piece that ends with
"WithCompletion(Handler)", prepend the text before that suffix to the
base name or previous argument label, as appropriate. This ensures that
we don't lose information from the name, particularly with delegate names.
2020-10-22 13:32:03 -07:00
John McCall
2f0883542f Merge pull request #34388 from rjmccall/import-concurrency
Implicitly import _Concurrency under -enable-experimental-concurrency
2020-10-22 12:06:01 -04:00
Doug Gregor
8521453af3 [Concurrency] Drop "Asynchronously" suffix from imported 'async' methods.
The "Asynchronously" is a needless word for an "async" function. Remove
it.
2020-10-21 21:57:30 -07:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
e1852956a0 [Concurrency] Drop "get" prefix when importing Objective-C methods as async.
Implements rdar://70506634.
2020-10-21 12:33:49 -07:00