Commit Graph

53 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
df7df7e4c0 Merge pull request #75031 from Sajjon/cyon_typo_batch__test__concurrency
Typos: `test/concurrency`
2024-07-08 14:24:13 +09:00
Michael Gottesman
62c6de7713 [region-isolation] Reuse ActorInstance::lookThroughInsts when computing the actor instance for SILIsolationInfo purposes.
We are already using this routine in other parts of TransferNonSendable to
ensure that we look through common insts that SILGen inserts that do not change
the actual underlying actor instance that we are using. In this case, I added
support for casts, optional formation, optional extraction, existential ref
initialization.

As an example of where this came up is the following test case where we fail to
look through an init_existential_ref.

```swift
public actor MyActor {
  private var intDict: [Int: Int] = [:]

  public func test() async {
    await withTaskGroup(of: Void.self) { taskGroup in
      for (_, _) in intDict {}
      await taskGroup.waitForAll() // Isolation merge failure happens here
    }
  }
}
```

I also added the ability to at the SIL level actual test out this merge
condition using the analysis test runner. I used this to validate that this
functionality works as expected in a precise way.

rdar://130113744
2024-07-06 23:02:11 -07:00
Alexander Cyon
7074c29bf3 [test/concurrency] Fix typos 2024-07-06 13:25:45 +02:00
Michael Gottesman
4697546e09 [sending] Mark Task.init,detached, and friends as sending methods instead of __owned @Sendable so we can capture non-isolated values. 2024-06-21 02:24:03 -07:00
Holly Borla
1a07152ee0 [NFC][Concurrency] Remove -disable-region-based-isolation-with-strict-concurrency
from tests.
2024-06-19 20:48:59 -07:00
Holly Borla
7af38860ed [Concurrency] Deprecate and obsolete AnyActor.
This marker protocol isn't useful for abstracting over actors and distributed
actors because it doesn't have any runtime requirements, so there's no way
to switch to the given actor. Instead, you should use `isolated (any Actor)?`
parameters, and the compiler will compute a local actor value from a
distributed actor using `DistributedActor.asLocalActor`.
2024-05-24 08:57:17 -07:00
Michael Gottesman
a3d95b993d [concurrency] Add REQUIRES: asserts to a test. 2024-04-24 11:32:09 -07:00
Michael Gottesman
2e5b3bc257 [region-isolation] Do not treat functions/class_methods that are isolated to a #isolated as being globally isolated to that.
Instead, we need to consider the isolation at the apply site.

rdar://126285681
rdar://125078448
2024-04-11 16:00:55 -07:00
Meghana Gupta
5934b9466c Disable test Concurrency/isolated_parameters.swift 2024-04-08 11:53:46 -07:00
Michael Gottesman
b3e837c16c [region-isolation] Enable region isolation by default with strict-concurrency.
I added a disable flag -disable-region-based-isolation-with-strict-concurrency
so that we do not need to update the current tests. It is only available when
asserts are enabled to ensure users cannot use it.

rdar://125918028
2024-04-04 13:07:32 -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
e653423b13 [Concurrency] Make sure to record the actor for #isolation when used as
a default argument for a regular (not isolated) parameter.
2024-03-04 21:24:58 -08:00
Holly Borla
a8a55eb1b1 [Concurrency] Look through caller-side default arguments for #isolation
when computing the isolated actor expression for a call.
2024-03-04 20:10:03 -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
26621b804c [Concurrency] Enable optional isolated parameters. 2024-02-16 16:28:45 -08:00
Holly Borla
ef265399bd Merge pull request #71503 from hborla/invalid-isolated-param
[Concurrency] Always diagnose invalid isolated parameter types in type resolution.
2024-02-09 08:59:41 -08:00
Holly Borla
aa99cbc80e [Concurrency] Always diagnose invalid isolated parameter types in type resolution. 2024-02-08 23:15:50 -08:00
Finagolfin
8e7a5c6e53 [Test] Make sure macros are enabled for the tests that use the new #isolation macro 2024-01-28 02:20:07 +05:30
Holly Borla
917eacbee1 Merge pull request #71197 from hborla/isolated-parameter-sendable 2024-01-27 08:48:24 -08:00
Holly Borla
fef9a54242 [Concurrency] Don't consider callees with isolated parameters as exiting
to nonisolated unless the callee isolation is statically known to be
nonisolated.
2024-01-26 18:04:16 -08:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
Holly Borla
a43779c396 [Concurrency] Handle #isolation in isolated argument checking. 2024-01-24 22:00:40 -08:00
Holly Borla
f2b088518c [Concurrency] Implement more precise actor isolation for isolated argument
values.

Teach ActorIsolation that a `nil` isolated argument is statically nonisolated,
and a reference to GlobalActor.shared statically has global actor isolation.

This change also models arbitrary actor instance isolation using VarDecls
when possible, which allows comparing two ActorIsolation values that may
represent different actor instances. Previously, ActorIsolation was
modeled only by storing the nominal actor type and the parameter index,
so the actor isolation value for two different actors was considered
to be equal. Now, the nominal actor type is only used for isolated `self`
in cases where there is no implicit self parameter decl, such as for
stored properties.
2024-01-24 20:24:34 -08:00
Konrad `ktoso` Malawski
14acfb20bd [Concurrency] isolated fixes; ban Array<T> and handle Self in actor (#70955) 2024-01-17 22:42:45 -08:00
Konrad `ktoso` Malawski
5a3cad992d [Concurrency] allow isolated on dynamic self types (#70925) 2024-01-17 12:16:33 +09:00
Holly Borla
f15ef1a055 [Concurrency] Allow isolated parameters to have optional type. 2024-01-09 21:37:24 -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
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
Kavon Farvardin
16af507d9e [Concurrency] tighten-up rules about isolated generic parameters
We were missing a check for conformance to `Actor` or `DistributedActor`
when an isolated parameter's type is a generic parameter.

Previously, if you used a generic parameter constrained to just `AnyActor`,
you'd crash the compiler in LowerHopToExecutor because it doesn't know
how to obtain the executor for such a value. Since `AnyActor` has no
`unownedExecutor` requirement, there's no way to get the executor without
emitting code to do dynamic casts down to `Actor` or `DistributedActor`.

Rather than have the compiler silently emit dynamic casting, I figured
it's best to ban it. This forces people to either do the dynamic casts
themselves, or use one of the more specific types to constrain their
parameter.

For other generic parameters, we would silently treat the function
as though it is nonisolated (i.e., as if the `isolated` wasn't written
on the parameter at all).

resolves rdar://109059544
2023-09-18 20:27:46 -07:00
Holly Borla
511add6727 [NFC][Concurrency] Add a test case for non-escaping, synchronous closures
used inside a function with an isolated parameter.
2023-09-03 12:32:50 -07:00
Holly Borla
68a4b314c9 [NFC][Concurrency] Add a test case for inheriting actor context within a
function that uses isolated parameters.
2023-09-03 12:22:42 -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
Holly Borla
6a4c7891b8 [Concurrency] Diagnose non-sendable 'self' arguments crossing isolation boundaries. 2023-08-04 09:32:41 -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
Kavon Farvardin
3b3bdaf8d1 enforce correctness rules about isolated parameters
This covers function types, closures, and function declarations:

- only one `isolated` parameter
- no global-actor + `isolated` parameter
- no `nonisolated` + `isolated`.

all diagnostics are warnings until Swift 6
2022-11-11 16:00:12 -08:00
Konrad `ktoso` Malawski
e94aa362fa [Concurrency] Ban multiple isolated params, as per SE-0313 2022-11-10 12:18:53 -08:00
Doug Gregor
141ffc2b8d Model isolated parameters in ActorIsolation.
A function can be actor instance-isolated to one of its parameters.
Make sure that this is reflected in ActorIsolation, so such a function
doesn't get a different actor isolation.
2022-08-23 23:19:46 -07:00
Doug Gregor
f4ac02fd63 Isolate closures to their 'isolated' parameters.
When a closure has an isolated parameter, the closure itself is
isolated to that parameter. Capture this in the isolation of the
closure itself, so it is propagated to nested closures.

Fixes rdar://83733845.
2021-11-08 13:20:16 -08:00
Doug Gregor
5154341c46 Make isolated parameter checking work with existential values.
We needed to look through opaque value expressions.
Fixes rdar://84581926.
2021-11-04 23:04:24 -07:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Doug Gregor
45824befd2 Infer 'isolated' closure parameters from context.
When a closure is provided with a contextual type that has isolated
parameters, infer that the corresponding closure parameter is "isolated".

Fixes rdar://83732479.
2021-10-20 21:51:42 -07:00
LucianoAlmeida
d53a862251 [Sema][SR-15179] Do not record default argument mismatch fix if there is one remove arg fix already for locator 2021-09-13 13:51:18 -03:00
Hamish Knight
cab39bf26c [CS] Formalize param flag handling for imploding params
By default avoid imploding params that have parameter
flags, but carve out exceptions for ownership flags,
which can be thunked, and `@_nonEphemeral` which can
be freely dropped without issue.
2021-09-09 21:46:31 +01:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
35dbba20b0 Ignore whether a parameter is "isolated" for the purposes of redeclarations.
Overload resolution won't be able to tell them apart, and they're mangled
identically. Fixes rdar://80918858.
2021-07-22 09:59:35 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Kavon Farvardin
5ffe8e0878 fix parsing of isolated as an argument label
With the introduction of `isolated` as
a type modifier for actor types, the
parsing of a parameter regressed such
that `isolated` was no longer accepted
as an ordinary argument label. This patch
fixes that and adds a little lookahead
utility to clean-up the code that
disambiguates the uses of `isolated`
as either a label or a type modifier.

Resolves rdar://80300022
2021-07-15 17:49:33 -07:00
Doug Gregor
5bcd5a8e25 Use "isolated" parameters to check for synchronous actor access.
Rework the checking of actor member access to rely on "isolated" parameters
(and captures thereof) to determine whether one can synchronously access
an actor or not. This allows synchronous access via an "isolated" parameter
as a general notion, which subsumes the declaration-based "self" access.

Simplify the checking of and diagnostic reporting for actor member
access by collapsing a number of redundant diagnostics down into a
single, parameterized diagnostic with a single point of emission. This
normalizes the logic a bit.
2021-06-08 00:00:12 -07:00