@@ -97,6 +97,40 @@ getActorTransportArgument(ASTContext& C, SILFunction& F, ConstructorDecl *ctor)
97
97
// / \verbatim
98
98
// / self.actorTransport = <<constructor parameter:ActorTransport>>
99
99
// / \endverbatim
100
+ static void emitDistributedActorStore_transport (
101
+ ASTContext& C, SILGenFunction &SGF,
102
+ SILValue actorSelf, AbstractFunctionDecl *func,
103
+ SILArgument *transportArg) {
104
+ auto &B = SGF.B ;
105
+ auto &F = SGF.F ;
106
+ auto &SGM = SGF.SGM ;
107
+ SILGenFunctionBuilder builder (SGM);
108
+
109
+ auto *dc = func->getDeclContext ();
110
+ auto classDecl = dc->getSelfClassDecl ();
111
+
112
+ auto loc = SILLocation (func);
113
+ loc.markAutoGenerated ();
114
+
115
+ // ==== Prepare the property reference: self.id
116
+ auto vars = classDecl->lookupDirect (C.Id_actorTransport );
117
+ assert (vars.size () == 1 );
118
+ auto *var = dyn_cast<VarDecl>(vars.front ());
119
+
120
+ // ----
121
+ auto *selfTyDecl = func->getParent ()->getSelfNominalTypeDecl ();
122
+ auto fieldAddr = B.createRefElementAddr (
123
+ loc, actorSelf, var,
124
+ SGF.getLoweredType (var->getInterfaceType ()));
125
+
126
+ // ==== Store the transport
127
+ B.createCopyAddr (loc,
128
+ /* src*/ transportArg,
129
+ /* dest*/ fieldAddr,
130
+ IsNotTake, IsInitialization); // TODO(distributed): should it be IsTake?
131
+ }
132
+
133
+ // TODO(distributed): remove this store impl and reuse Store_transport
100
134
static void
101
135
emitDistributedActor_init_transportStore (
102
136
SILGenFunction &SGF,
@@ -134,50 +168,44 @@ emitDistributedActor_init_transportStore(
134
168
// / \verbatim
135
169
// / self.id = <<parameter:identity>>
136
170
// / \endverbatim
137
- static void
138
- emitDistributedActorIdentityStore (
171
+ static void emitDistributedActorStore_id (
139
172
ASTContext& C, SILGenFunction &SGF,
140
- SILValue actorSelf, FuncDecl *func, SILArgument *identityArg) {
173
+ SILValue actorSelf, AbstractFunctionDecl *func,
174
+ SILArgument *identityArg) {
141
175
auto &B = SGF.B ;
142
176
auto &F = SGF.F ;
143
177
auto &SGM = SGF.SGM ;
144
178
SILGenFunctionBuilder builder (SGM);
145
179
146
180
auto *dc = func->getDeclContext ();
147
181
auto classDecl = dc->getSelfClassDecl ();
148
- assert (classDecl->isDistributedActor ());
149
182
150
183
auto loc = SILLocation (func);
151
184
loc.markAutoGenerated ();
152
185
153
186
// ==== Prepare the property reference: self.id
154
- auto idVars = classDecl->lookupDirect (C.Id_id );
155
- assert (idVars .size () == 1 );
156
- auto *idVar = dyn_cast<VarDecl>(idVars .front ());
187
+ auto vars = classDecl->lookupDirect (C.Id_id );
188
+ assert (vars .size () == 1 );
189
+ auto *var = dyn_cast<VarDecl>(vars .front ());
157
190
158
191
// ==== Prepare assignment
159
- // SILValue identityArgValue = identityArg->getValue();
160
- fprintf (stderr, " [%s:%d] (%s) THE ACTOR SELF\n " , __FILE__, __LINE__, __FUNCTION__);
161
- actorSelf->dump ();
162
-
163
- SILValue identityArgValue = identityArg;
164
- auto idFieldAddr = B.createRefElementAddr (
165
- loc, actorSelf, idVar,
166
- SGF.getLoweredType (idVar->getInterfaceType ()));
192
+ auto fieldAddr = B.createRefElementAddr (
193
+ loc, actorSelf, var,
194
+ SGF.getLoweredType (var->getInterfaceType ()));
167
195
168
196
// ==== Store the transport
169
197
B.createCopyAddr (loc,
170
- /* src*/ identityArgValue ,
171
- /* dest*/ idFieldAddr ,
172
- IsNotTake, IsInitialization); // TODO(distributed): should it be take ?
198
+ /* src*/ identityArg ,
199
+ /* dest*/ fieldAddr ,
200
+ IsNotTake, IsInitialization); // TODO(distributed): should it be IsTake ?
173
201
}
174
202
175
203
// / Synthesize the distributed actor's identity (`id`) initialization:
176
204
// /
177
205
// / \verbatim
178
206
// / self.id = transport.assignIdentity(Self.self)
179
207
// / \endverbatim
180
- static void emitDistributedActorIdentity_init_assignIdentity (
208
+ static void emitDistributedActorStore_init_assignIdentity (
181
209
SILGenFunction &SGF,
182
210
ManagedValue borrowedSelfArg, VarDecl *selfVarDecl,
183
211
ConstructorDecl *ctor,
@@ -273,7 +301,7 @@ static void emitDistributedActorIdentity_init_assignIdentity(
273
301
{ temp, selfMetatypeValue, transportArchetypeValue});
274
302
275
303
// ==== Assign the identity to stored property
276
-
304
+ // TODO(distributed): reuse emitDistributedActorStore_id here, pass the SILValue
277
305
// --- Prepare address of self.id
278
306
auto idFieldAddr = B.createRefElementAddr (
279
307
loc, borrowedSelfArg.getValue (), var,
@@ -325,13 +353,14 @@ void SILGenFunction::initializeDistributedActorImplicitStorageInit(
325
353
if (var->getName () == C.Id_actorTransport &&
326
354
var->getInterfaceType ()->isEqual (transportTy)) {
327
355
transportMember = var;
356
+ // TODO(distributed): reuse emitDistributedActorStore_transport
328
357
emitDistributedActor_init_transportStore (
329
358
*this , borrowedSelfArg, selfVarDecl, ctor, pattern, var);
330
359
} else if (var->getName () == C.Id_id &&
331
360
(var->getInterfaceType ()->isEqual (identityProtoTy) ||
332
361
var->getInterfaceType ()->isEqual (anyIdentityTy))) { // TODO(distributed): stick one way to store, but today we can't yet store the existential
333
362
idMember = var;
334
- emitDistributedActorIdentity_init_assignIdentity (
363
+ emitDistributedActorStore_init_assignIdentity (
335
364
*this , borrowedSelfArg, selfVarDecl, ctor, pattern, var);
336
365
}
337
366
if (transportMember && idMember) {
@@ -458,7 +487,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
458
487
assert (identityArg->getType ().getASTType ()->isEqual (C.getAnyActorIdentityType ()));
459
488
460
489
// --- Parameter: transport
461
- SILArgument *transportArg = F.getArgument (1 ); // existential
490
+ SILArgument *transportArg = F.getArgument (1 );
462
491
assert (
463
492
transportArg->getType ().getASTType ()->isEqual (C.getActorTransportType ()));
464
493
@@ -530,13 +559,12 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
530
559
531
560
// ==== Initialize distributed actor properties
532
561
// --- Store the identity: self.id = identity
533
- emitDistributedActorIdentityStore (
562
+ emitDistributedActorStore_id (
534
563
C, *this , /* actorSelf*/ remote, fd, identityArg);
535
564
536
- // --- Store the transport: self.transport = transport
537
- // FIXME(distributed): IMPLEMENT:
538
- // emitDistributedActorTransportStore(
539
- // *this, borrowedSelfArg, selfVarDecl, fd, transportArg);
565
+ // --- Store the transport: self.actorTransport = transport
566
+ emitDistributedActorStore_transport (
567
+ C, *this , /* actorSelf*/ remote, fd, transportArg);
540
568
541
569
// ==== Return the fully initialized remote instance
542
570
B.createReturn (loc, remote);
@@ -576,8 +604,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
576
604
/* ****************** DISTRIBUTED DEINIT: resignAddress ************************/
577
605
/* *****************************************************************************/
578
606
579
-
580
- void SILGenFunction::injectDistributedActorDestructorLifecycleCall (
607
+ void SILGenFunction::emitDistributedActor_resignAddress (
581
608
DestructorDecl *dd, SILValue selfValue, SILBasicBlock *continueBB) {
582
609
ASTContext &ctx = getASTContext ();
583
610
0 commit comments