Specifically, this means importing getters defined via swift_async_name. This
just ensures that they are treated just like any other imported objc async
function with completion handler.
rdar://156985950
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
Such references used to be downgraded until Swift 6 but since the
context is `@preconcurrency` it should be possible for API authors
to introduce concurrency annotations such as `@Sendable` without
breaking clients even when they are compiled in Swift 6 mode.
Resolves: rdar://157061896
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.
rdar://151802975
I tried to port this behavior to another test that validated the behavior using
RBI. When I tried to do so I ran into the issue that the behavior in this test
only reproduces in targeted mode not in complete mode which is required for rbi
to run.
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.
subclassing.
These features are additive, and they don't need to be gated behind the
`GlobalActorIsolatedTypesUsability` upcoming feature. The other inference
changes, including `@Sendable` inference for global-actor-isolated function
types, and global-actor inference on protocol refinements, remain gated
behind the upcoming flag.
`TypeChecker::containsProtocol` shouldn't propagate user-provided
`allowMissing` to existential superclass check because the type
could be `& Sendable` and `allowMissing` propagation would result
in invalid builtin conformance returned for a non-conforming
superclass.
Remarks are intended to be enabled via eg. `-R...`, where as
`(add|remove)_predates_concurrency_import` is a diagnostic that's always
output without any `-R` flag. Move it to a warning instead.
Resolves rdar://114207080.
actor isolation.
Adding global actor isolation via subclassing admits data races because
actor-isolated types are Sendable while nonisolated classes are not (unless
otherwise annotated), so this allowed bypassing Sendable checking.
Swift 5 mode.
When you annotate a ValueDecl with `@preconcurrency`, the compiler should allow
concurrency violations by downgrading errors in the actor isolation checker to
warnings in Swift 5 mode. Previously, the actor isolation checker only checked
whether the caller's context was preconcurrency when deciding to downgrade, so
referencing preconcurrency declarations directly remained errors. Preconcurrency
was also dropped when computing actor isolation for declarations imported from
clang, which are always preconcurrency.
The move to perform all call checking that can cross concurrency
domains into one place dropped the specific logic for distributed
actor calls. Introduce that logic, cleaning it up to consistently use
the "known to be local" semantics needed for distributed actors.
`@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.
Much like how we do for an isolation mismatch for a call within
a closure that is `@preconcurrency`, references should also only
warn about the isolation issue too.
The reason why there is a mismatch is that the completion-handlers
are considered `@Sendable`, which disables the isolation inheriting
behavior of other, non-Sendable closures.
resolves rdar://96830159
When determining whether a superclass conforms to a particular protocol,
skip unavailable conformances. This way, we don't minimize away a
constraint that might only apply to subclasses of the specified
superclass.
Fixes rdar://91853658.
In C, one can provide a typedef name for an anonymous tag declaration in
one shot, e.g.,
typedef struct {
double x, y
} Point;
In this case, there are effectively two declarations at the C level:
the typedef and the struct. The Clang importer was only taking
attributes from the anonymous struct (i.e., the tag) and not from the
typedef. However, any attributes put before the `typedef` should apply
as well... so consider those, too.
For now, only do this for `swift_attr` attributes, because we're
seeing this primarily with `Sendable` annotations. In the future, we
can look to generalizing it, but that could have source-breaking
consequences.
Fixes rdar://91632960.
The three options are now:
* `explicit`: Enforce Sendable constraints where it has been explicitly adopted and perform actor-isolation checking wherever code has adopted concurrency. (This is the default)
* `targeted`: Enforce Sendable constraints and perform actor-isolation checking wherever code has adopted concurrency, including code that has explicitly adopted Sendable.
* `complete`: Enforce Sendable constraints and actor-isolation checking throughout the entire module.
`isConcurrencyChecked()` was being used as a proxy for
`-warn-concurrency` that didn't account for Swift 6. Replace
checks against it within the current module with checks against the
strict concurrency level, which subsumes the Swift 6 check and can
account for the difference between "limited" and "on".
`isConcurrencyChecked()` is used now used exclusively to mean "treat a
missing Sendable conformance as an explicitly-non-Sendable type".
There were some tests that relied on the top-level code not being an
asynchronous context to emit certain error messages. Now that it is,
those tests weren't emitting the expected error message.
In other cases, the issue was that they were trying to initialize a
global variable and weren't really using top-level code as top-level
code, so adding `-parse-as-library` was sufficient for the testing
purposes.
To fix the objc_async test, parsing as a library was nearly sufficient.
Unfortunately, the little `if #available` trick that I was using stopped
working since it relied on being in top-level code. So that we emit the
unavailableFromAsync error message, I had to set the availability on
everything correctly because we can't just disable availability
checking.
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.
During actor isolation inference, we would unconditionally choose the
isolation of the overridden decl (when, say, there is no attribute on the decl).
The overridden decl is identified with `getOverriddenDecl`.
This works mostly fine, but initializers have some unusual overridden decls
returned by that method. For example, in the following code:
```swift
@objc class PictureFrame: NSObject {
init(size: Int) { }
}
@MainActor
class FooFrame: PictureFrame {
init() {
super.init(size: 0)
}
}
```
that method claims that `FooFrame.init()` overrides `PictureFrame.init()`, when
it really does not! So, if we were to unconditionally take the isolation from
`PictureFrame.init()` (and thus `NSObject.init()`), then we'd infer that
`FooFrame.init()` has unspecified isolation, despite the nominal it resides in
being marked as `MainActor`. This is in essence the problem in SR-15694, where
placing the isolation directly on the initializer fixes this issue.
If `FooFrame.init()` really does override, then why can it be `MainActor`? Well,
we have a rule in one part of the type-checker saying that if an ObjC-imported
decl has unspecified isolation, then overriding it with isolation is permitted.
But the other part of the type-checker dealing with the isolation inference was
not permitting that.
So, this patch unifies how actor-isolation inference is conducted to reuse that
same logic. In addition, the inference now effectively says that, if the decl
has no inferred isolation, or the inferred isolation is invalid according to the
overriding rules, then we use the isolation of the overridden decl. This
preserves the old behavior of the inference, while also fixing this issue with
ObjC declarations by expanding where isolation is allowed.
For example, as a consequence of this change, in the following code:
```swift
@MainActor
class FooFrame: NotIsolatedPictureFrame {
override func rotate() {
mainActorFn()
}
}
```
if `NotIsolatedPictureFrame` is a plain-old not-isolated class imported from
Objective-C, then `rotate` will now have `MainActor` isolation, instead of
having unspecified isolation like it was inferred to have previously. This
helps make things consistent, because `rotate` is allowed to be `@MainActor` if
it were explicitly marked as such.
resolves rdar://87217618 / SR-15694
Introduce the `@preconcurrency` attribute name for `@_predatesConcurrency`,
which has been the favored name in the pitch thread so far. Retain the
old name for now to help smooth migration.
Extend the implicit Sendable request to produce an inherited
conformance when queried, rather than depending on the conformance
lookup table to always have the right entries. This acknowledges that
implicit Sendable needs to happen more at the type checking level than
the name-binding level, which is needed to eliminate cyclic
dependencies.
Adding the ability to add an optional message to the unavailable from
async attribute. This can be used to indicate other possible API to use,
or help explain why it's unavailable.
Rather than only checking the sendability of captures at the point of
use, diagnose captures uniformly for the closure as a whole. Fixes a
case where we were missing a diagnostic due to an explicit capture,
rdar://85988937.
This patch adds a bunch of tests to verify the behaviour of the
@_unavailableFromAsync attribute.
The attribute is only allowed on functions, so we verify that an error
is emitted when it is applied to structs, extensions, classes, and
actors. The attribute may be applied to constructors to disallow
construction in an async context, but cannot be applied to destructors
since a destructor must be callable from anywhere. Additionally, the
attribute cannot be applied to asynchronous functions since an async
function _must_ be called from an async context.
Specific checks include
- Errors are emitted in an async context (global function, e.g.)
- Errors are emitted when the async context is nested in a sync context
- Errors are not emitted from a sync context nested in an async context
This patch also includes verification that the attribute is propagated
across module boundaries and is be imported from ObjC functions.
Lastly, this patch adds the IDE completion testing to verify that the
attribute is considered.
I'm re-enabling availability checking in the
test/ClangImporter/objc_async.swift test because I want to perform an
availability check in the future.
In re-enabling it, I came across a warning with a fixme and a test
failure on the line. Given that the expected warning has a fixme and is
currently filled in with "something about missing conformance", I think
this is the warning message that they were looking for. Supplying that
gets the test passing with availability-checking enabled.
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.
This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.