Commit Graph

110 Commits

Author SHA1 Message Date
Michael Gottesman
df2844d267 [concurrency] Cleanup verify-additional-prefix usage in tests.
This includes a bunch of fixes. It is not exhaustive but fit my time boxed time
period I set aside to look at this today.

A quick non-exhaustive list:

1. I removed unnecessary verify-additional-prefix lines.
2. Split tests with typechecker error and non-typechecker error components.
3. Removed complete- lines that we used when testing w/without send
non sednable.
4. Translated complete-and-tns- lines to be just complete- since they are just
testing strict-concurrency=complete and we are not testing complete without
send non sendable anymore.
2025-08-12 10:56:02 -07:00
Michael Gottesman
d7e6054dc9 [concurrency] Remove from test RUN lines uses of enable-upcoming-feature RegionBasedIsolation when it is already inferred from strict-concurrency=complete. 2025-08-08 19:04:07 -07:00
Michael Gottesman
bf78c6206b Revert "[flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits"
This reverts commit 501bad55a8.
2025-06-17 13:01:28 -07:00
Michael Gottesman
501bad55a8 [flow-isolation] Allow for initialization of fields of a Global Actor isolated class in its nonisolated inits
This just involved loosening some checks in the type checker so we stopped
erroring in the type checker and instead deferred to SIL level checks.

rdar://131136194
2025-06-02 08:37:05 -07:00
Pavel Yaskevich
9e562881fe [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
2025-05-23 00:20:18 -07:00
Doug Gregor
3f1a6c84c2 Update tests for isolated conformances being enabled by default 2025-04-13 15:41:57 -07:00
Doug Gregor
1b1f28decb Tighten up diagnostics wording a bit 2025-03-20 22:13:19 -07:00
Doug Gregor
9ea735b9ed Rework diagnostics for conformance isolation failures
A protocol conformance can be ill-formed due to isolation mismatches
between witnesses and requirements, or with associated conformances.
Previously, such failures would be emitted as a number of separate
errors (downgraded to warnings in Swift 5), one for each witness and
potentially an extra for associated conformances. The rest was a
potential flood of diagnostics that was hard to sort through.

Collect all of the isolation-related problems for a given conformance
together and produce a single error (downgraded to a warning when
appropriate) that describes the overall issue. That error will have up
to three notes suggesting specific courses of action:
* Isolating the conformance (when the experimental feature is enabled)
* Marking the witnesses as 'nonisolated' where needed
*

The diagnostic also has notes to point out the witnesses/associated
conformances that have isolation problems. There is a new educational
note that also describes these options.

We give the same treatment to missing 'distributed' on witnesses to a
distributed protocol.
2025-03-20 21:23:16 -07:00
Doug Gregor
cd99fb57fd [Diagnostics] Remove unhelpful notes from witness-isolation diagnostics
When diagnosing an isolation mismatch between a requirement and witness,
we would produce notes on the requirement itself suggesting the addition of
`async`. This is almost never what you want to do, and is often so far
away from the actual conforming type as to be useless. Remove this note,
and the non-function fallback that just points at the requirement, because
they are unhelpful.

This is staging for a rework of the way we deal with conformance-level
actor isolation problems.
2025-03-19 17:18:52 -07:00
Anthony Latsis
e626887dcc Sema: Improve requirement indicator note for actor_isolated_witness
`x declared here` is not helpful and clear enough, especially when there
are other notes attached. Swap it for a new note that says
`requirement x declared here`.
2025-01-14 14:52:41 +00:00
Anthony Latsis
f85eb97337 ConformanceChecker: Make actor_isolated_witness call out the protocol 2025-01-14 14:49:22 +00:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
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.
2024-11-02 11:46:46 -07:00
Holly Borla
5fa35b5c3e [Concurrency] Compute the source of actor isolation in ActorIsolationRequest. 2024-08-04 18:48:57 -07:00
Michael Gottesman
474aa47732 [concurrency] Standardize sending of non-isolated -> nonisolated to match the keyword 'nonisolated'.
rdar://130827967
2024-06-29 18:09:38 -07:00
Doug Gregor
5a0e70a2bc Update diagnostic text to address code review feedback 2024-05-20 22:06:40 -07:00
Doug Gregor
640042f396 Suggest @preconcurrency on conformances it could help
When diagnosing a case where an actor-isolated witness cannot satisfy
a non-isolated requirement, also suggest that the conformance could be
annotated with `@preconcurrency`.
2024-05-20 22:06:40 -07:00
Michael Gottesman
de85b79423 [concurrency] Make GlobalActorIsolatedTypesUsability an upcoming swift 6 feature.
rdar://118244451
2024-05-13 18:40:58 -07:00
Holly Borla
87f49a5571 [Concurrency] Allow isolation on subclasses of non-Sendable, non-isolated
superclasses.
2024-05-07 15:40:01 -07:00
Sima Nerush
05859b442c [Features] Gate global-actor-isolated types usability changes behind an experimental feature flag. 2024-03-23 20:03:01 -07:00
Sima Nerush
043cc26661 [Concurrency] Infer nonisolated for a mutable storage of a value type accessed from within the module. 2024-03-23 20:01:45 -07:00
Michael Gottesman
99e3f7fb13 [region-isolation] Make RegionBasedIsolation an upcoming feature for swift 6.
To make the tests pass, I had to teach sil-opt how to setup upcoming features
since it did not know how to parse them.

rdar://124100266
2024-03-05 15:15:14 -08:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Holly Borla
ecd94e4908 [Concurrency] Diagnose @GlobalActor(unsafe) attributes with a fix-it to use
`@preconcurrency` instead.

This diagnosic is a warning until Swift 6, and it's ignored in swiftinterfaces.
2024-01-21 21:05:33 -08:00
Holly Borla
20829faa43 [Concurrency] Handle cases where a property initializer is subsumed by another
property for IsolatedDefaultValues.

For property wrappers and init accesors, skip property initializers that are
subsumed, e.g. by an init accessor or a backing property wrapper initializer,
and always consider the subsuming initializer to determine whether compiler
synthesized initializers should have `nonisolated` applied.

This change also lessens the source break of SE-0411 by still emitting
member initializers in implicit constructors when the initializer violates
actor isolation to preserve the behavior of existing code when concurrency
diagnostics are downgraded to warnings in Swift 5 mode.
2024-01-19 18:12:25 -08:00
Holly Borla
a1a975f528 Merge pull request #71002 from hborla/preconcurrency-downgrade-take-two
[Concurrency] Set `preconcurrency` for actor isolation created from unsafe global actor attributes.
2024-01-19 15:39:52 -08:00
Holly Borla
79593411d9 [Concurrency] Set preconcurrency for actor isolation created from unsafe global
actor attributes.
2024-01-19 09:29:13 -08:00
Holly Borla
b99995c2b2 [Concurrency] Downgrade isolated_default_argument_context to a warning until
Swift 6 for stored properties.
2024-01-16 10:47:52 -08:00
Holly Borla
e47a66cc33 [Concurrency] Enable IsolatedDefaultValues under strict concurrency checking. 2024-01-10 20:53:42 -08:00
Pavel Yaskevich
dbf1146963 [Concurrency] NFC: Switch tests to use -strict-concurrency=complete instead of -warn-concurrency 2023-12-08 14:10:51 -08:00
Holly Borla
275d78342f [Concurrency] Compute actor isolation for var decls before checking
decl attributes.
2023-12-04 17:36:59 -08:00
Michael Gottesman
cb46851194 [region-isolation] Rename the experimental feature to RegionBasedIsolation.
This ensures that the pass is called TransferNonSendable but the experimental
feature is RegionBasedIsolation.
2023-10-26 12:01:44 -07:00
Michael Gottesman
0bad8f9b67 [region-isolation] Rename SendNonSendable.cpp -> TransferNonSendable.cpp. 2023-10-26 12:01:44 -07:00
Holly Borla
0b1e2feaad [Concurrency] Don't allow initializing global actor isolated stored
properties with non-Sendable type from across isolation boundaries.
2023-10-18 20:47:30 -07:00
Holly Borla
c9bfe8c3dd [Concurrency] Don't allow subclasses of nonisolated classes to add global
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.
2023-10-11 12:41:00 -07:00
Michael Gottesman
b53af9419c [send-non-sendable] Add REQUIRES: asserts to concurrency tests that use SendNonSendable. 2023-08-31 19:25:23 -07:00
Michael Gottesman
026f1735b5 [send-non-sendable] Update concurrency tests so that we run them in all concurrency modes as appropriate.
This means that:

1. In test cases where minimal is the default (swift 5 without
-warn-concurrency), I added RUN lines for targeted, complete, and complete +
sns.

2. In test cases where complete is the default (swift 6, -warn-concurrency,
specified complete with -strict-concurrency), I added a send non-sendable run
line.

In each of these cases, I added additional expected-* lines as appropriate so
the tests can compile in each mode successfully.
2023-08-30 13:40:17 -07:00
Doug Gregor
d78a5edb99 Handle all isolation checking for function calls in one place
Isolation checking for calls had two separate implementation places:
one that looked at the declaration being called (for member
declarations) and one that worked on the actual call expression. Unify
on the latter implementation, which is more general and has access to
the specific call arguments. Improve diagnostics here somewher so we
don't regress in that area.

This refactoring shouldn't change the actual semantics, but it makes
upcoming semantic changes easier.
2023-06-26 13:39:56 -07:00
Suyash Srijan
b30cc9dc1c [Sema] Diagnose 'nonisolated' attribute on wrapped properties (#60475)
* [Sema] Diagnose 'nonisolated' attribute on wrapped properties

* [AST] Update diagnostic wording for nonisolated_wrapped_property
2022-08-10 20:51:49 +01:00
Suyash Srijan
ad26df09ab Revert "[Sema] Propagate nonisolated attribute from wrapped property to the synthesized projectedValue property (#60421)" (#60462)
This reverts commit 2aa47b86dd.
2022-08-09 19:29:35 +01:00
Suyash Srijan
2aa47b86dd [Sema] Propagate nonisolated attribute from wrapped property to the synthesized projectedValue property (#60421)
* [Sema] Propagate nonisolated attribute from wrapped variable to the synthesized projectedValue variable

* [Test] Add some test cases
2022-08-09 01:40:22 +01:00
hank121314
c05afe20f0 test[Concurrency]: Add test to make sure actor isolation checking is performing in visitPatternBinding. 2022-06-21 11:19:11 +08:00
Doug Gregor
fdc6260bc1 Reimplement conformance isolation checking using the actor reference logic.
Reimplement the final client of ActorIsolationRestriction, conformance
isolation checking, to base it on the new "actor reference" logic.
Centralize the diagnostics emission so we have a single place where we
emit the primary diagnostic (which is heavily customized based on
actor isolation/distributed/etc.) and any relevant notes to make
adjustments to the witness and/or requirement, e.g., adding
'distributed', 'async', 'throws', etc. Improve the diagnostics
slightly by providing Fix-Its when suggesting that we add "async"
and/or "throws".

With the last client of ActorIsolationRestriction gone, remove it
entirely.
2022-04-07 17:10:02 -07:00
Doug Gregor
1b27c48cc6 Switch non-member actor isolation checking to the new implementation 2022-04-07 09:07:37 -07:00
Doug Gregor
eef2704c86 Reimplement actor isolation checking for referencing a declaration.
Start collapsing the several implementations of actor isolation checking
into a single place that determines what it means to reference a declaration
from a given context, potentially supplying an instance for an actor. This
is partly cleanup, and partly staging for the implementation of the
Sendable restrictions introduced in SE-0338. The result of this check
falls into one of three categories:

* Reference occurs within the same concurrency domain (actor/task)
* Reference leaves an actor context to a nonisolated context (SE-0338)
* Reference enters the context of the actor, which might require a
combination of implicit async, implicit throws, and a "distributed" check.

Throughout this change I've sought to maintain the existing semantics,
even where I believe they are incorrect. The changes to the test cases
are not semantic changes, but reflect the unification of some
diagnostic paths that changed the diagnostic text but not when or how
those diagnostics are produced. Additionally, SE-0338 has not yet been
implemented, although this refactoring makes it easier to implement
SE-0338.

Use this new actor isolation checking scheme to implement the most
common actor-isolation check, which occurs when accessing a member of
an instance.
2022-04-07 09:07:36 -07:00
Kavon Farvardin
9b1fcedf2f backtrack on part of SE-327 dealing with default-value exprs
This effectively reverts 6823744779

The blanket removal of isolation in default-value expressions had
unintented consequences for important workflows. It's still
a problem that needs to be addressed, but we need to be more precise
about the problematic situations.
2022-03-18 18:41:05 -07:00
Kavon Farvardin
13dd3d9ecf have the inferred isolation for properties change only in Swift 6
This patch delays the removal of redundant isolation for inferred
global-actor isolation to Swift 6 too, since we only warn about it
changing in Swift 5. Otherwise, only isolation that is a byproduct
of inference no longer needs an await, which will probably confuse
people.

This change is with respect to SE-327, which argues that the
non-static stored properties of ordinary structs do not need
global-actor isolation.
2022-02-04 14:43:12 -07:00
Kavon Farvardin
19bdfb1172 In a property-wrapper, global-actor isolation remains on wrappedValue
If a struct is a property-wrapper, then global-actor isolation
still applies to the `wrappedValue`, even if it's a stored property.
This is needed in order to support the propagation of global-actor
isolation through the wrapper, even when the programmer has opted
to use a stored property instead of a computed one for the
`wrappedValue`. Since this propagation is a useful pattern, I think
this exception is reasonable.
2022-02-04 14:41:49 -07:00
Kavon Farvardin
a60da756cf fix bug with unidentified custom attribute during serialization
In Swift 5 mode, I only warned about the global-actor attribute
becoming unnecessary in the future, yet I was still returning
None for the global-actor attribute checking request. This led
to the attribute remaining unidentified, but also not removed.
During module serialization, this problem was manifesting as
emitting a typeless attribute, which when deserialized would
trigger a segfault.
2022-02-04 14:41:31 -07:00
Kavon Farvardin
bd024caca9 [SE-327] Remove redundant global-actor isolation.
As part of SE-327, global-actor isolation applied to
the instance-stored properties of a value type do
not require any isolation, since there is no way to
create a race on access to that storage.

https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md#removing-redundant-isolation

This change turns global-actor annotations on such
properties into an error in Swift 6+, and a warning
in Swift 5 and earlier.

In addition, inference for global-actor isolation
no longer applies global-actor isolation to such
properties. Since this latter change only results
in warnings in existing Swift 5 code, about a now
superflous 'await', this change will happen in
Swift 5+.

Fixes rdar://87568381
2022-02-03 15:19:59 -07:00
Doug Gregor
7149702d12 Rename @_predatesConcurrency to @preconcurrency.
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.
2022-01-26 08:39:01 -08:00