@@ -1325,23 +1325,6 @@ namespace {
13251325 wrapperInfo.wrappedValuePlaceholder ->getOriginalWrappedValue ())
13261326 return false ;
13271327
1328- // If we have a nonmutating setter on a value type, the call
1329- // captures all of 'self' and we cannot rewrite an assignment
1330- // into an initialization.
1331-
1332- // Unless this is an assignment to a self parameter inside a
1333- // constructor, in which case we would like to still emit a
1334- // assign_by_wrapper because the setter will be deleted by lowering
1335- // anyway.
1336- if (!isAssignmentToSelfParamInInit &&
1337- !VD->isSetterMutating () &&
1338- VD->getDeclContext ()->getSelfNominalTypeDecl () &&
1339- VD->isInstanceMember () &&
1340- !VD->getDeclContext ()->getDeclaredInterfaceType ()
1341- ->hasReferenceSemantics ()) {
1342- return false ;
1343- }
1344-
13451328 // If this property wrapper uses autoclosure in it's initializer,
13461329 // the argument types of the setter and initializer shall be
13471330 // different, so we don't rewrite an assignment into an
@@ -1490,7 +1473,9 @@ namespace {
14901473 }
14911474
14921475 CanSILFunctionType setterTy = setterFRef->getType ().castTo <SILFunctionType>();
1493- SILFunctionConventions setterConv (setterTy, SGF.SGM .M );
1476+ auto substSetterTy = setterTy->substGenericArgs (SGF.SGM .M , Substitutions,
1477+ SGF.getTypeExpansionContext ());
1478+ SILFunctionConventions setterConv (substSetterTy, SGF.SGM .M );
14941479
14951480 // Emit captures for the setter
14961481 SmallVector<SILValue, 4 > capturedArgs;
@@ -1509,21 +1494,19 @@ namespace {
15091494
15101495 if (setterConv.getSILArgumentConvention (argIdx).isInoutConvention ()) {
15111496 capturedBase = base.getValue ();
1497+ } else if (base.getType ().isAddress () &&
1498+ base.getType ().getObjectType () ==
1499+ setterConv.getSILArgumentType (argIdx,
1500+ SGF.getTypeExpansionContext ())) {
1501+ // If the base is a reference and the setter expects a value, emit a
1502+ // load. This pattern is emitted for property wrappers with a
1503+ // nonmutating setter, for example.
1504+ capturedBase = SGF.B .createTrivialLoadOr (
1505+ loc, base.getValue (), LoadOwnershipQualifier::Copy);
15121506 } else {
15131507 capturedBase = base.copy (SGF, loc).forward (SGF);
15141508 }
15151509
1516- // If the base is a reference and the setter expects a value, emit a
1517- // load. This pattern is emitted for property wrappers with a
1518- // nonmutating setter, for example.
1519- if (base.getType ().isAddress () &&
1520- base.getType ().getObjectType () ==
1521- setterConv.getSILArgumentType (argIdx,
1522- SGF.getTypeExpansionContext ())) {
1523- capturedBase = SGF.B .createTrivialLoadOr (
1524- loc, capturedBase, LoadOwnershipQualifier::Take);
1525- }
1526-
15271510 capturedArgs.push_back (capturedBase);
15281511 }
15291512
@@ -1538,8 +1521,6 @@ namespace {
15381521 assert (value.isRValue ());
15391522 ManagedValue Mval = std::move (value).asKnownRValue (SGF).
15401523 getAsSingleValue (SGF, loc);
1541- auto substSetterTy = setterTy->substGenericArgs (SGF.SGM .M , Substitutions,
1542- SGF.getTypeExpansionContext ());
15431524 auto param = substSetterTy->getParameters ()[0 ];
15441525 SILType loweredSubstArgType = Mval.getType ();
15451526 if (param.isIndirectInOut ()) {
0 commit comments