@@ -205,7 +205,8 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
205
205
auto uintInit = ctx.getIntBuiltinInitDecl (uintDecl);
206
206
207
207
auto missingTransportDecl = ctx.getMissingDistributedActorTransport ();
208
- assert (missingTransportDecl && " Could not locate '_missingDistributedActorTransport' function" );
208
+ assert (missingTransportDecl &&
209
+ " Could not locate '_missingDistributedActorTransport' function" );
209
210
210
211
// Create a call to _Distributed._missingDistributedActorTransport
211
212
auto loc = func->getLoc ();
@@ -243,16 +244,10 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
243
244
file->setBuiltinInitializer (staticStringInit);
244
245
245
246
auto startLineAndCol = SM.getPresumedLineAndColumnForLoc (distributedFunc->getStartLoc ());
246
- // auto *line = new (ctx) MagicIdentifierLiteralExpr(
247
- // MagicIdentifierLiteralExpr::Line, loc, /*Implicit=*/true);
248
- // auto *line = new (ctx) IntegerLiteralExpr(startLineAndCol.first, loc,
249
- // /*implicit*/ true);
250
247
auto *line = IntegerLiteralExpr::createFromUnsigned (ctx, startLineAndCol.first );
251
248
line->setType (uintType);
252
249
line->setBuiltinInitializer (uintInit);
253
250
254
- // auto *column = new (ctx) MagicIdentifierLiteralExpr(
255
- // MagicIdentifierLiteralExpr::Column, loc, /*Implicit=*/true);
256
251
auto *column = IntegerLiteralExpr::createFromUnsigned (ctx, startLineAndCol.second );
257
252
column->setType (uintType);
258
253
column->setBuiltinInitializer (uintInit);
@@ -264,7 +259,6 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
264
259
265
260
SmallVector<ASTNode, 2 > stmts;
266
261
stmts.push_back (call); // something() -> Never
267
- // stmts.push_back(new (ctx) ReturnStmt(SourceLoc(), /*Result=*/nullptr)); // FIXME: this causes 'different types for return type: String vs. ()'
268
262
auto body = BraceStmt::create (ctx, SourceLoc (), stmts, SourceLoc (),
269
263
/* implicit=*/ true );
270
264
return { body, /* isTypeChecked=*/ true };
@@ -290,7 +284,8 @@ static Identifier makeRemoteFuncIdentifier(FuncDecl* func) {
290
284
// /
291
285
// / and is intended to be replaced by a transport library by providing an
292
286
// / appropriate @_dynamicReplacement function.
293
- static void addImplicitRemoteActorFunction (ClassDecl *decl, FuncDecl *func) {
287
+ static FuncDecl*
288
+ addImplicitRemoteFunction (ClassDecl *decl, FuncDecl *func) {
294
289
auto &C = decl->getASTContext ();
295
290
auto parentDC = decl;
296
291
@@ -315,6 +310,10 @@ static void addImplicitRemoteActorFunction(ClassDecl *decl, FuncDecl *func) {
315
310
remoteFuncDecl->getAttrs ().add (
316
311
new (C) DistributedActorIndependentAttr (/* IsImplicit=*/ true ));
317
312
313
+ // nonisolated
314
+ remoteFuncDecl->getAttrs ().add (
315
+ new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
316
+
318
317
// users should never have to access this function directly;
319
318
// it is only invoked from our distributed function thunk if the actor is remote.
320
319
remoteFuncDecl->setUserAccessible (false );
@@ -326,16 +325,16 @@ static void addImplicitRemoteActorFunction(ClassDecl *decl, FuncDecl *func) {
326
325
remoteFuncDecl->copyFormalAccessFrom (func, /* sourceIsParentContext=*/ false );
327
326
328
327
decl->addMember (remoteFuncDecl);
328
+ return remoteFuncDecl;
329
329
}
330
330
331
331
// / Synthesize dynamic _remote stub functions for each encountered distributed function.
332
- static void addImplicitRemoteActorFunctions (ClassDecl *decl) {
332
+ static void addImplicitRemoteFunctions (ClassDecl *decl) {
333
333
assert (decl->isDistributedActor ());
334
-
335
334
for (auto member : decl->getMembers ()) {
336
- auto func = dyn_cast<FuncDecl >(member);
335
+ auto func = dyn_cast<AbstractFunctionDecl >(member);
337
336
if (func && func->isDistributed ()) {
338
- addImplicitRemoteActorFunction (decl, func);
337
+ ( void ) func-> getDistributedActorRemoteFuncDecl ( );
339
338
}
340
339
}
341
340
}
@@ -344,8 +343,33 @@ static void addImplicitRemoteActorFunctions(ClassDecl *decl) {
344
343
/* *********************** SYNTHESIS ENTRY POINT *******************************/
345
344
/* *****************************************************************************/
346
345
346
+ AbstractFunctionDecl *TypeChecker::addImplicitDistributedActorRemoteFunction (
347
+ ClassDecl *decl, AbstractFunctionDecl *AFD) {
348
+ if (!decl->isDistributedActor ())
349
+ return nullptr ;
350
+
351
+ if (auto func = dyn_cast<FuncDecl>(AFD))
352
+ return addImplicitRemoteFunction (decl, func);
353
+
354
+ return nullptr ;
355
+ }
356
+
357
+ void TypeChecker::addImplicitDistributedActorRemoteFunctions (NominalTypeDecl *decl) {
358
+ // Bail out if not a distributed actor definition.
359
+ if (!decl->isDistributedActor ())
360
+ return ;
361
+
362
+ // If the _Distributed module is missing we cannot synthesize anything.
363
+ if (!swift::ensureDistributedModuleLoaded (decl))
364
+ return ;
365
+
366
+ if (auto clazz = dyn_cast<ClassDecl>(decl))
367
+ addImplicitRemoteFunctions (clazz);
368
+ }
369
+
347
370
// / Entry point for adding all computed members to a distributed actor decl.
348
- void swift::addImplicitDistributedActorMembersToClass (ClassDecl *decl) {
371
+ // TODO(distributed): move the synthesis of protocol requirements to DerivedConformance style
372
+ void swift::addImplicitDistributedActorMembers (ClassDecl *decl) {
349
373
// Bail out if not a distributed actor definition.
350
374
if (!decl->isDistributedActor ())
351
375
return ;
@@ -356,5 +380,4 @@ void swift::addImplicitDistributedActorMembersToClass(ClassDecl *decl) {
356
380
357
381
addFactoryResolveFunction (decl);
358
382
addImplicitDistributedActorStoredProperties (decl);
359
- addImplicitRemoteActorFunctions (decl);
360
383
}
0 commit comments