@@ -210,157 +210,6 @@ void emitDistributedActorSystemWitnessCall(
210
210
}
211
211
}
212
212
213
- void emitDistributedWitnessCall (
214
- SILBuilder &B, SILLocation loc, DeclName methodName,
215
- SILValue base, ProtocolDecl *proto, SILType actorType,
216
- llvm::ArrayRef<SILValue> args,
217
- llvm::Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets) {
218
- auto &F = B.getFunction ();
219
- auto &M = B.getModule ();
220
- auto &C = F.getASTContext ();
221
-
222
- // Dig out the conformance to the passed in protocol.
223
- auto astType = base->getType ().getASTType ();
224
- auto *module = M.getSwiftModule ();
225
- ProtocolConformanceRef confRef;
226
-
227
- // If the base is an existential open it.
228
- if (astType->isAnyExistentialType ()) {
229
- OpenedArchetypeType *opened;
230
- astType = astType->openAnyExistentialType (opened)->getCanonicalType ();
231
- base = B.createOpenExistentialAddr (
232
- loc, base, F.getLoweredType (astType),
233
- OpenedExistentialAccess::Immutable);
234
- }
235
-
236
- if (astType->isTypeParameter () || astType->is <ArchetypeType>()) {
237
- confRef = ProtocolConformanceRef (proto);
238
- } else {
239
- confRef = module ->lookupConformance (astType, proto);
240
- }
241
-
242
- assert (!confRef.isInvalid () &&
243
- " Missing conformance to `DistributedActorSystem`" );
244
-
245
- // Dig out the method.
246
- auto method = cast<FuncDecl>(proto->getSingleRequirement (methodName));
247
- auto methodRef = SILDeclRef (method, SILDeclRef::Kind::Func);
248
- auto methodSILTy =
249
- M.Types .getConstantInfo (B.getTypeExpansionContext (), methodRef)
250
- .getSILType ();
251
-
252
- auto witnessMethod = B.createWitnessMethod (
253
- loc, astType, confRef, methodRef, methodSILTy);
254
-
255
- // prepare conformance substitutions
256
- SubstitutionMap subs;
257
- {
258
- auto genericSig = method->getGenericSignature ();
259
- SmallVector<Type, 2 > subTypes;
260
- SmallVector<ProtocolConformanceRef, 2 > subConformances;
261
- subTypes.push_back (astType);
262
- subConformances.push_back (confRef);
263
- if (actorType) {
264
- ProtocolDecl *actorProto = C.getProtocol (
265
- KnownProtocolKind::DistributedActor);
266
- assert (actorProto);
267
-
268
- ProtocolConformanceRef conformance;
269
- auto distributedActorConfRef = module ->lookupConformance (
270
- actorType.getASTType (), actorProto);
271
- assert (!distributedActorConfRef.isInvalid () &&
272
- " Missing conformance to `DistributedActor`" );
273
- subTypes.push_back (actorType.getASTType ());
274
- subConformances.push_back (distributedActorConfRef);
275
- }
276
-
277
- subs = SubstitutionMap::get (genericSig, subTypes, subConformances);
278
- }
279
-
280
- Optional<SILValue> temporaryActorIDBuffer;
281
-
282
- // If the self parameter is indirect but the actorSystem is a value, put it
283
- // into a temporary allocation.
284
- auto methodSILFnTy = methodSILTy.castTo <SILFunctionType>();
285
- Optional<SILValue> temporaryInvocationBuffer;
286
- if (methodSILFnTy->getSelfParameter ().isFormalIndirect () &&
287
- !base->getType ().isAddress ()) {
288
- auto buf = B.createAllocStack (loc, base->getType (), None);
289
- base = B.emitCopyValueOperation (loc, base);
290
- B.emitStoreValueOperation (
291
- loc, base, buf, StoreOwnershipQualifier::Init);
292
- temporaryInvocationBuffer = SILValue (buf);
293
- }
294
-
295
- // === Call the method.
296
- // --- Push the arguments
297
- SmallVector<SILValue, 2 > allArgs;
298
- auto params = methodSILFnTy->getParameters ();
299
- for (size_t i = 0 ; i < args.size (); ++i) {
300
- auto arg = args[i];
301
- if (params[i].isFormalIndirect () &&
302
- !arg->getType ().isAddress () &&
303
- !dyn_cast<AnyMetatypeType>(arg->getType ().getASTType ())) {
304
- auto buf = B.createAllocStack (loc, arg->getType (), None);
305
- auto argCopy = B.emitCopyValueOperation (loc, arg);
306
- B.emitStoreValueOperation (
307
- loc, argCopy, buf, StoreOwnershipQualifier::Init);
308
- temporaryActorIDBuffer = SILValue (buf);
309
- allArgs.push_back (*temporaryActorIDBuffer);
310
- } else {
311
- allArgs.push_back (arg);
312
- }
313
- }
314
- // Push the self argument
315
- auto selfArg = temporaryInvocationBuffer ? *temporaryInvocationBuffer : base;
316
- allArgs.push_back (selfArg);
317
-
318
- SILInstruction *apply;
319
- if (tryTargets) {
320
- apply = B.createTryApply (
321
- loc, witnessMethod, subs, allArgs, tryTargets->first ,
322
- tryTargets->second );
323
- } else {
324
- apply = B.createApply (loc, witnessMethod, subs, allArgs);
325
- }
326
-
327
- // Local function to emit a cleanup after the call.
328
- auto emitCleanup = [&](llvm::function_ref<void (SILBuilder &builder)> fn) {
329
- if (tryTargets) {
330
- {
331
- SILBuilderWithScope normalBuilder (tryTargets->first , apply);
332
- fn (normalBuilder);
333
- }
334
- {
335
- SILBuilderWithScope errorBuilder (tryTargets->second , apply);
336
- fn (errorBuilder);
337
- }
338
- } else {
339
- fn (B);
340
- }
341
- };
342
-
343
- // ==== If we had to create a buffers we need to clean them up
344
- // --- Cleanup id buffer
345
- if (temporaryActorIDBuffer) {
346
- emitCleanup ([&](SILBuilder & builder) {
347
- auto value = builder.emitLoadValueOperation (
348
- loc, *temporaryActorIDBuffer, LoadOwnershipQualifier::Take);
349
- builder.emitDestroyValueOperation (loc, value);
350
- builder.createDeallocStack (loc, *temporaryActorIDBuffer);
351
- });
352
- }
353
- // --- Cleanup actorSystem buffer
354
- if (temporaryInvocationBuffer) {
355
- emitCleanup ([&](SILBuilder & builder) {
356
- auto value = builder.emitLoadValueOperation (
357
- loc, *temporaryInvocationBuffer, LoadOwnershipQualifier::Take);
358
- builder.emitDestroyValueOperation (loc, value);
359
- builder.createDeallocStack (loc, *temporaryInvocationBuffer);
360
- });
361
- }
362
- }
363
-
364
213
void emitActorReadyCall (SILBuilder &B, SILLocation loc, SILValue actor,
365
214
SILValue actorSystem) {
366
215
0 commit comments