The core part of the check runs as follows
1. Are we in an async context
2. Does the decl we're calling have the unavailableFromAsync attribute
3. Emit a diagnostic
There are a couple challenges that muddy the implementation. First,
single-expression closures are typechecked differently than
multi-expression closures. The single-expression closure is never added
to the closure stack. We have to record it separately upon entry to
verify separately. This is necessary for `_ = { foo() }()` where `foo`
is unavailable from async, and the surrounding context is async.
The second challenge is regarding when things get typechecked. A type
must be assigned to AbstractClosureExprs to determine whether they are
an async context or not. Unfortunately, availability checking runs
before types are fully assigned in some cases. This specifically happens
when working with result builders in specific conditions. I haven't been
able to figure out how to reduce the issue further.
Some notes:
1. This is not actually wired up to any part of codegen. Instead, this PR just
has the code necessary to parse the attribute and to ensure that we use it only
on local lets. The rest will come in subsequent commits.
2. I am allowing for the attribute to be attached to generic things in Sema
since we do not have enough information in the TypeChecker to distinguish in
between structs with a type parameter but that have all non-generic stored vars
from one with generic stored vars. We can only support the later with opaque
values but the former we can support without opaque values (and is one of the
use cases we are interested in).
rdar://83957088
This attribute creates an unavailable extension with a `Sendable` conformance so that the type is explicity marked as not being `Sendable`.
We also fully suppress diagnostics about unavailable Sendable conformances in Swift 5 mode code. (This is not fully developed yet—it should return to being a warning in concurrent contexts.)
The behavior when a @_nonSendable and a Sendable conformance are both on the same type is also not right yet.