@@ -1477,78 +1477,6 @@ namespace {
1477
1477
1478
1478
return Mval;
1479
1479
}
1480
-
1481
- std::pair<SILValue, CanSILFunctionType>
1482
- applySetterToBase (SILGenFunction &SGF, SILLocation loc, SILDeclRef setter,
1483
- ManagedValue base) const {
1484
- auto setterFRef = [&]() -> SILValue {
1485
- auto setterInfo =
1486
- SGF.getConstantInfo (SGF.getTypeExpansionContext (), setter);
1487
- if (setter.hasDecl () && setter.getDecl ()->shouldUseObjCDispatch ()) {
1488
- // Emit a thunk we might have to bridge arguments.
1489
- auto foreignSetterThunk = setter.asForeign (false );
1490
- return SGF
1491
- .emitDynamicMethodRef (
1492
- loc, foreignSetterThunk,
1493
- SGF.SGM .Types
1494
- .getConstantInfo (SGF.getTypeExpansionContext (),
1495
- foreignSetterThunk)
1496
- .SILFnType )
1497
- .getValue ();
1498
- }
1499
-
1500
- return SGF.emitGlobalFunctionRef (loc, setter, setterInfo);
1501
- }();
1502
-
1503
- auto getSetterType = [&](SILValue setterFRef) {
1504
- CanSILFunctionType setterTy =
1505
- setterFRef->getType ().castTo <SILFunctionType>();
1506
- return setterTy->substGenericArgs (SGF.SGM .M , Substitutions,
1507
- SGF.getTypeExpansionContext ());
1508
- };
1509
-
1510
- auto setterTy = getSetterType (setterFRef);
1511
- SILFunctionConventions setterConv (setterTy, SGF.SGM .M );
1512
-
1513
- // Emit captures for the setter
1514
- SmallVector<SILValue, 4 > capturedArgs;
1515
- auto captureInfo = SGF.SGM .Types .getLoweredLocalCaptures (setter);
1516
- if (!captureInfo.getCaptures ().empty ()) {
1517
- SmallVector<ManagedValue, 4 > captures;
1518
- SGF.emitCaptures (loc, setter, CaptureEmission::AssignByWrapper,
1519
- captures);
1520
-
1521
- for (auto capture : captures)
1522
- capturedArgs.push_back (capture.forward (SGF));
1523
- } else {
1524
- assert (base);
1525
-
1526
- SILValue capturedBase;
1527
- unsigned argIdx = setterConv.getNumSILArguments () - 1 ;
1528
-
1529
- if (setterConv.getSILArgumentConvention (argIdx).isInoutConvention ()) {
1530
- capturedBase = base.getValue ();
1531
- } else if (base.getType ().isAddress () &&
1532
- base.getType ().getObjectType () ==
1533
- setterConv.getSILArgumentType (
1534
- argIdx, SGF.getTypeExpansionContext ())) {
1535
- // If the base is a reference and the setter expects a value, emit a
1536
- // load. This pattern is emitted for property wrappers with a
1537
- // nonmutating setter, for example.
1538
- capturedBase = SGF.B .createTrivialLoadOr (
1539
- loc, base.getValue (), LoadOwnershipQualifier::Copy);
1540
- } else {
1541
- capturedBase = base.copy (SGF, loc).forward (SGF);
1542
- }
1543
-
1544
- capturedArgs.push_back (capturedBase);
1545
- }
1546
-
1547
- PartialApplyInst *setterPAI =
1548
- SGF.B .createPartialApply (loc, setterFRef, Substitutions, capturedArgs,
1549
- ParameterConvention::Direct_Guaranteed);
1550
- return {SGF.emitManagedRValueWithCleanup (setterPAI).getValue (), setterTy};
1551
- }
1552
1480
};
1553
1481
1554
1482
class InitAccessorComponent
@@ -1593,8 +1521,8 @@ namespace {
1593
1521
CanSILFunctionType setterTy;
1594
1522
1595
1523
if (auto *setter = field->getOpaqueAccessor (AccessorKind::Set)) {
1596
- std::tie (setterFRef, setterTy) =
1597
- applySetterToBase (SGF, loc, SILDeclRef (setter), base);
1524
+ std::tie (setterFRef, setterTy) = SGF. emitApplyOfSetterToBase (
1525
+ loc, SILDeclRef (setter), base, Substitutions );
1598
1526
} else {
1599
1527
setterFRef = SILUndef::get (initFRef->getType (), SGF.F );
1600
1528
setterTy = initFRef->getType ().castTo <SILFunctionType>();
@@ -1897,7 +1825,7 @@ namespace {
1897
1825
SILValue setterFn;
1898
1826
CanSILFunctionType setterTy;
1899
1827
std::tie (setterFn, setterTy) =
1900
- applySetterToBase ( SGF, loc, Accessor, base);
1828
+ SGF. emitApplyOfSetterToBase ( loc, Accessor, base, Substitutions );
1901
1829
1902
1830
// Create the assign_by_wrapper with the initializer and setter.
1903
1831
0 commit comments