@@ -205,7 +205,8 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
205205 auto uintInit = ctx.getIntBuiltinInitDecl (uintDecl);
206206
207207 auto missingTransportDecl = ctx.getMissingDistributedActorTransport ();
208- assert (missingTransportDecl && " Could not locate '_missingDistributedActorTransport' function" );
208+ assert (missingTransportDecl &&
209+ " Could not locate '_missingDistributedActorTransport' function" );
209210
210211 // Create a call to _Distributed._missingDistributedActorTransport
211212 auto loc = func->getLoc ();
@@ -243,16 +244,10 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
243244 file->setBuiltinInitializer (staticStringInit);
244245
245246 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);
250247 auto *line = IntegerLiteralExpr::createFromUnsigned (ctx, startLineAndCol.first );
251248 line->setType (uintType);
252249 line->setBuiltinInitializer (uintInit);
253250
254- // auto *column = new (ctx) MagicIdentifierLiteralExpr(
255- // MagicIdentifierLiteralExpr::Column, loc, /*Implicit=*/true);
256251 auto *column = IntegerLiteralExpr::createFromUnsigned (ctx, startLineAndCol.second );
257252 column->setType (uintType);
258253 column->setBuiltinInitializer (uintInit);
@@ -264,7 +259,6 @@ synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
264259
265260 SmallVector<ASTNode, 2 > stmts;
266261 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. ()'
268262 auto body = BraceStmt::create (ctx, SourceLoc (), stmts, SourceLoc (),
269263 /* implicit=*/ true );
270264 return { body, /* isTypeChecked=*/ true };
@@ -290,7 +284,8 @@ static Identifier makeRemoteFuncIdentifier(FuncDecl* func) {
290284// /
291285// / and is intended to be replaced by a transport library by providing an
292286// / appropriate @_dynamicReplacement function.
293- static void addImplicitRemoteActorFunction (ClassDecl *decl, FuncDecl *func) {
287+ static FuncDecl*
288+ addImplicitRemoteFunction (ClassDecl *decl, FuncDecl *func) {
294289 auto &C = decl->getASTContext ();
295290 auto parentDC = decl;
296291
@@ -315,6 +310,10 @@ static void addImplicitRemoteActorFunction(ClassDecl *decl, FuncDecl *func) {
315310 remoteFuncDecl->getAttrs ().add (
316311 new (C) DistributedActorIndependentAttr (/* IsImplicit=*/ true ));
317312
313+ // nonisolated
314+ remoteFuncDecl->getAttrs ().add (
315+ new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
316+
318317 // users should never have to access this function directly;
319318 // it is only invoked from our distributed function thunk if the actor is remote.
320319 remoteFuncDecl->setUserAccessible (false );
@@ -326,16 +325,16 @@ static void addImplicitRemoteActorFunction(ClassDecl *decl, FuncDecl *func) {
326325 remoteFuncDecl->copyFormalAccessFrom (func, /* sourceIsParentContext=*/ false );
327326
328327 decl->addMember (remoteFuncDecl);
328+ return remoteFuncDecl;
329329}
330330
331331// / Synthesize dynamic _remote stub functions for each encountered distributed function.
332- static void addImplicitRemoteActorFunctions (ClassDecl *decl) {
332+ static void addImplicitRemoteFunctions (ClassDecl *decl) {
333333 assert (decl->isDistributedActor ());
334-
335334 for (auto member : decl->getMembers ()) {
336- auto func = dyn_cast<FuncDecl >(member);
335+ auto func = dyn_cast<AbstractFunctionDecl >(member);
337336 if (func && func->isDistributed ()) {
338- addImplicitRemoteActorFunction (decl, func);
337+ ( void ) func-> getDistributedActorRemoteFuncDecl ( );
339338 }
340339 }
341340}
@@ -344,8 +343,33 @@ static void addImplicitRemoteActorFunctions(ClassDecl *decl) {
344343/* *********************** SYNTHESIS ENTRY POINT *******************************/
345344/* *****************************************************************************/
346345
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+
347370// / 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) {
349373 // Bail out if not a distributed actor definition.
350374 if (!decl->isDistributedActor ())
351375 return ;
@@ -356,5 +380,4 @@ void swift::addImplicitDistributedActorMembersToClass(ClassDecl *decl) {
356380
357381 addFactoryResolveFunction (decl);
358382 addImplicitDistributedActorStoredProperties (decl);
359- addImplicitRemoteActorFunctions (decl);
360383}
0 commit comments