Commit Graph

17 Commits

Author SHA1 Message Date
Jamie
96ee7a0ffb [Sema]: Fix data race safety hole with mutable statics within actors
Update the concurrency typechecking logic to remove a check that allowed
mutable static variable declarations nested within an Actor type to be
ignored when diagnosing mutable non-Sendable state.
2025-02-15 10:29:40 -06:00
Горбенко Роман
2c1e45a598 Changed note main actor variables 2024-07-20 02:39:33 +02: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
e1a4a1e8e6 Don't diagnose accesses to global/static variables within the same module
When SE-0412 (strict concurrency for global variables) is enabled, each
global or static mutable variable will be diagnosed if it isn't
explicitly on a global actor or `nonisolated(unsafe)`.

Suppress diagnostics for references to such global variables when they
are in the same module as the declaration of the global variable
itself. While these diagnostics are technically correct, they are not
strictly necessary since we've already diagnosed the global variable
itself (with more actionable advice), and they tend to pile on the
developer in a manner that is not helpful.
2024-05-19 18:35:19 -07:00
Doug Gregor
d4ce618e2f Provide more Fix-It guidance for concurrency-unsafe global variables (SE-0412)
When diagnosing a concurrency-unsafe global or static variable, provide
Fix-Its with specific guidance and advice. This is intended to aid the
workflow for folks enabling strict concurrency checking or Swift 6.
There are up to three Fix-Its attached to a diagnostic about
concurrency-unsafe global/static variables:

* convert 'global' to a 'let' constant to make the shared state
immutable, which replaces `var` with `let`
* restrict 'global' to the main actor if it will only be accessed from the
main thread, which adds `@MainActor`
* unsafely mark %0 as concurrency-safe if all accesses are protected
by an external synchronization mechanism, which adds `nonisolated(unsafe)`

I fretted over two things before deciding on this path:

1. For the second note, the reality is that any global actor will
suffice, but `@MainActor` is orders of magnitude more common than any
other global actor, so "common case convenience" wins over "precise
but less useful.
2. For the third note, `nonisolated(unsafe)` should only be used
sparingly, and surfacing it via Fix-It could cause overuse. However,
developers need to know about it, and this is how we do that. It comes
last in the list of notes (after the better options) and says "unsafe"
in not one but two places.
2024-05-19 15:05:39 -07:00
Doug Gregor
fc85f98460 Respect @preconcurrency in check of nonisoalted let variables 2024-05-16 21:47:39 -07:00
Doug Gregor
94a2529609 Teach diagnostic about non-Sendable global lets to respect @preconcurrency
The diagnostic for non-Sendable globa/static `let` properties was checking
for a Sendable conformance without considering `@preconcurrency`. Emit
this diagnostic via a `@preconcurrency`-sensitive path.

Fixes rdar://121889248.
2024-05-16 11:24:22 -07:00
Sima Nerush
a5eff6b69e [Concurrency] Diagnose redundant nonisolated(unsafe) for an actor-isolated Sendable immutable storage. 2024-03-12 22:19:53 -07:00
Sima Nerush
e2f9267012 [Concurrency] Diagnose redundant (unsafe) for a public actor-isolated Sendable immutable storage. 2024-03-12 22:19:53 -07:00
Sima Nerush
9fc5b7ecb1 [Concurrency] Diagnose redundant nonisolated(unsafe) for a Sendable immutable storage. 2024-03-12 22:19:48 -07:00
Holly Borla
c0486c38a4 [Concurrency] Improve the diagnostics for unsafe immutable global and
static variables.
2024-03-06 21:12:11 -08:00
Holly Borla
a24fe7c2aa [Concurrency] Suppress unsafe global variable warnings when the variable is from
a `@preconcurrency` import.
2024-03-04 18:19:08 -08:00
Holly Borla
f1cd9cb422 [Test] Remove REQUIRES: asserts from tests that use -swift-version 6. 2024-02-13 07:13:35 -08:00
Holly Borla
009d7d0c70 [Concurrency] nonisolated can only be applied to actor properties with
`Sendable` type.
2024-01-26 08:54:28 -08:00
Sophia Poirier
073f541734 [Concurrency] promote GlobalConcurrency from experimental to future feature 2024-01-06 19:07:23 -08:00
Sophia Poirier
223a9eeb11 [Concurrency] split global variable tests from experimental feature strict concurrency tests 2024-01-06 11:00:30 -08:00