@@ -47,61 +47,49 @@ using namespace swift;
47
47
// / expected to be filled-in during SILGen.
48
48
static void addFactoryResolveFunction (ClassDecl *decl) {
49
49
assert (decl->isDistributedActor ());
50
- auto &ctx = decl->getASTContext ();
50
+ auto &C = decl->getASTContext ();
51
51
52
- {
53
- auto &C = ctx;
54
- auto conformanceDC = decl;
55
-
56
- // Expected type: (Self) -> (ActorAddress, ActorTransport) -> (Self)
57
- //
58
- // Param: (resolve address: AnyActorAddress)
59
- auto addressType = C.getAnyActorIdentityDecl ()->getDeclaredInterfaceType ();
60
- auto *idParamDecl = new (C) ParamDecl (
61
- SourceLoc (), SourceLoc (), C.Id_resolve ,
62
- SourceLoc (), C.Id_id , conformanceDC);
63
- idParamDecl->setImplicit ();
64
- idParamDecl->setSpecifier (ParamSpecifier::Default);
65
- idParamDecl->setInterfaceType (addressType);
66
-
67
- // Param: (using transport: ActorTransport)
68
- auto transportType = C.getActorTransportDecl ()->getDeclaredInterfaceType ();
69
- auto *transportParamDecl = new (C) ParamDecl (
70
- SourceLoc (), SourceLoc (), C.Id_using ,
71
- SourceLoc (), C.Id_transport , conformanceDC);
72
- transportParamDecl->setImplicit ();
73
- transportParamDecl->setSpecifier (ParamSpecifier::Default);
74
- transportParamDecl->setInterfaceType (transportType);
75
-
76
- auto *paramList = ParameterList::create (
77
- C,
78
- /* LParenLoc=*/ SourceLoc (),
79
- /* params=*/ {idParamDecl, transportParamDecl},
80
- /* RParenLoc=*/ SourceLoc ()
81
- );
82
-
83
- // Func name: init(resolve:using:)
84
- DeclName name (C, DeclBaseName::createConstructor (), paramList);
85
-
86
- auto *initDecl =
87
- new (C) ConstructorDecl (name, SourceLoc (),
88
- /* Failable=*/ false , SourceLoc (),
89
- /* Async=*/ false , SourceLoc (),
90
- /* Throws=*/ true , SourceLoc (),
91
- paramList,
92
- /* GenericParams=*/ nullptr , conformanceDC);
93
- initDecl->setImplicit ();
94
- // TODO: determine how to mark this as being synthesized by SILGen.
95
- // initDecl->setSynthesized();
96
- // initDecl->setBodySynthesizer(&createDistributedActor_init_resolve_body);
97
-
98
- auto *nonIsoAttr = new (C) NonisolatedAttr (/* IsImplicit*/ true );
99
- initDecl->getAttrs ().add (nonIsoAttr);
100
-
101
- initDecl->copyFormalAccessFrom (decl, /* sourceIsParentContext=*/ true );
102
-
103
- decl->addMember (initDecl);
104
- }
52
+ auto mkParam = [&](Identifier argName, Identifier paramName, Type ty) -> ParamDecl* {
53
+ auto *param = new (C) ParamDecl (SourceLoc (),
54
+ SourceLoc (), argName,
55
+ SourceLoc (), paramName, decl);
56
+ param->setImplicit ();
57
+ param->setSpecifier (ParamSpecifier::Default);
58
+ param->setInterfaceType (ty);
59
+ return param;
60
+ };
61
+
62
+ auto addressType = C.getAnyActorIdentityDecl ()->getDeclaredInterfaceType ();
63
+ auto transportType = C.getActorTransportDecl ()->getDeclaredInterfaceType ();
64
+
65
+ // (_ id: AnyActorAddress, using transport: ActorTransport)
66
+ auto *params = ParameterList::create (
67
+ C,
68
+ /* LParenLoc=*/ SourceLoc (),
69
+ /* params=*/ { mkParam (Identifier (), C.Id_id , addressType),
70
+ mkParam (C.Id_using , C.Id_transport , transportType)
71
+ },
72
+ /* RParenLoc=*/ SourceLoc ()
73
+ );
74
+
75
+ // Func name: resolve(_:using:)
76
+ DeclName name (C, C.Id_resolve , params);
77
+
78
+ // Expected type: (Self) -> (ActorAddress, ActorTransport) throws -> (Self)
79
+ auto *factoryDecl =
80
+ FuncDecl::createImplicit (C, StaticSpellingKind::KeywordStatic,
81
+ name, SourceLoc (),
82
+ /* async=*/ false ,
83
+ /* throws=*/ true ,
84
+ /* genericParams=*/ nullptr ,
85
+ params,
86
+ /* returnType*/ decl->getDeclaredInterfaceType (),
87
+ decl);
88
+
89
+ factoryDecl->setDistributedActorFactory ();
90
+ factoryDecl->copyFormalAccessFrom (decl, /* sourceIsParentContext=*/ true );
91
+
92
+ decl->addMember (factoryDecl);
105
93
}
106
94
107
95
// / Synthesizes an empty body of the `init(transport:)` initializer as:
0 commit comments