|
30 | 30 | #include "DerivedConformances.h"
|
31 | 31 | using namespace swift;
|
32 | 32 |
|
33 |
| -/******************************************************************************/ |
34 |
| -/******************************* RESOLVE FUNCTION *****************************/ |
35 |
| -/******************************************************************************/ |
36 |
| - |
37 |
| -/// Synthesizes the |
38 |
| -/// |
39 |
| -/// \verbatim |
40 |
| -/// static resolve(_ address: ActorAddress, |
41 |
| -/// using transport: ActorTransport) throws -> Self { |
42 |
| -/// <filled in by SILGenDistributed> |
43 |
| -/// } |
44 |
| -/// \endverbatim |
45 |
| -/// |
46 |
| -/// factory function in the AST, with an empty body. Its body is |
47 |
| -/// expected to be filled-in during SILGen. |
48 |
| -// TODO(distributed): move this synthesis to DerivedConformance style |
49 |
| -static void addFactoryResolveFunction(ClassDecl *decl) { |
50 |
| - assert(decl->isDistributedActor()); |
51 |
| - auto &C = decl->getASTContext(); |
52 |
| - |
53 |
| - auto mkParam = [&](Identifier argName, Identifier paramName, Type ty) -> ParamDecl* { |
54 |
| - auto *param = new (C) ParamDecl(SourceLoc(), |
55 |
| - SourceLoc(), argName, |
56 |
| - SourceLoc(), paramName, decl); |
57 |
| - param->setImplicit(); |
58 |
| - param->setSpecifier(ParamSpecifier::Default); |
59 |
| - param->setInterfaceType(ty); |
60 |
| - return param; |
61 |
| - }; |
62 |
| - |
63 |
| - auto addressType = C.getAnyActorIdentityDecl()->getDeclaredInterfaceType(); |
64 |
| - auto transportType = C.getActorTransportDecl()->getDeclaredInterfaceType(); |
65 |
| - |
66 |
| - // (_ identity: AnyActorIdentity, using transport: ActorTransport) |
67 |
| - auto *params = ParameterList::create( |
68 |
| - C, |
69 |
| - /*LParenLoc=*/SourceLoc(), |
70 |
| - /*params=*/{ mkParam(Identifier(), C.Id_identity, addressType), |
71 |
| - mkParam(C.Id_using, C.Id_transport, transportType) |
72 |
| - }, |
73 |
| - /*RParenLoc=*/SourceLoc() |
74 |
| - ); |
75 |
| - |
76 |
| - // Func name: resolve(_:using:) |
77 |
| - DeclName name(C, C.Id_resolve, params); |
78 |
| - |
79 |
| - // Expected type: (Self) -> (AnyActorIdentity, ActorTransport) throws -> (Self) |
80 |
| - auto *factoryDecl = |
81 |
| - FuncDecl::createImplicit(C, StaticSpellingKind::KeywordStatic, |
82 |
| - name, SourceLoc(), |
83 |
| - /*async=*/false, |
84 |
| - /*throws=*/true, |
85 |
| - /*genericParams=*/nullptr, |
86 |
| - params, |
87 |
| - /*returnType*/decl->getDeclaredInterfaceType(), |
88 |
| - decl); |
89 |
| - |
90 |
| - factoryDecl->setDistributedActorFactory(); // TODO(distributed): should we mark this specifically as the resolve factory? |
91 |
| - factoryDecl->copyFormalAccessFrom(decl, /*sourceIsParentContext=*/true); |
92 |
| - |
93 |
| - decl->addMember(factoryDecl); |
94 |
| -} |
95 |
| - |
96 |
| -/******************************************************************************/ |
97 |
| -/******************************** PROPERTIES **********************************/ |
98 |
| -/******************************************************************************/ |
99 |
| - |
100 |
| -// TODO: deduplicate with 'declareDerivedProperty' from DerivedConformance... |
101 |
| -std::pair<VarDecl *, PatternBindingDecl *> |
102 |
| -createStoredProperty(ClassDecl *classDecl, ASTContext &ctx, |
103 |
| - VarDecl::Introducer introducer, Identifier name, |
104 |
| - Type propertyInterfaceType, Type propertyContextType, |
105 |
| - bool isStatic, bool isFinal) { |
106 |
| - auto parentDC = classDecl; |
107 |
| - |
108 |
| - VarDecl *propDecl = new (ctx) |
109 |
| - VarDecl(/*IsStatic*/ isStatic, introducer, |
110 |
| - SourceLoc(), name, parentDC); |
111 |
| - propDecl->setImplicit(); |
112 |
| - propDecl->setSynthesized(); |
113 |
| - propDecl->copyFormalAccessFrom(classDecl, /*sourceIsParentContext*/ true); |
114 |
| - propDecl->setInterfaceType(propertyInterfaceType); |
115 |
| - |
116 |
| - Pattern *propPat = NamedPattern::createImplicit(ctx, propDecl); |
117 |
| - propPat->setType(propertyContextType); |
118 |
| - |
119 |
| - propPat = TypedPattern::createImplicit(ctx, propPat, propertyContextType); |
120 |
| - propPat->setType(propertyContextType); |
121 |
| - |
122 |
| - auto *pbDecl = PatternBindingDecl::createImplicit( |
123 |
| - ctx, StaticSpellingKind::None, propPat, /*InitExpr*/ nullptr, |
124 |
| - parentDC); |
125 |
| - return {propDecl, pbDecl}; |
126 |
| -} |
127 |
| - |
128 |
| -/// Adds the following, fairly special, properties to each distributed actor: |
129 |
| -/// - actorTransport |
130 |
| -/// - id |
131 |
| -// TODO(distributed): move this synthesis to DerivedConformance style |
132 |
| -static void addImplicitDistributedActorStoredProperties(ClassDecl *decl) { |
133 |
| - assert(decl->isDistributedActor()); |
134 |
| - |
135 |
| - auto &C = decl->getASTContext(); |
136 |
| - |
137 |
| - // ``` |
138 |
| - // @_distributedActorIndependent |
139 |
| - // let id: AnyActorIdentity |
140 |
| - // ``` |
141 |
| - { |
142 |
| - auto propertyType = C.getAnyActorIdentityDecl()->getDeclaredInterfaceType(); |
143 |
| - |
144 |
| - VarDecl *propDecl; |
145 |
| - PatternBindingDecl *pbDecl; |
146 |
| - std::tie(propDecl, pbDecl) = createStoredProperty( |
147 |
| - decl, C, |
148 |
| - VarDecl::Introducer::Let, C.Id_id, |
149 |
| - propertyType, propertyType, |
150 |
| - /*isStatic=*/false, /*isFinal=*/true); |
151 |
| - |
152 |
| - // mark as @_distributedActorIndependent, allowing access to it from everywhere |
153 |
| - propDecl->getAttrs().add( |
154 |
| - new (C) DistributedActorIndependentAttr(/*IsImplicit=*/true)); |
155 |
| - |
156 |
| - decl->addMember(propDecl); |
157 |
| - decl->addMember(pbDecl); |
158 |
| - } |
159 |
| - |
160 |
| - // ``` |
161 |
| - // @_distributedActorIndependent |
162 |
| - // let actorTransport: ActorTransport |
163 |
| - // ``` |
164 |
| - // (no need for @actorIndependent because it is an immutable let) |
165 |
| - { |
166 |
| - auto propertyType = C.getActorTransportDecl()->getDeclaredInterfaceType(); |
167 |
| - |
168 |
| - VarDecl *propDecl; |
169 |
| - PatternBindingDecl *pbDecl; |
170 |
| - std::tie(propDecl, pbDecl) = createStoredProperty( |
171 |
| - decl, C, |
172 |
| - VarDecl::Introducer::Let, C.Id_actorTransport, |
173 |
| - propertyType, propertyType, |
174 |
| - /*isStatic=*/false, /*isFinal=*/true); |
175 |
| - |
176 |
| - // mark as @_distributedActorIndependent, allowing access to it from everywhere |
177 |
| - propDecl->getAttrs().add( |
178 |
| - new (C) DistributedActorIndependentAttr(/*IsImplicit=*/true)); |
179 |
| - |
180 |
| - decl->addMember(propDecl); |
181 |
| - decl->addMember(pbDecl); |
182 |
| - } |
183 |
| -} |
184 |
| - |
185 | 33 | /******************************************************************************/
|
186 | 34 | /*************************** _REMOTE_ FUNCTIONS *******************************/
|
187 | 35 | /******************************************************************************/
|
@@ -354,7 +202,5 @@ void swift::addImplicitDistributedActorMembersToClass(ClassDecl *decl) {
|
354 | 202 | if (!swift::ensureDistributedModuleLoaded(decl))
|
355 | 203 | return;
|
356 | 204 |
|
357 |
| - addFactoryResolveFunction(decl); |
358 |
| - addImplicitDistributedActorStoredProperties(decl); |
359 | 205 | addImplicitRemoteActorFunctions(decl);
|
360 | 206 | }
|
0 commit comments