@@ -1325,23 +1325,6 @@ namespace {
1325
1325
wrapperInfo.wrappedValuePlaceholder ->getOriginalWrappedValue ())
1326
1326
return false ;
1327
1327
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
-
1345
1328
// If this property wrapper uses autoclosure in it's initializer,
1346
1329
// the argument types of the setter and initializer shall be
1347
1330
// different, so we don't rewrite an assignment into an
@@ -1490,7 +1473,9 @@ namespace {
1490
1473
}
1491
1474
1492
1475
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 );
1494
1479
1495
1480
// Emit captures for the setter
1496
1481
SmallVector<SILValue, 4 > capturedArgs;
@@ -1509,21 +1494,19 @@ namespace {
1509
1494
1510
1495
if (setterConv.getSILArgumentConvention (argIdx).isInoutConvention ()) {
1511
1496
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);
1512
1506
} else {
1513
1507
capturedBase = base.copy (SGF, loc).forward (SGF);
1514
1508
}
1515
1509
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
-
1527
1510
capturedArgs.push_back (capturedBase);
1528
1511
}
1529
1512
@@ -1538,8 +1521,6 @@ namespace {
1538
1521
assert (value.isRValue ());
1539
1522
ManagedValue Mval = std::move (value).asKnownRValue (SGF).
1540
1523
getAsSingleValue (SGF, loc);
1541
- auto substSetterTy = setterTy->substGenericArgs (SGF.SGM .M , Substitutions,
1542
- SGF.getTypeExpansionContext ());
1543
1524
auto param = substSetterTy->getParameters ()[0 ];
1544
1525
SILType loweredSubstArgType = Mval.getType ();
1545
1526
if (param.isIndirectInOut ()) {
0 commit comments