Commit Graph

83 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
5daac06b72 [Distributed] Remove dead code 2021-11-04 14:55:37 +09:00
Doug Gregor
4aacc1c99e Make the actor identity type an associated type of ActorTransport
Eliminate the use of the type-erased `AnyActorIdentity` within the
distributed actor protocol by exposing the identity type of an actor
transport as an associated type, `Identity`, which is then used to
refer to all actors that have that transport.

Retain `AnyActorIdentity`, because it remains useful for type-erasing
actor transports, especially as the `Identity` type for
`AnyActorTransport`. For now, make it the default type of `Identity`:
this helps smooth over the transition from use of `AnyActorIdentity`,
but we might want to remove this to make use of the type-erased forms
always opt-in.
2021-11-03 08:58:21 -07:00
Doug Gregor
c2ba06c3d2 Make the actor transport an associated type of the DistributedActor protocol.
Eliminate the required use of existentials in distributed actors by
introducing the `Transport` associated type into the
`DistributedActor` protocol. Each distributed actor has a known
(concrete) actor transport type, reducing storage requirements and
transport dynamism when it isn't needed.

Distributed actors can manually specify their `Transport` associated
type or pick up a default by looking for a type named
`DefaultActorTransport`. A library that vends an actor transport can
make create a public typealias `DefaultActorTransport` referring to
its transport, so importing that library and defining a distributed
actor will use that library's transport.

Introduce a type-erased `AnyActorTransport` type to provide an
explicitly dynamic actor transport. This is still an important option,
e.g., for cases where one wants to be able to dynamically change the
transport for testing or different kinds of deployment. For now, we
default to this transport in the library (via `DefaultActorTransport`),
but we may very well want to eliminate this because it will be
ambiguous with client libraries that vend their own
`DefaultActorTransport`.
2021-11-01 22:37:33 -07:00
Doug Gregor
3da14e6f65 Refactor and generalize distributed actor transport SIL generation.
Refactor the code that generates SIL to call into the distributed actor
transport to eliminate duplication and better cope with concrete actor
transports. Centralize the knowledge of which actor transport is used
with a given distributed actor type.
2021-10-30 21:49:35 -07:00
Kavon Farvardin
e54fa6c6db inject actorReady calls for async dist actor ctors
Immediately after the hop_to_executor in an async, distributed
actor init, we need to notify the transport that the actor is ready.

This patch does not yet account for more complex cases. In particular,
we will need a mechanism to prevent multiple calls to actorReady,
which can happen if a loop appears in the init:

distributed actor Dactor {
  var x: Int
  init(tport: ActorTransport, count: Int) async {
    var i = count
    repeat {
      self.x = count
      // hop is injected here
      i -= 1
    } while i > 0
  }
}
2021-10-21 19:41:31 -07:00
Kavon Farvardin
51b769795a decouple the emission of actorReady from SILGen
We need to be able to inject a call to a distributed actor's
transport.actorReady, passing the actor instance to it,
during definite initialization. This means that its dependence
on SILGenFunction must be broken, hence this refactoring as
a SILOptimizer utility.
2021-10-21 19:41:31 -07:00
Kavon Farvardin
b7d5e0aff7 invoke resignIdentity in an async failable initializer
For distributed actors, their async initializers will call
actorReady prior to the end of the initializer.
If that happens, we need to resign the identity if we end
up in the failure path of the init.
2021-10-21 19:41:31 -07:00
Kavon Farvardin
8d3c9b0e15 refactor some of SILGen's distributed actor code 2021-10-21 19:41:31 -07:00
Kavon Farvardin
38e6303d11 fixed emission of actorReady call in init epilogue 2021-10-21 19:41:31 -07:00
Doug Gregor
9db26386f3 Support distributed actor init with a non-existential "transport" parameter.
Fixes rdar://84329494.
2021-10-19 08:23:39 -07:00
Doug Gregor
214b1bd454 Add support for distributed functions in extensions of distributed actors.
Fix a few minor issues in the type checker and SILGen to properly cope with
distributed functions defined within extensions of distributed actors.
While here, centralize the logic that adds the "_remote_" function.

Fixes rdar://84325525.
2021-10-15 22:46:44 -07:00
Doug Gregor
e0767e0e09 Stop relying on @_distributedActorIndependent anywhere.
This is an non-user-visible attribute that is semantically identical to
`nonisolated` except that it allows use in distributed actors. It is
only, and can only, be used for the two fields that distributed actors
have in both the local actor and in the remote proxy, "id" and
"actorTransport". So, special-case the "nonisolated" check for those
fields and stop using `@_distributedActorIndependent`.
2021-10-01 23:04:42 -07:00
Andrew Trick
8f53a927b0 SILGen OSSA support for switch_enum/checked_cast_br, related cleanup
Use APIs for creating terminator results that handle forwarding
ownership consistently.

Add ManagedValue::forForwardedRValue(SILValue) to handle cleanups
consistently based on ownership forwarding.

Add SILGenBuilder::createForwardedTermResult(SILType type) for
creating termator results with the correct ownership and cleanups.

Add SILGenBuilder::createTermResult(SILType type, ValueOwnershipKind
ownership) that handles cleanup based on terminator result ownership.

Add SILGenBuilder::createOptionalSomeResult(SwitchEnumInst) so a lot
of code doesn't need to deal with unwrapping Optional types,
terminator results, and ownership rules.

Replace the existing "phi" APIs with a single
SILGenBuilder::createPhi(SILType, ValueOwnershipKind) that handles
cleanup based on phi ownership.

Phis and terminator results are fundamentally different and need to be handled differently everywhere. Remove the confusion where terminator results were generated with a "phi argument" API.
2021-09-07 22:50:46 -07:00
Dario Rexin
49b33bb9ab [Distributed] Remove unused code from SILGenDistributed (#39052) 2021-08-26 12:16:54 +09:00
Dario Rexin
d43ea45b6a Revert "Revert "Merge pull request #38938 from drexin/wip-dist-resolve" (#38994)" (#39011)
This reverts commit f6ae9f3387.
2021-08-24 13:33:37 +09:00
Konrad `ktoso` Malawski
f6ae9f3387 Revert "Merge pull request #38938 from drexin/wip-dist-resolve" (#38994)
This reverts commit a4f3f2fb48, reversing
changes made to 8cf6c2e71b.
2021-08-23 20:30:41 +09:00
Konrad `ktoso` Malawski
beaf8a3203 Revert "[Distributed] Ensure _remote funcs synthesized before dynamic replacement (#38974)"
This reverts commit fe4ba18bf7.
2021-08-23 13:23:39 +09:00
Konrad `ktoso` Malawski
fe4ba18bf7 [Distributed] Ensure _remote funcs synthesized before dynamic replacement (#38974)
* [Distributed] Ensure _remote funcs synthesized before dynamic replacement

* cleanup

* remove redundant synthesis cause
2021-08-23 11:40:12 +09:00
Dario Rexin
3161d8f66c [Distributed] Generate SIL for DistributedActor.resolve
rdar://78484431
2021-08-19 17:32:00 -07:00
Konrad `ktoso` Malawski
d414a26ef1 [Distributed] cleanup some warnings in SILGenDistributed (#38901)
* [Distributed] cleanup some warnings in SILGenDistributed

* [Distributed] cleanup SILGenDestructor, move dist logic to
SILGenDistributed

* [Distributed] de-duplicate SIL gen for if remote/local branch
2021-08-17 13:36:05 +09:00
Konrad `ktoso` Malawski
4e8ca79072 [Distributed] deinit aware of remote "properties" (lack thereof in storage) 2021-08-13 19:43:53 +09:00
Konrad `ktoso` Malawski
ad346ae7f4 [Distributed] re-disable distributed/runtime tests to land initial work 2021-08-12 17:28:03 +09:00
Konrad `ktoso` Malawski
829a5d6895 [Distributed] Review followup and cleanups 2021-08-12 14:09:03 +09:00
Konrad `ktoso` Malawski
a99e935050 [Distributed] implemented storing transport in resolve 2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
f1a06653ad [Distributed] move SILGen for destructor resignIdentity to
SILGenDistributed
2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
aaf81371ef [Distributed] work in progress SIL actorReady call 2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
ac6bee45db [Distributed] SIL invocation of initialize remote done 2021-08-12 14:09:01 +09:00
Konrad `ktoso` Malawski
7e0a3eba13 [Distributed] Implementing calling transport in resolve and assigning id/transp 2021-08-12 14:08:58 +09:00
Konrad `ktoso` Malawski
d5b7bb3572 [Distributed] diagnose missing module 2021-08-12 14:04:51 +09:00
Konrad `ktoso` Malawski
1f33a0cc45 [Distributed] move where we invoke dist synthesis; detect transport param 2021-08-12 14:04:50 +09:00
Konrad `ktoso` Malawski
e1dcd776c5 [Distributed] Implement assigning address in SIL 2021-08-12 14:04:50 +09:00
Konrad `ktoso` Malawski
4f2c2f0a31 [Distributed] move emitDistributedThunk to SILGenDDistributed 2021-08-12 14:04:49 +09:00
Konrad `ktoso` Malawski
d1e16386dc [Distributed] SILGenDDistributed initializers 2021-08-12 14:04:49 +09:00