@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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
`@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.
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.
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)