Commit Graph

603 Commits

Author SHA1 Message Date
Allan Shortlidge
fdc7ebddbc Tests: Make distributed_actor_custom_executor_availability.swift use an explicit deployment target.
Split distributed_actor_custom_executor_availability.swift into two tests, one
that only runs on existing platforms that support back deployment to Swift 5.7
aligned runtimes, and another test that is not restricted by platform that
tests behavior when deploying to a Swift 5.9 aligned runtime or later.
2024-01-24 22:21:51 -08:00
Allan Shortlidge
e0aa2e8a4b Tests: Make distributed_actor_accessor_thunks_64bit.swift less sensitive to deployment target. 2024-01-24 22:21:51 -08:00
Slava Pestov
9c077ec338 Sema: Consolidate calls to emitDelayedDiags() 2024-01-24 13:16:49 -05:00
Slava Pestov
ec7269da5c Sema: Clean up diagnoseMissingWitnesses() 2024-01-24 12:38:36 -05:00
Slava Pestov
4d7a22375b Fix typo in name of test file 2024-01-24 12:05:24 -05:00
Doug Gregor
5c83cae0df Merge pull request #71105 from DougGregor/silgen-hack-distributed-actor-as-actor
[SILGen] Ensure that we emit the distributed-actor-as-actor conformance
2024-01-23 22:36:17 -08:00
Michael Gottesman
c4622a235d Merge pull request #71099 from gottesmm/pr-387f6b4fba6f40c5cb78dd54f3fd718902f9d38d
[region-isolation] Make it so that we only propagate actor self if the callee takes self as isolated.
2024-01-23 20:47:17 -08:00
Doug Gregor
07c6b78540 [SILGen] Ensure that we emit the distributed-actor-as-actor conformance
The distributed-actor-as-actor conformance is synthesized by the
frontend, so make sure that when we access the API that exposes it
(asLocalActor), we be sure to mark the conformance as "used".

This is a very specific workaround for general problem with
compiler-synthesized conformances. SIL deserialization can bring in a
reference to a conformance late in the SIL pipeline, after the point at
which SILGen can create the conformance. We should be able to address
this systemically to remove the hack.
2024-01-23 19:32:47 -08:00
Michael Gottesman
bfc12c550c Fix another test 2024-01-23 16:24:53 -08:00
Michael Gottesman
6f3d45219a [ast] Represent a parameter's isolation at the SIL level.
I did this by adding flag on SILParamInfo.

rdar://121387872
2024-01-23 15:20:22 -08:00
Doug Gregor
f79a108e85 Implement support for #isolation for distributed actors
When using `#isolation` within a context that is isolated to a
distributed actor, resolve to an `asLocalActor` access to retrieve the
local actor corresponding to the distributed actor.
2024-01-23 13:47:03 -08:00
Doug Gregor
a25911ef8c Remove unnecessary Darwin-specific check 2024-01-22 21:13:19 -08:00
Doug Gregor
97ea19d191 Introduce a builtin and API for getting the local actor from a distributed one
When an actual instance of a distributed actor is on the local node, it is
has the capabilities of `Actor`. This isn't expressible directly in the type
system, because not all `DistributedActor`s are `Actor`s, nor is the
opposite true.

Instead, provide an API `DistributedActor.asLocalActor` that can only
be executed when the distributed actor is known to be local (because
this API is not itself `distributed`), and produces an existential
`any Actor` referencing that actor. The resulting existential value
carries with it a special witness table that adapts any type
conforming to the DistributedActor protocol into a type that conforms
to the Actor protocol. It is "as if" one had written something like this:

    extension DistributedActor: Actor { }

which, of course, is not permitted in the language. Nonetheless, we
lovingly craft such a witness table:

* The "type" being extended is represented as an extension context,
rather than as a type context. This hasn't been done before, all Swift
runtimes support it uniformly.

* A special witness is provided in the Distributed library to implement
the `Actor.unownedExecutor` operation. This witness back-deploys to the
Swift version were distributed actors were introduced (5.7). On Swift
5.9 runtimes (and newer), it will use
`DistributedActor.unownedExecutor` to support custom executors.

* The conformance of `Self: DistributedActor` is represented as a
conditional requirement, which gets satisfied by the witness table
that makes the type a `DistributedActor`. This makes the special
witness work.

* The witness table is *not* visible via any of the normal runtime
lookup tables, because doing so would allow any
`DistributedActor`-conforming type to conform to `Actor`, which would
break the safety model.

* The witness table is emitted on demand in any client that needs it.
In back-deployment configurations, there may be several witness tables
for the same concrete distributed actor conforming to `Actor`.
However, this duplication can only be observed under fairly extreme
circumstances (where one is opening the returned existential and
instantiating generic types with the distributed actor type as an
`Actor`, then performing dynamic type equivalence checks), and will
not be present with a new Swift runtime.

All of these tricks together mean that we need no runtime changes, and
`asLocalActor` back-deploys as far as distributed actors, allowing it's
use in `#isolation` and the async for...in loop.
2024-01-22 17:27:31 -08:00
Konrad `ktoso` Malawski
9eb84a4ecb [Distributed] add test for remoteCall on dist property (#71052) 2024-01-21 23:42:52 -08:00
Slava Pestov
24814c5e9d Merge pull request #71041 from slavapestov/refactor-conformance-checker-diagnostics
Refactor conformance checker diagnostics
2024-01-21 11:14:47 -05:00
Slava Pestov
525b6effc6 Sema: Use diagnoseOrDefer() in ConformanceChecker::ensureRequirementsAreSatisfied() 2024-01-21 08:34:41 -05:00
Konrad `ktoso` Malawski
1dec00a420 [TaskExecutors] Task initializer and withTaskExecutor parameter changes (#70783) 2024-01-20 11:03:26 +09:00
Konrad `ktoso` Malawski
13a42f4bce [Distributed] Allow isolated any DistributedActor (#70906) 2024-01-14 21:16:00 -08:00
Konrad `ktoso` Malawski
396ecdf5ed [Distributed] Destroy decoded parameters after executeDistributedTarget (#70806) 2024-01-11 11:56:14 +09:00
Mike Ash
99f4bad86f Merge pull request #70377 from mikeash/distributed-actor-remotecall-argument-labels-disable-use-os-stdlib
[Test] Mark distributed_actor_remoteCall_argument_labels.swift unsupported for use_os_stdlib.
2023-12-13 20:23:26 -05:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Mike Ash
9eac772c21 [Test] Mark distributed_actor_remoteCall_argument_labels.swift unsupported for use_os_stdlib. 2023-12-11 12:41:53 -05: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
Konrad `ktoso` Malawski
6ddfb6d9c2 correct indent handling for requirement stubs 2023-11-29 14:48:11 +09:00
Konrad `ktoso` Malawski
29982fcc51 Add fixits for distributed system adhoc requirements; make easier to adopt
rdar://114185115
2023-11-29 14:48:10 +09:00
Konrad `ktoso` Malawski
1219d4b8a4 [Distributed] Remove redundant isa check in getting SR 2023-11-16 11:48:17 +09:00
Konrad `ktoso` Malawski
0f5e564bbf handle conformance requirement on extension in distributed funcs 2023-11-14 22:06:35 +09:00
Konrad `ktoso` Malawski
30653a8091 [Distributed] Don't crash in thunk generation when missing SR conformance 2023-11-14 20:57:33 +09:00
Konrad `ktoso` Malawski
aa4b0d0ae3 Merge pull request #69823 from ktoso/wip-remoteCall_argument_old_os_tests
[Distributed] Resolve test issue on old OSes in remoteCall labels
2023-11-14 11:41:11 +09:00
Konrad `ktoso` Malawski
708f23a836 [Distributed] Resolve test issue on old OSes in remoteCall labels 2023-11-14 07:21:31 +09:00
Allan Shortlidge
941ac3c097 Distributed: Enabled availability checking in Distributed tests.
Various distributed actors test cases were testing behavior that ultimately
depends on availability checking but then disabled availability checking on the
command line when building. This will break with future planned changes to
availability checking infrastructure.
2023-11-08 20:56:04 -08:00
Konrad `ktoso` Malawski
8fde809a2c Remove ad-hoc ambiguity detection code; use conflicting() 2023-11-06 12:59:30 +09:00
Konrad `ktoso` Malawski
faf287015f [Distributed] Allow overloads with different types; mangling can handle it 2023-11-02 12:36:40 +09:00
Allan Shortlidge
d0e2ca4e0c SILGen: Skip emitting distributed thunks for skipped accessors.
Generalizes https://github.com/apple/swift/pull/68917 to cover accessors in
addition to methods.

Resolves rdar://117226130
2023-10-26 16:32:51 -07:00
Konrad `ktoso` Malawski
370fa50132 Merge pull request #69093 from ktoso/wip-distributed-effective-label 2023-10-25 10:40:17 +09:00
Konrad `ktoso` Malawski
0a65445765 [Distributed] Correct handling super-class implemented ad-hoc requirements 2023-10-20 10:30:51 +09:00
Konrad `ktoso` Malawski
1d150c811c [Distributed] Fix effectiveLabel implemementation to expected semantics 2023-10-11 00:19:34 +09:00
Allan Shortlidge
a200333a2d SILGen: Skip emitting distributed thunks for skipped functions. 2023-10-02 11:04:07 -07:00
Evan Wilde
6cb608f906 Merge pull request #68757 from etcwilde/ewilde/require-swiftcompilersource 2023-09-26 08:48:37 -07:00
Alex Lorenz
6ecea1ac09 Merge pull request #68481 from hyp/eng/no-nocapture
[IRGen][interop] do not add 'nocapture' to not bitwise takable types
2023-09-26 07:52:05 -07:00
Evan Wilde
af5065dcdf Require swift_in_compiler in dist. ownership verify sil
Commit 5bc036661c introduced changes to
distributed_id_system_ownership_verify_sil.swift that don't work unless
you have SwiftCompilerSources enable. Gating test on that.
2023-09-25 20:48:23 -07:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
Konrad `ktoso` Malawski
04f589fea9 Disable flaky distributed_actor_executor_ast.swift while we investigate
Disable while we investigate rdar://114453974
2023-09-21 08:15:16 -05:00
eeckstein
97668d5b94 Merge pull request #68349 from eeckstein/let-property-lowering
SIL+Optimizer: a better representation for class let-fields
2023-09-19 20:27:43 +02:00
Erik Eckstein
5bc036661c SIL optimizer: add the LetPropertyLowering pass
It lowers let property accesses of classes.
Lowering consists of two tasks:

* In class initializers, insert `end_init_let_ref` instructions at places where all let-fields are initialized.
  This strictly separates the life-range of the class into a region where let fields are still written during
  initialization and a region where let fields are truly immutable.

* Add the `[immutable]` flag to all `ref_element_addr` instructions (for let-fields) which are in the "immutable"
  region. This includes the region after an inserted `end_init_let_ref` in an class initializer, but also all
  let-field accesses in other functions than the initializer and the destructor.

This pass should run after DefiniteInitialization but before RawSILInstLowering (because it relies on `mark_uninitialized` still present in the class initializer).
Note that it's not mandatory to run this pass. If it doesn't run, SIL is still correct.

Simplified example (after lowering):

  bb0(%0 : @owned C):                           // = self of the class initializer
    %1 = mark_uninitialized %0
    %2 = ref_element_addr %1, #C.l              // a let-field
    store %init_value to %2
    %3 = end_init_let_ref %1                    // inserted by lowering
    %4 = ref_element_addr [immutable] %3, #C.l  // set to immutable by lowering
    %5 = load %4
2023-09-19 15:10:30 +02: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
swift-ci
b1abe1b7ab Merge pull request #68451 from ktoso/wip-radar-91857262
[Distributed] Add test coverage for extension where Self: DistributedActor
2023-09-12 04:20:20 -07:00
Becca Royal-Gordon
8770c7f826 Rework ASTDumper (#68438)
This PR refactors the ASTDumper to make it more structured, less mistake-prone, and more amenable to future changes. For example:

```cpp
  // Before:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
    printCommon(E, "unresolved_dot_expr")
      << " field '" << E->getName() << "'";
    PrintWithColorRAII(OS, ExprModifierColor)
      << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind());
    if (E->getBase()) {
      OS << '\n';
      printRec(E->getBase());
    }
    PrintWithColorRAII(OS, ParenthesisColor) << ')';
  }

  // After:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) {
    printCommon(E, "unresolved_dot_expr", label);

    printFieldQuoted(E->getName(), "field");
    printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor);

    if (E->getBase()) {
      printRec(E->getBase());
    }

    printFoot();
  }
```

* Values are printed through calls to base class methods, rather than direct access to the underlying `raw_ostream`.
    * These methods tend to reduce the chances of bugs like missing/extra spaces or newlines, too much/too little indentation, etc.
    * More values are quoted, and unprintable/non-ASCII characters in quoted values are escaped before printing.
* Infrastructure to label child nodes now exists.
    * Some weird breaks from the normal "style", like `PatternBindingDecl`'s original and processed initializers, have been brought into line.
* Some types that previously used ad-hoc dumping functions, like conformances and substitution maps, are now structured similarly to the dumper classes.
* I've fixed the odd dumping bug along the way. For example, distributed actors were only marked `actor`, not `distributed actor`.

This PR doesn't change the overall style of AST dumps; they're still pseudo-S-expressions. But the logic that implements this style is now isolated into a relatively small base class, making it feasible to introduce e.g. JSON dumping in the future.
2023-09-11 23:56:38 -07:00
Konrad `ktoso` Malawski
954c38bbfd Add test coverage for extension where Self: DistributedActor
Additional test coverage for rdar://91857262
2023-09-12 13:55:40 +09:00
Konrad `ktoso` Malawski
b5219c31ed Make sure we don't crash on missing ActorSystem typealias
Refs rdar://90886302
2023-09-12 11:11:37 +09:00