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