@@ -63,14 +63,17 @@ static void initializeProperty(SILGenFunction &SGF, SILLocation loc,
6363
6464 auto fieldAddr = emitActorPropertyReference (SGF, loc, actorSelf, prop);
6565
66- if (loweredType.isAddressOnly (SGF.F )) {
66+ if (loweredType.isAddressOnly (SGF.F ) && SGF. useLoweredAddresses () ) {
6767 SGF.B .createCopyAddr (loc, value, fieldAddr, isTake, IsInitialization);
6868 } else {
6969 if (value->getType ().isAddress ()) {
7070 SGF.emitSemanticLoadInto (loc, value, SGF.F .getTypeLowering (value->getType ()),
7171 fieldAddr, SGF.getTypeLowering (loweredType), isTake, IsInitialization);
7272 } else {
73- value = SGF.B .emitCopyValueOperation (loc, value);
73+ // If it's not semantically a take, copy it.
74+ if (isTake == IsNotTake)
75+ value = SGF.B .emitCopyValueOperation (loc, value);
76+
7477 SGF.B .emitStoreValueOperation (
7578 loc, value, fieldAddr, StoreOwnershipQualifier::Init);
7679 }
@@ -204,20 +207,31 @@ void SILGenFunction::emitDistActorIdentityInit(ConstructorDecl *ctor,
204207 auto selfMetatype = getLoweredType (MetatypeType::get (selfTy));
205208 SILValue selfMetatypeValue = B.createMetatype (loc, selfMetatype);
206209
207- // --- create a temporary storage for the result of the call
208- // it will be deallocated automatically as we exit this scope
209210 VarDecl *var = classDecl->getDistributedActorIDProperty ();
210- auto resultTy = getLoweredType (F.mapTypeIntoEnvironment (var->getInterfaceType ()));
211- auto temp = emitTemporaryAllocation (loc, resultTy);
212-
213- // --- emit the call itself.
214- emitDistributedActorSystemWitnessCall (
215- B, loc, C.Id_assignID ,
216- actorSystem, getLoweredType (selfTy),
217- { temp, selfMetatypeValue });
218-
219- // --- initialize the property.
220- initializeProperty (*this , loc, borrowedSelfArg, var, temp, IsTake);
211+ if (useLoweredAddresses ()) {
212+ // --- create a temporary storage for the result of the call
213+ // it will be deallocated automatically as we exit this scope
214+ auto resultTy = getLoweredType (F.mapTypeIntoEnvironment (var->getInterfaceType ()));
215+ auto temp = emitTemporaryAllocation (loc, resultTy);
216+
217+ // --- emit the call itself.
218+ emitDistributedActorSystemWitnessCall (
219+ B, loc, C.Id_assignID ,
220+ actorSystem, getLoweredType (selfTy),
221+ { selfMetatypeValue }, temp);
222+
223+ // --- initialize the property.
224+ initializeProperty (*this , loc, borrowedSelfArg, var, temp, IsTake);
225+ } else {
226+ // --- emit the call itself.
227+ auto result = emitDistributedActorSystemWitnessCall (
228+ B, loc, C.Id_assignID ,
229+ actorSystem, getLoweredType (selfTy),
230+ { selfMetatypeValue });
231+
232+ // --- initialize the property.
233+ initializeProperty (*this , loc, borrowedSelfArg, var, result.value (), IsTake);
234+ }
221235}
222236
223237// TODO(distributed): rename to DistributedActorID
@@ -361,27 +375,6 @@ void SILGenFunction::emitDistributedActorReady(
361375// ==== ------------------------------------------------------------------------
362376// MARK: remote instance initialization
363377
364- // / emit a call to the distributed actor system's resolve function:
365- // /
366- // / \verbatim
367- // / system.resolve(id:as:)
368- // / \endverbatim
369- static void createDistributedActorFactory_resolve (
370- SILGenFunction &SGF, ASTContext &C, FuncDecl *fd, SILValue idValue,
371- SILValue actorSystemValue, Type selfTy, SILValue selfMetatypeValue,
372- SILType resultTy, SILBasicBlock *normalBB, SILBasicBlock *errorBB) {
373- auto &B = SGF.B ;
374-
375- auto loc = SILLocation (fd);
376- loc.markAutoGenerated ();
377-
378- // // ---- actually call system.resolve(id: id, as: Self.self)
379- emitDistributedActorSystemWitnessCall (
380- B, loc, C.Id_resolve , actorSystemValue, SGF.getLoweredType (selfTy),
381- { idValue, selfMetatypeValue },
382- std::make_pair (normalBB, errorBB));
383- }
384-
385378// / Function body of:
386379// / \verbatim
387380// / DistributedActor.resolve(
@@ -435,9 +428,15 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
435428
436429 // ==== Call `try system.resolve(id: id, as: Self.self)`
437430 {
438- createDistributedActorFactory_resolve (
439- *this , C, fd, idArg, actorSystemArg, selfTy, selfMetatypeValue,
440- optionalReturnTy, switchBB, errorBB);
431+ auto loc = SILLocation (fd);
432+ loc.markAutoGenerated ();
433+
434+ // // ---- actually call system.resolve(id: id, as: Self.self)
435+ emitDistributedActorSystemWitnessCall (
436+ B, loc, C.Id_resolve , actorSystemArg, getLoweredType (selfTy),
437+ { idArg, selfMetatypeValue },
438+ /* indirectResult=*/ std::nullopt ,
439+ std::make_pair (switchBB, errorBB));
441440 }
442441
443442 // ==== switch resolved { ... }
0 commit comments