@@ -1403,7 +1403,7 @@ namespace {
1403
1403
assert (getAccessorDecl ()->isSetter ());
1404
1404
SILDeclRef setter = Accessor;
1405
1405
1406
- if (IsOnSelfParameter && canRewriteSetAsPropertyWrapperInit (SGF) &&
1406
+ if (canRewriteSetAsPropertyWrapperInit (SGF) &&
1407
1407
!Storage->isStatic () &&
1408
1408
isBackingVarVisible (cast<VarDecl>(Storage),
1409
1409
SGF.FunctionDC )) {
@@ -1434,7 +1434,9 @@ namespace {
1434
1434
1435
1435
// Get the address of the storage property.
1436
1436
ManagedValue proj;
1437
- if (BaseFormalType->mayHaveSuperclass ()) {
1437
+ if (!BaseFormalType) {
1438
+ proj = SGF.maybeEmitValueOfLocalVarDecl (backingVar);
1439
+ } else if (BaseFormalType->mayHaveSuperclass ()) {
1438
1440
RefElementComponent REC (backingVar, LValueOptions (), varStorageType,
1439
1441
typeData);
1440
1442
proj = std::move (REC).project (SGF, loc, base);
@@ -1471,33 +1473,51 @@ namespace {
1471
1473
.SILFnType )
1472
1474
.getValue ();
1473
1475
1474
- } else
1476
+ } else {
1475
1477
setterFRef = SGF.emitGlobalFunctionRef (loc, setter, setterInfo);
1478
+ }
1479
+
1476
1480
CanSILFunctionType setterTy = setterFRef->getType ().castTo <SILFunctionType>();
1477
1481
SILFunctionConventions setterConv (setterTy, SGF.SGM .M );
1478
1482
1479
- SILValue capturedBase;
1480
- unsigned argIdx = setterConv.getNumSILArguments () - 1 ;
1481
- if (setterConv.getSILArgumentConvention (argIdx).isInoutConvention ()) {
1482
- capturedBase = base.getValue ();
1483
- } else {
1484
- capturedBase = base.copy (SGF, loc).forward (SGF);
1485
- }
1483
+ // Emit captures for the setter
1484
+ SmallVector<SILValue, 4 > capturedArgs;
1485
+ auto captureInfo = SGF.SGM .Types .getLoweredLocalCaptures (setter);
1486
+ if (!captureInfo.getCaptures ().empty ()) {
1487
+ SmallVector<ManagedValue, 4 > captures;
1488
+ SGF.emitCaptures (loc, setter, CaptureEmission::PartialApplication, captures);
1486
1489
1487
- // If the base is a reference and the setter expects a value, emit a
1488
- // load. This pattern is emitted for property wrappers with a
1489
- // nonmutating setter, for example.
1490
- if (base.getType ().isAddress () &&
1491
- base.getType ().getObjectType () ==
1492
- setterConv.getSILArgumentType (argIdx,
1493
- SGF.getTypeExpansionContext ())) {
1494
- capturedBase = SGF.B .createTrivialLoadOr (
1495
- loc, capturedBase, LoadOwnershipQualifier::Take);
1490
+ for (auto capture : captures)
1491
+ capturedArgs.push_back (capture.forward (SGF));
1492
+ } else {
1493
+ assert (base);
1494
+
1495
+ SILValue capturedBase;
1496
+ unsigned argIdx = setterConv.getNumSILArguments () - 1 ;
1497
+
1498
+ if (setterConv.getSILArgumentConvention (argIdx).isInoutConvention ()) {
1499
+ capturedBase = base.getValue ();
1500
+ } else {
1501
+ capturedBase = base.copy (SGF, loc).forward (SGF);
1502
+ }
1503
+
1504
+ // If the base is a reference and the setter expects a value, emit a
1505
+ // load. This pattern is emitted for property wrappers with a
1506
+ // nonmutating setter, for example.
1507
+ if (base.getType ().isAddress () &&
1508
+ base.getType ().getObjectType () ==
1509
+ setterConv.getSILArgumentType (argIdx,
1510
+ SGF.getTypeExpansionContext ())) {
1511
+ capturedBase = SGF.B .createTrivialLoadOr (
1512
+ loc, capturedBase, LoadOwnershipQualifier::Take);
1513
+ }
1514
+
1515
+ capturedArgs.push_back (capturedBase);
1496
1516
}
1497
1517
1498
1518
PartialApplyInst *setterPAI =
1499
1519
SGF.B .createPartialApply (loc, setterFRef,
1500
- Substitutions, { capturedBase } ,
1520
+ Substitutions, capturedArgs ,
1501
1521
ParameterConvention::Direct_Guaranteed);
1502
1522
ManagedValue setterFn = SGF.emitManagedRValueWithCleanup (setterPAI);
1503
1523
0 commit comments