@@ -45,22 +45,45 @@ static VarDecl* lookupProperty(NominalTypeDecl *ty, DeclName name) {
4545 return dyn_cast<VarDecl>(refs.front ());
4646}
4747
48+ // / Emit a reference to a specific stored property of the actor.
49+ static SILValue emitActorPropertyReference (
50+ SILGenFunction &SGF, SILLocation loc, SILValue actorSelf,
51+ VarDecl *property) {
52+ Type formalType = SGF.F .mapTypeIntoContext (property->getInterfaceType ());
53+ SILType loweredType = SGF.getLoweredType (formalType).getAddressType ();
54+ #if false
55+ if (!loweredType.isAddress ()) {
56+ loweredType = SILType::getPrimitiveAddressType (
57+ formalType->getCanonicalType ());
58+ }
59+ #endif
60+ return SGF.B .createRefElementAddr (loc, actorSelf, property, loweredType);
61+ }
62+
4863// / Perform an initializing store to the given property using the value
4964// / \param actorSelf the value representing `self` for the actor instance.
5065// / \param prop the property to be initialized.
5166// / \param value the value to use when initializing the property.
5267static void initializeProperty (SILGenFunction &SGF, SILLocation loc,
5368 SILValue actorSelf,
5469 VarDecl* prop, SILValue value) {
55- CanType propType = SGF.F .mapTypeIntoContext (prop->getInterfaceType ())
56- -> getCanonicalType ( );
57- SILType loweredPropType = SGF. getLoweredType (propType);
58- auto fieldAddr = SGF. B . createRefElementAddr ( loc, actorSelf, prop, loweredPropType );
70+ Type formalType = SGF.F .mapTypeIntoContext (prop->getInterfaceType ());
71+ SILType loweredType = SGF. getLoweredType (formalType );
72+
73+ auto fieldAddr = emitActorPropertyReference (SGF, loc, actorSelf, prop);
5974
60- if (fieldAddr-> getType (). isAddress ())
75+ if (loweredType. isAddressOnly (SGF. F )) {
6176 SGF.B .createCopyAddr (loc, value, fieldAddr, IsNotTake, IsInitialization);
62- else
63- SGF.B .emitStoreValueOperation (loc, value, fieldAddr, StoreOwnershipQualifier::Init);
77+ } else {
78+ if (value->getType ().isAddress ()) {
79+ value = SGF.B .createTrivialLoadOr (
80+ loc, value, LoadOwnershipQualifier::Copy);
81+ }
82+
83+ value = SGF.B .emitCopyValueOperation (loc, value);
84+ SGF.B .emitStoreValueOperation (
85+ loc, value, fieldAddr, StoreOwnershipQualifier::Init);
86+ }
6487}
6588
6689/* *****************************************************************************/
@@ -355,26 +378,20 @@ void SILGenFunction::emitResignIdentityCall(SILLocation loc,
355378 FormalEvaluationScope scope (*this );
356379
357380 // ==== locate: self.id
358- auto *idVarDeclRef = lookupProperty (actorDecl, ctx.Id_id );
359- CanType idType = F.mapTypeIntoContext (
360- idVarDeclRef->getInterfaceType ())->getCanonicalType ();
361- auto idRef = B.createRefElementAddr (loc, actorSelf, idVarDeclRef,
362- getLoweredType (idType));
381+ auto idRef = emitActorPropertyReference (
382+ *this , loc, actorSelf.getValue (), lookupProperty (actorDecl, ctx.Id_id ));
363383
364384 // ==== locate: self.actorTransport
365- auto transportVarDeclRef = lookupProperty (actorDecl, ctx.Id_actorTransport );
366- CanType transportType = F.mapTypeIntoContext (
367- transportVarDeclRef->getInterfaceType ())->getCanonicalType ();
368- auto transportRef =
369- B.createRefElementAddr (loc, actorSelf, transportVarDeclRef,
370- getLoweredType (transportType));
385+ auto transportRef = emitActorPropertyReference (
386+ *this , loc, actorSelf.getValue (),
387+ lookupProperty (actorDecl, ctx.Id_actorTransport ));
371388
372389 // Perform the call.
373390 emitActorTransportWitnessCall (
374391 B, loc, ctx.Id_resignIdentity ,
375- transportRef. getValue () ,
392+ transportRef,
376393 SILType (),
377- { idRef. getValue () });
394+ { idRef });
378395}
379396
380397void
0 commit comments