Commit Graph

108 Commits

Author SHA1 Message Date
Doug Gregor
5a6f58e686 Teach witness matching to apply minimal/strict diagnostics rules.
This downgrades some errors to warnings in Swift 5 mode, and ensures that
we diagnose all conditions in Swift 6 mode.
2021-12-02 22:24:09 -08:00
Doug Gregor
a77f05f627 Switch @_unsafeSendable and @_unsafeMainActor tests to @_predatesConcurrency 2021-11-18 09:01:31 -08:00
Doug Gregor
3ddf8c6921 Actor isolation inference: @IBAction implies @MainActor(unsafe)
@IBAction calls are always delivered in the main thread, so reflect that
by inferring `@MainActor(unsafe)` for such methods whenever no other
actor isolation is provided.

Implements rdar://84474640.
2021-11-08 16:37:58 -08:00
Doug Gregor
dec3a9a1d9 Propagate actor isolation through dynamic replacement.
Infer actor insolation through dynamic replacement, because we need
the same rules for the original and the replacements.
Fixes rdar://83153816.
2021-11-05 15:37:58 -07:00
Doug Gregor
68418cd660 [SE-0302] Crank up Sendable to also diagnose in-module missing conformances.
Extend the diagnostics for `Sendable` conformances to always diagnose
missing `Sendable` conformances for nominal types that are within the
same module. The intuition here is that if the type is in the same
module, it can be updated and evaluated at the same time as code
requiring the `Sendable` conformance is introduced.

Another part of rdar://78269348.
2021-08-16 14:01:42 -07:00
Doug Gregor
ea5ec22971 Allow a global-actor-isolated class to inherit from a nonisolated one.
Fixes rdar://80902604.
2021-07-30 11:15:01 -07: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
5dc4fcf91e A "defer" block is global-actor-isolated if its context is.
Fixes rdar://80799233.
2021-07-19 13:13:34 -07:00
Doug Gregor
96ced72349 [SE-0316] Check global actor isolation of a class vs. its superclass.
Close an actor-isolation hole where we permitted a class to have a
different global actor isolation than its superclass.
2021-07-01 14:28:39 -07:00
Doug Gregor
9ec20776c9 [SE-0306] Make actors semantically "final".
Treat actors as being semantically `final` throughout the type checker.
This allows, for example, a non-`required` initializer to satisfy a
protocol requirement.

We're leaving the ABI open for actor inheritance should we need it.

Addresses rdar://78269551.
2021-06-30 10:59:49 -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
03f55d7bb4 Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e8ea.
2021-06-03 14:03:57 -07:00
Karoy Lorentey
5925cb2ed8 Merge pull request #37619 from apple/revert-37462-remove-actor-independent
Revert "Remove `@actorIndependent` attribute."
2021-05-25 10:37:51 -07:00
Holly Borla
27f86adee0 Merge pull request #37627 from hborla/local-default-init-wrapper
[Property Wrappers] Always check actor isolation and initializer effects in `PropertyWrapperInitializerInfoRequest`.
2021-05-25 09:43:28 -07:00
Holly Borla
1068494854 [NFC][Test] Add tests for actor isolation checking for local property
wrapper default initializers.
2021-05-24 19:39:14 -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
Holly Borla
b6a3434851 [Concurrency] Emit a tailored note for a missing await if the call is implicitly
asynchronous due to actor isolation.
2021-05-05 11:35:40 -07:00
Holly Borla
8e78c8b35c [CSApply] Propagate 'async' from contextual types to closures, unless the closure
is an argument to a 'reasync' function.
2021-05-05 11:35:40 -07:00
Evan Wilde
d0d9bef703 Merge pull request #37056 from etcwilde/ewilde/fix-await-fixits
[Concurrency] Fix await fix-it placement
2021-04-26 08:12:50 -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
b88e678694 [SE-0306] Disable actor inheritance.
Actor inheritance was removed in the second revision of SE-0306. Remove
the ability to inherit actors.

Note that this doesn't fully eliminate all vestigates of inheritance
from actors. There are simplifications that need to be performed
still, e.g., there's no need to distinguish
designated/convenience/required initializers. That will follow.
2021-04-23 15:08:57 -07:00
Doug Gregor
b9f1e7f626 [Concurrency] Add @_inheritActorContext hidden parameter attribute.
This new attribute can be used on parameters of `@Sendable async` type
to indicate that the closures arguments passed to such parameters
should inherit the actor context where they are formed, which is not
the normal behavior for `@Sendable` closures.

Another part of rdar://76927008.
2021-04-21 15:23:27 -07:00
Doug Gregor
14a311b36e [Global actors] Check calls to global-actor-qualified functions, not references
Check actor isolation of calls to functions with global-actor-qualified
type. This closes a pre-existing loophole where a value of
global-actor-qualified function type could be called from any context.
Paired with this, references to global-actor-qualified function
declarations will get global-actor-qualified function type whenever
they are referenced within an experience, i.e., whenever we form a
value of that type. Such references can occur anywhere (one does not
need to be on the actor), and carrying the global actor along with the
function type ensures that they can only be called from the right
actor. For example:

    @MainActor func onlyOnMainActor() { ... }

    func callIt(_ fn: @MainActor () -> Void) {
      fn() // error: not on the main actor, so cannot synchronously call
           // this wasn't previously diagnosed
    }

    func passIt() {
      callIt(onlyOnMainActor)  // okay to pass the function
                               // used to be an error
    }

While here, fix up some broken substitution logic for
global-actor-qualified function types and "override" actor isolation.
2021-04-16 00:26:39 -07:00
Holly Borla
97ecb9435f [ASTScope] Always skip implicit attributes.
ASTScope only cares about attributes when lookup can be done inside of the
attribute, which isn't the case for implicit attributes because they're
typically built fully type-checked. This also avoids a crash when an
implicit attribute does not have a source range.
2021-04-06 16:38:46 -07:00
Doug Gregor
1f33aa9586 Infer a type's actor isolation from the property wrappers it uses.
Fixes rdar://76252310.
2021-04-05 23:13:52 -07:00
Doug Gregor
f02a01e4f2 Add @_unsafeMainActor corresponding to @MainActor 2021-03-31 09:40:41 -07:00
Doug Gregor
5342706d1c [Actor inference] Infer global actors on a type based on conformances.
If a protocol is stated to be part of a global actor, infer that a type
that conforms to a protocol in its original definition is also part of
that global actor.

Addresses rdar://75992299.
2021-03-29 23:56:45 -07:00
Doug Gregor
1a9b58d9f9 Add support for @actorIndependent on closures.
Closures often end up being implicitly actor-isolated. Allow them to opt
out with `@actorIndependent`, as as other declarations can opt out of
actor isolation.
2021-03-25 22:37:53 -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
dbc021a73f [Concurrency] Don't let "unsafe" inference block other inference.
The presence of an unsafe global-actor attribute on something we can
infer from (e.g., a witnessed protocol requirement or overridden
declaration) was preventing propagation of actor-isolation attributes
from outer scopes. Only take "positive" results from such places.
2021-03-19 00:02:22 -07:00
Doug Gregor
2f2c194272 Adopt 'nonisolated' in many tests, make sure its a modifier 2021-03-07 11:37:57 -08:00
Doug Gregor
f56ba59605 Add 'nonisolated' modifier as the preferred spelling for @actorIndependent 2021-03-07 10:57:35 -08:00
Kavon Farvardin
0c675c74cf Improve error messages for implicitly-async in sync contexts
when an expression that would be validly considered implicitly-async appears
within a sync context, we try to be a bit more specific about the problem
being that it's a sync context.
2021-03-06 10:26:44 -08:00
Doug Gregor
2b6bda269e Update diagnostics in some tests 2021-03-05 00:24:38 -08:00
Doug Gregor
a7c6a1afad Eliminate circular references while checking property wrapper isolation 2021-03-04 22:49:57 -08:00
Doug Gregor
8a4cb8bafd Support actor isolation for property wrappers
Property wrappers can provide global actor isolation based on the
property wrapper type itself (which affects the backing property),
`wrappedValue` (which affects the wrapped property), and
`projectedValue` (which affects the $ property). This allows us to
express, e.g., property wrappers that require accesses to occur on a
particular global actor.
2021-03-04 22:49:57 -08:00
Doug Gregor
1de83ac0da Enforce safe access to unsafe global actor declarations only from "new" code.
Allow references to unsafe global actor-isolated declarations only from
existing code that has not adopted concurrency features (such as
async, @concurrent closures, etc.). This allows declarations that
should be isolated to a global actor to be annotated as such without
breaking existing code (as if isolation was unspecified), while code
that does adopt concurrency will treat the declaration as being part
of that global actor.
2021-03-03 17:59:01 -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
a864c5575f Update remaining test cases 2021-02-24 13:45:11 -08:00
Kavon Farvardin
9342540661 add fix-it to note for "add 'async' to function"
resolves rdar://72313654
2021-02-11 14:44:49 -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
Kavon Farvardin
0d99a30269 Merge pull request #35012 from kavon/concurrency-lib-upgrades
[concurrency] partially implement @MainActor + convenience method for UnsafeThrowingContinuation
2021-01-07 09:49:01 -08:00
Kavon Farvardin
a2c57d13c3 [concurrency] initial declaration of MainActor
Implementation is left as a TODO for now.

Resolves rdar://72161578
Partially resolves rdar://72105129
2021-01-06 15:01:22 -08:00
Doug Gregor
ec2aacefca [Concurrency] Fix actor-isolation override checking with @asyncHandler.
`@asyncHandler` methods can override with a completely different actor
isolation because they will hop to the appropriate actor themselves.
Therefore, allow differing actor isolation when an `@asyncHandler`
method overrides another method, and don't propagate the actor
isolation from the overridden method to the overriding `@asyncHandler`
method.
2021-01-05 17:38:25 -08:00
Doug Gregor
8b9cbe2411 [Concurrency] Always infer actor isolation from overridden declaration.
Infer actor isolation from the overridden declaration unless some other
isolation attribute was explicitly specified directly on that
declaration. This allows type- and extension-level annotations with
a global actor to not break overrides.
2021-01-05 16:59:51 -08:00
Kavon Farvardin
e8dcc979a0 fix-it regression coverage for notes suggesting 'async', '@asyncHandler' and '@GlobalActorType'
Currently, we don't have a fix-it to insert 'async', so I've marked those places
as not expecting a fix-it, until someone goes and implements that (rdar://72313654)
2020-12-14 15:21:27 -08:00