@@ -197,7 +197,6 @@ static std::pair<BraceStmt *, bool>
197
197
deriveBodyDistributed_thunk (AbstractFunctionDecl *thunk, void *context) {
198
198
auto implicit = true ;
199
199
ASTContext &C = thunk->getASTContext ();
200
- auto module = thunk->getParentModule ();
201
200
202
201
// mock locations, we're a thunk and don't really need detailed locations
203
202
const SourceLoc sloc = SourceLoc ();
@@ -216,21 +215,6 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
216
215
Type returnTy = func->getResultInterfaceType ();
217
216
auto isVoidReturn = returnTy->isVoid ();
218
217
219
- // === self.actorSystem
220
- ProtocolDecl *DAS = C.getDistributedActorSystemDecl ();
221
- Type systemTy = getConcreteReplacementForProtocolActorSystemType (thunk);
222
- assert (systemTy && " distributed thunk can only be synthesized with concrete "
223
- " actor system types" );
224
- NominalTypeDecl *systemDecl = systemTy->getAnyNominal ();
225
- assert (systemDecl);
226
- auto systemConfRef = module ->lookupConformance (systemTy, DAS);
227
- assert (systemConfRef && " ActorSystem must conform to DistributedActorSystem" );
228
-
229
- // === ActorSystem.InvocationEncoder
230
- Type invocationEncoderTy =
231
- getDistributedActorSystemInvocationEncoderType (systemDecl);
232
- NominalTypeDecl *invocationEncoderDecl = invocationEncoderTy->getAnyNominal ();
233
-
234
218
// === Type:
235
219
StructDecl *RCT = C.getRemoteCallTargetDecl ();
236
220
Type remoteCallTargetTy = RCT->getDeclaredInterfaceType ();
@@ -293,17 +277,13 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
293
277
// === remote branch --------------------------------------------------------
294
278
SmallVector<ASTNode, 8 > remoteBranchStmts;
295
279
// --- self.actorSystem
296
- auto systemProperty = nominal->getDistributedActorSystemProperty ();
297
- assert (systemProperty && " Unable to find 'actorSystem' property" );
298
280
auto systemRefExpr =
299
281
UnresolvedDotExpr::createImplicit (
300
282
C, new (C) DeclRefExpr (selfDecl, dloc, implicit), // TODO: make createImplicit
301
283
C.Id_actorSystem );
302
284
303
- auto *systemVar =
304
- new (C) VarDecl (/* isStatic=*/ false , VarDecl::Introducer::Let, sloc,
305
- C.Id_system , thunk);
306
- systemVar->setInterfaceType (systemProperty->getInterfaceType ());
285
+ auto *systemVar = new (C) VarDecl (
286
+ /* isStatic=*/ false , VarDecl::Introducer::Let, sloc, C.Id_system , thunk);
307
287
systemVar->setImplicit ();
308
288
systemVar->setSynthesized ();
309
289
@@ -320,18 +300,15 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
320
300
auto *invocationVar =
321
301
new (C) VarDecl (/* isStatic=*/ false , VarDecl::Introducer::Var, sloc,
322
302
C.Id_invocation , thunk);
323
- invocationVar->setInterfaceType (invocationEncoderTy);
324
303
invocationVar->setImplicit ();
325
304
invocationVar->setSynthesized ();
326
305
327
306
{
328
307
Pattern *invocationPattern = NamedPattern::createImplicit (C, invocationVar);
329
308
330
- FuncDecl *makeInvocationEncoderDecl =
331
- C.getMakeInvocationEncoderOnDistributedActorSystem (func);
332
309
auto makeInvocationExpr = UnresolvedDotExpr::createImplicit (
333
310
C, new (C) DeclRefExpr (ConcreteDeclRef (systemVar), dloc, implicit),
334
- makeInvocationEncoderDecl-> getName ( ));
311
+ DeclName (C. Id_makeInvocationEncoder ));
335
312
auto *makeInvocationArgs = ArgumentList::createImplicit (C, {});
336
313
auto makeInvocationCallExpr =
337
314
CallExpr::createImplicit (C, makeInvocationExpr, makeInvocationArgs);
@@ -347,12 +324,11 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
347
324
// --- Recording invocation details
348
325
// -- recordGenericSubstitution(s)
349
326
if (auto genEnv = thunk->getGenericEnvironment ()) {
350
- auto recordGenericSubstitutionDecl =
351
- C. getRecordGenericSubstitutionOnDistributedInvocationEncoder (invocationEncoderDecl);
352
- assert (recordGenericSubstitutionDecl );
327
+ auto recordGenericSubstitutionName =
328
+ DeclName (C, C. Id_recordGenericSubstitution ,
329
+ /* labels= */ { Identifier ()} );
353
330
auto recordGenericSubstitutionDeclRef =
354
- UnresolvedDeclRefExpr::createImplicit (
355
- C, recordGenericSubstitutionDecl->getName ());
331
+ UnresolvedDeclRefExpr::createImplicit (C, recordGenericSubstitutionName);
356
332
357
333
for (auto genParamType : genEnv->getGenericParams ()) {
358
334
auto tyExpr = TypeExpr::createImplicit (genEnv->mapTypeIntoContext (genParamType), C);
@@ -366,12 +342,14 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
366
342
{subTypeExpr},
367
343
C);
368
344
369
- Expr *recordGenericSub =
370
- CallExpr::createImplicit (C,
371
- UnresolvedDotExpr::createImplicit (C,
372
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit, AccessSemantics::Ordinary),
373
- recordGenericSubstitutionDecl->getName ()),
374
- recordGenericSubArgsList);
345
+ Expr *recordGenericSub = CallExpr::createImplicit (
346
+ C,
347
+ UnresolvedDotExpr::createImplicit (
348
+ C,
349
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
350
+ implicit, AccessSemantics::Ordinary),
351
+ recordGenericSubstitutionName),
352
+ recordGenericSubArgsList);
375
353
recordGenericSub = TryExpr::createImplicit (C, sloc, recordGenericSub);
376
354
377
355
remoteBranchStmts.push_back (recordGenericSub);
@@ -380,14 +358,9 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
380
358
381
359
// -- recordArgument(s)
382
360
{
383
- auto recordArgumentDecl =
384
- C.getRecordArgumentOnDistributedInvocationEncoder (invocationEncoderDecl);
385
- assert (recordArgumentDecl);
386
-
361
+ auto recordArgumentName = DeclName (C, C.Id_recordArgument ,
362
+ /* labels=*/ {Identifier ()});
387
363
for (auto param : *thunk->getParameters ()) {
388
- auto recordArgumentDeclRef = UnresolvedDeclRefExpr::createImplicit (
389
- C, recordArgumentDecl->getName ());
390
-
391
364
auto argumentName = param->getArgumentName ().str ();
392
365
LiteralExpr *argumentLabelArg;
393
366
if (argumentName.empty ()) {
@@ -444,100 +417,96 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
444
417
445
418
// / --- Pass the argumentRepr to the recordArgument function
446
419
auto recordArgArgsList = ArgumentList::forImplicitCallTo (
447
- recordArgumentDeclRef->getName (),
448
- {
449
- new (C) DeclRefExpr (
450
- ConcreteDeclRef (callArgVar), dloc, implicit,
451
- AccessSemantics::Ordinary)
452
- }, C);
453
-
454
- auto tryRecordArgExpr = TryExpr::createImplicit (C, sloc,
455
- CallExpr::createImplicit (C,
456
- UnresolvedDotExpr::createImplicit (C,
457
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit, AccessSemantics::Ordinary),
458
- recordArgumentDecl->getName ()),
459
- recordArgArgsList));
420
+ DeclNameRef (recordArgumentName),
421
+ {new (C) DeclRefExpr (ConcreteDeclRef (callArgVar), dloc, implicit,
422
+ AccessSemantics::Ordinary)},
423
+ C);
424
+
425
+ auto tryRecordArgExpr = TryExpr::createImplicit (
426
+ C, sloc,
427
+ CallExpr::createImplicit (
428
+ C,
429
+ UnresolvedDotExpr::createImplicit (
430
+ C,
431
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
432
+ implicit, AccessSemantics::Ordinary),
433
+ recordArgumentName),
434
+ recordArgArgsList));
460
435
461
436
remoteBranchStmts.push_back (tryRecordArgExpr);
462
437
}
463
438
}
464
439
465
440
// -- recordErrorType
466
441
if (func->hasThrows ()) {
442
+ auto recordErrorTypeName = DeclName (C, C.Id_recordErrorType ,
443
+ /* labels=*/ {Identifier ()});
467
444
// Error.self
468
445
auto errorDecl = C.getErrorDecl ();
469
446
auto *errorTypeExpr = new (C) DotSelfExpr (
470
447
UnresolvedDeclRefExpr::createImplicit (C, errorDecl->getName ()), sloc,
471
448
sloc, errorDecl->getDeclaredInterfaceType ());
472
449
473
- auto recordErrorDecl = C.getRecordErrorTypeOnDistributedInvocationEncoder (
474
- invocationEncoderDecl);
475
- assert (recordErrorDecl);
476
- auto recordErrorDeclRef =
477
- UnresolvedDeclRefExpr::createImplicit (C, recordErrorDecl->getName ());
478
-
479
450
auto recordArgsList = ArgumentList::forImplicitCallTo (
480
- recordErrorDeclRef->getName (),
481
- {errorTypeExpr},
482
- C);
483
- auto tryRecordErrorTyExpr = TryExpr::createImplicit (C, sloc,
484
- CallExpr::createImplicit (C,
485
- UnresolvedDotExpr::createImplicit (C,
486
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit, AccessSemantics::Ordinary),
487
- recordErrorDecl->getName ()),
488
- recordArgsList));
451
+ DeclNameRef (recordErrorTypeName), {errorTypeExpr}, C);
452
+ auto tryRecordErrorTyExpr = TryExpr::createImplicit (
453
+ C, sloc,
454
+ CallExpr::createImplicit (
455
+ C,
456
+ UnresolvedDotExpr::createImplicit (
457
+ C,
458
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
459
+ implicit, AccessSemantics::Ordinary),
460
+ recordErrorTypeName),
461
+ recordArgsList));
489
462
490
463
remoteBranchStmts.push_back (tryRecordErrorTyExpr);
491
464
}
492
465
493
466
// -- recordReturnType
494
467
if (!isVoidReturn) {
468
+ auto recordReturnTypeName = DeclName (C, C.Id_recordReturnType ,
469
+ /* labels=*/ {Identifier ()});
470
+
495
471
// Result.self
496
472
// Watch out and always map into thunk context
497
473
auto resultType = thunk->mapTypeIntoContext (func->getResultInterfaceType ());
498
474
auto *metaTypeRef = TypeExpr::createImplicit (resultType, C);
499
475
auto *resultTypeExpr =
500
476
new (C) DotSelfExpr (metaTypeRef, sloc, sloc, resultType);
501
477
502
- auto recordReturnTypeDecl =
503
- C.getRecordReturnTypeOnDistributedInvocationEncoder (
504
- invocationEncoderDecl);
505
- auto recordReturnTypeDeclRef =
506
- UnresolvedDeclRefExpr::createImplicit (C, recordReturnTypeDecl->getName ());
507
-
508
478
auto recordArgsList = ArgumentList::forImplicitCallTo (
509
- recordReturnTypeDeclRef->getName (),
510
- {resultTypeExpr},
511
- C);
512
- auto tryRecordReturnTyExpr = TryExpr::createImplicit (C, sloc,
513
- CallExpr::createImplicit (C,
514
- UnresolvedDotExpr::createImplicit (C,
515
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit,
516
- AccessSemantics::Ordinary),
517
- recordReturnTypeDecl->getName ()),
518
- recordArgsList));
479
+ DeclNameRef (recordReturnTypeName), {resultTypeExpr}, C);
480
+ auto tryRecordReturnTyExpr = TryExpr::createImplicit (
481
+ C, sloc,
482
+ CallExpr::createImplicit (
483
+ C,
484
+ UnresolvedDotExpr::createImplicit (
485
+ C,
486
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
487
+ implicit, AccessSemantics::Ordinary),
488
+ recordReturnTypeName),
489
+ recordArgsList));
519
490
520
491
remoteBranchStmts.push_back (tryRecordReturnTyExpr);
521
492
}
522
493
523
494
// -- doneRecording
524
495
{
525
- auto doneRecordingDecl =
526
- C.getDoneRecordingOnDistributedInvocationEncoder (invocationEncoderDecl);
527
- assert (doneRecordingDecl && " Could not find 'doneRecording' ad-hoc requirement witness." );
528
- auto doneRecordingDeclRef =
529
- UnresolvedDeclRefExpr::createImplicit (C, doneRecordingDecl->getName ());
530
-
496
+ DeclName doneRecordingName (C.Id_doneRecording );
531
497
auto argsList =
532
- ArgumentList::forImplicitCallTo (doneRecordingDeclRef->getName (), {}, C);
533
- auto tryDoneRecordingExpr = TryExpr::createImplicit (C, sloc,
534
- CallExpr::createImplicit (C,
535
- UnresolvedDotExpr::createImplicit (C,
536
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit,
537
- AccessSemantics::Ordinary,
538
- invocationVar->getInterfaceType ()),
539
- doneRecordingDecl->getName ()),
540
- argsList));
498
+ ArgumentList::forImplicitCallTo (DeclNameRef (doneRecordingName), {}, C);
499
+ auto tryDoneRecordingExpr = TryExpr::createImplicit (
500
+ C, sloc,
501
+ CallExpr::createImplicit (
502
+ C,
503
+ UnresolvedDotExpr::createImplicit (
504
+ C,
505
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
506
+ implicit, AccessSemantics::Ordinary,
507
+ invocationVar->getInterfaceType ()),
508
+ doneRecordingName),
509
+ argsList));
541
510
542
511
remoteBranchStmts.push_back (tryDoneRecordingExpr);
543
512
}
@@ -584,12 +553,20 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
584
553
585
554
// === Make the 'remoteCall(Void)(...)'
586
555
{
587
- auto remoteCallDecl =
588
- C.getRemoteCallOnDistributedActorSystem (systemDecl, isVoidReturn);
589
- auto systemRemoteCallRef =
590
- UnresolvedDotExpr::createImplicit (
591
- C, new (C) DeclRefExpr (ConcreteDeclRef (systemVar), dloc, implicit),
592
- remoteCallDecl->getName ());
556
+ DeclName remoteCallName;
557
+ if (isVoidReturn) {
558
+ remoteCallName =
559
+ DeclName (C, C.Id_remoteCallVoid ,
560
+ {C.Id_on , C.Id_target , C.Id_invocation , C.Id_throwing });
561
+ } else {
562
+ remoteCallName = DeclName (C, C.Id_remoteCall ,
563
+ {C.Id_on , C.Id_target , C.Id_invocation ,
564
+ C.Id_throwing , C.Id_returning });
565
+ }
566
+
567
+ auto systemRemoteCallRef = UnresolvedDotExpr::createImplicit (
568
+ C, new (C) DeclRefExpr (ConcreteDeclRef (systemVar), dloc, implicit),
569
+ remoteCallName);
593
570
594
571
SmallVector<Expr *, 5 > args;
595
572
// -- on actor: Act
@@ -601,9 +578,11 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
601
578
AccessSemantics::Ordinary,
602
579
RCT->getDeclaredInterfaceType ()));
603
580
// -- invocation: inout InvocationEncoder
604
- args.push_back (new (C) InOutExpr (sloc,
605
- new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc,
606
- implicit, AccessSemantics::Ordinary, invocationEncoderTy), invocationEncoderTy, implicit));
581
+ args.push_back (new (C) InOutExpr (
582
+ sloc,
583
+ new (C) DeclRefExpr (ConcreteDeclRef (invocationVar), dloc, implicit,
584
+ AccessSemantics::Ordinary),
585
+ Type (), implicit));
607
586
608
587
// -- throwing: Err.Type
609
588
if (func->hasThrows ()) {
@@ -635,7 +614,7 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
635
614
args.push_back (resultTypeExpr);
636
615
}
637
616
638
- assert (args.size () == remoteCallDecl-> getParameters ()-> size ( ));
617
+ assert (args.size () == (isVoidReturn ? 4 : 5 ));
639
618
auto remoteCallArgs = ArgumentList::forImplicitCallTo (
640
619
systemRemoteCallRef->getName (), args, C);
641
620
0 commit comments