Commit Graph

46 Commits

Author SHA1 Message Date
Michael Gottesman
3ed4059a60 [sema] Change non-sendable -> non-Sendable in diagnostics.
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
2025-05-22 11:37:58 -07:00
Mykola Pokhylets
5ac1cba8d1 Handle versioning of the IsolatedDeinit feature 2024-12-12 16:41:02 +09:00
Mykola Pokhylets
bc80529d02 Revert "Merge pull request #77438 from swiftlang/revert-77364-mpokhylets/non-experimental-isolated-deinit"
This reverts commit 11781a5fd1, reversing
changes made to 2ee2f1eb2c.
2024-12-12 16:41:02 +09:00
Konrad `ktoso` Malawski
aadc67ec0e Revert "Make IsolatedDeinit non-experimental" 2024-11-07 09:59:00 +09:00
Mykola Pokhylets
c139d1b1a7 Make IsolatedDeinit non-experimental 2024-11-05 12:19:01 +01: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
Konrad `ktoso` Malawski
e345665dd4 add experimental flag to 3 more tests 2024-09-22 22:58:13 +09:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Горбенко Роман
2c1e45a598 Changed note main actor variables 2024-07-20 02:39:33 +02:00
Mykola Pokhylets
816d62c972 Merge remote-tracking branch 'upstream/main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/SILGen/SILGenDestructor.cpp
#	test/Concurrency/flow_isolation.swift
#	test/abi/macOS/arm64/concurrency.swift
#	test/abi/macOS/x86_64/concurrency.swift
2024-07-11 13:11:59 +02:00
Mykola Pokhylets
4d0b624866 Make deinit non-isolated by default
Failing: Distributed/Runtime/distributed_actor_deinit.swift
2024-07-11 13:09:08 +02:00
Mykola Pokhylets
62dbc6c966 Fixed some tests. Using extract_executor SIL instruction instead of custom code. 2024-07-11 13:09:06 +02:00
Mykola Pokhylets
698e5e688a Enabled isolated deinit in Sema 2024-07-11 13:09:05 +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
Slava Pestov
c270597fd0 SIL: Fix false positive in FlowIsolation with DynamicSelfType usage
If an instruction references the DynamicSelfType by calling a
static member with `Self.foo()`, we consider this a type-dependent
use of `self`. This means that at runtime we may need to load the
isa pointer, but we don't need to touch any other protected state
from the instance.

Therefore, we can skip type-dependent uses in the analysis to
avoid false positives in this case.

An existing test case already exercised the overly-conservative
behavior, so I just updated it to not expect an error.

Fixes rdar://129676769.
2024-06-12 12:01:18 -04: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
c326fd3db2 Respect @preconcurrency for instance properties of non-sendable types in deinit
Instance properties of non-sendable types cannot safely be
accessed within deinitializers. Make sure we respect `@preconcurrency`
when diagnosing these.
2024-05-16 22:42:54 -07:00
Holly Borla
425b8052c7 [Concurrency] Don't diagnose 'nonisolated(unsafe)' properties during flow isolation. 2024-04-26 17:31:25 -07:00
Nate Chandler
373cc84329 [SILGen] Move non-trivial none-ownership values.
All non-trivial values which correspond to `VarDecl`s must be marked
appropriately so that they can be found by the relevant checker.  Here,
values with none ownership are marked.
2024-03-09 23:19:30 -08: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
Pavel Yaskevich
4275bbd632 [SILOptimizer] FlowIsolation: Teach analysis to recognize use of init accessor properties
Init accessor properties should be handled specifically because
they do not reference underlying storage directly via `ref_element_addr`
instructions when 'self' is fully initialized.
2024-02-07 09:30:41 -08:00
Pavel Yaskevich
e4d2d51f2c [Concurrency] memberAccessHasSpecialPermissionInSwift5 should treat init accessors as stored properties
Init accessor properties cannot escape self and are only allowed
to initialized and access a set of properties declared in their
`@storageRestrictions(...)` attribute.

Resolves: https://github.com/apple/swift/issues/70550
2024-02-07 09:30:40 -08:00
Pavel Yaskevich
e6b3f92a00 [Tests] NFC: Un-XFAIL flow_isolation tests 2024-02-06 09:31:50 -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
Holly Borla
fcbe5593a3 Merge pull request #70871 from hborla/fix-complete-concurrency-flags
[Concurrency] Promote `StrictConcurrency` to an upcoming feature flag.
2024-01-12 09:41:58 -08:00
Holly Borla
d37b9763b6 [Concurrency] Promote StrictConcurrency to an upcoming feature flag. 2024-01-11 21:23:25 -08:00
Allan Shortlidge
ed6322cd81 Disable Concurrency/flow_isolation.swift. 2024-01-11 09:16:43 -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
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
Kavon Farvardin
41134ea8a0 Remove the need for convenience on actor inits to delegate.
This is possible because actors do not support inheritance. There
is one specific exception to that rule, which is that an actor
can inherit from `NSObject` just to support ObjC interop.

This means an actor is effectively a final class.

resolves rdar://87568153
2022-06-27 16:01:08 -07:00
Kavon Farvardin
3211bd8260 Emit Sendable diagnostics in actor-like deinits only in 'complete' checking mode
The flow-isolation pass was not respecting the new strict-concurrency checking mode.
Since the Sendable diagnostics in these deinits are very noisy, I'm moving them to only
be emitted in 'complete' mode. The reason why they're so noisy is that any class that
inherits from a `@MainActor`-constrained class will have these diagnostics emitted when
trying to access its own `@MainActor`-isolated members.

This is needed, even during the `deinit`, because multiple instances of a `@MainActor`-isolated
class might have stored properties that refer to the same state.

This change specifically avoids emitting these diagnostics even in 'targeted' mode because
I'd like to take more time to reconsider the ergonomics of these deinits.

resolves rdar://94699928
2022-06-15 12:01:59 -07:00
Kavon Farvardin
9604304586 Downgrade more errors into warnings for actor inits.
In the replacement of the escaping-use restriction with
flow-isolation, I hadn't accounted for all of the situations
where the isolation changes would break backwards compatability
with Swift 5.5 programs. The escaping-use restriction permitted
a lot of very unsafe things with warnings that it would become
an error in Swift 6.

With the introduction of flow-isolation, it was a bit tricky to
get the right warnings back in place, while not unnessecarily
warning about property accesses that might actually be OK. There
is a very careful coordination between the type-checker and
the flow-isolation pass.

While I had done these downgrades for deinits, I also needed to
do them for inits as well, because member accesses to isolated
methods within actor initializer were still getting rejected
as an error. This patch should be pretty solid now.

fixes rdar://90595278
2022-03-22 14:38:02 -07:00
swift-ci
36a8058c99 Merge pull request #41375 from kavon/unsegfault-flowiso
fix flow-isolation diagnostic message crash
2022-02-17 17:43:02 -08:00
Kavon Farvardin
088a72c772 beef up the test 2022-02-17 17:05:27 -07:00
Kavon Farvardin
1343f6b97e fix busted assumption about decl context
When emitting the note to point out what introduced
nonisolation, the code building the message assumed that
`DeclContext::getDecl` will not return null, when it can
if it's a closure expression.

fixes rdar://88776902
2022-02-17 16:47:42 -07:00
Kavon Farvardin
a70ed0ffc3 permit isolated-member references in actor deinits with warning
This capability was available in Swift 5.5, but with flow-isolation
it's not safe to do so in general. When I initially implemented
flow-isolation, I intended for it to not break too much existing
code, and emit warnings about things changing in Swift 6. But
I missed this case, where we have just a simple method call in
a deinit, which is likely to be common:

```swift
actor A {
  func cleanup() { ... }
  deinit {
    cleanup()
  }
}
```

Instead of rejecting that call to `cleanup`, we now warn that it's
not going to be allowed in Swift 6, because `cleanup` is isolated
and the deinit is not.
2022-02-09 15:43:37 -07:00
Kavon Farvardin
94553fdec9 allow nonisolated + async + delegating actor inits. 2022-02-02 13:31:14 -07:00
Kavon Farvardin
d610493603 fix bugs with actor inits and flow-isolation
This is a combination of fixes:

- inject hops in self-isolated delegating actor initializers
  after self becomes initialized.

- fix sendable and isolation for convenience inits

- fix bug in distributed actor inits that I introduced when
  implementing flow-isolation.

- fix / add test coverage.
2022-02-02 13:31:14 -07:00
Kavon Farvardin
4f28b87de9 basic implementation of flow-isolation for SE-327
Flow-isolation is a diagnostic SIL pass that finds
unsafe accesses to properties in initializers and
deinitializers that cannot gain isolation to otherwise
protect those accesses from concurrent modifications.
See SE-327 for more details about how and why it exists.

This commit includes changes and features like:

- The removal of the escaping-use restriction
- Flow-isolation that works properly with `defer` statements
- Flow-isolation with an emphasis on helpful diagnostics.

It also includes known issues like:

- Local / nonescaping functions are not analyzed by
  flow-isolation, despite it being technically possible.
  The main challenge in supporting it efficiently is that
  such functions do not have a single exit-point, like
  a `defer`. In particular, arbitrary functions can throw
  so there are points where nonisolation should _not_ flow
  out of the function at a call-site in the initializer, etc.

- The implementation of the flow-isolation pass is not
  particularly memory efficient; it relies on BitDataflow
  even though the particular flow problem is simple.
  So, a more efficient implementation would be specialized for
  this particular problem, etc.

There are also some changes to the Swift language itself: defer
will respect its context when deciding its property access kind.

Previously, a defer in an initializer would always access a stored
property through its accessor methods, instead of doing so directly
like its enclosing function might. This inconsistency is unfortunate,
so for Swift 6+ we make this consistent. For Swift 5, only a defer
in a function that is a member of the following kinds of types
will gain this consistency:

- an actor type
- any nominal type that is actor-isolated, excluding UnsafeGlobalActor.

These types are still rather new, so there is much less of a chance of
breaking expected behaviors around defer. In particular, the danger is
that users are relying on the behavior of defer triggering a property
observer within an init or deinit, when it would not be triggering it
without the defer.
2022-02-02 13:31:14 -07:00