@@ -1439,8 +1439,23 @@ namespace {
1439
1439
}
1440
1440
1441
1441
ManagedValue emitValue (SILGenFunction &SGF, SILLocation loc, VarDecl *field,
1442
- Type fieldType, ArgumentSource &&value,
1443
- CanSILFunctionType accessorTy) {
1442
+ ArgumentSource &&value, AccessorKind accessorKind) {
1443
+ auto accessorInfo = SGF.getConstantInfo (
1444
+ SGF.getTypeExpansionContext (),
1445
+ SILDeclRef (field->getOpaqueAccessor (accessorKind)));
1446
+
1447
+ auto fieldTy = field->getValueInterfaceType ();
1448
+ auto accessorTy = SGF.SGM .Types
1449
+ .getLoweredType (accessorInfo.SILFnType ,
1450
+ SGF.getTypeExpansionContext ())
1451
+ .castTo <SILFunctionType>();
1452
+
1453
+ if (!Substitutions.empty ()) {
1454
+ fieldTy = fieldTy.subst (Substitutions);
1455
+ accessorTy = accessorTy->substGenericArgs (
1456
+ SGF.SGM .M , Substitutions, SGF.getTypeExpansionContext ());
1457
+ }
1458
+
1444
1459
SILFunctionConventions accessorConv (accessorTy, SGF.SGM .M );
1445
1460
1446
1461
// FIXME: This should use CallEmission instead of doing everything
@@ -1454,19 +1469,23 @@ namespace {
1454
1469
loweredSubstArgType =
1455
1470
SILType::getPrimitiveAddressType (loweredSubstArgType.getASTType ());
1456
1471
}
1472
+
1457
1473
auto loweredSubstParamTy = SILType::getPrimitiveType (
1458
1474
param.getArgumentType (SGF.SGM .M , accessorTy,
1459
1475
SGF.getTypeExpansionContext ()),
1460
1476
loweredSubstArgType.getCategory ());
1477
+
1461
1478
// Handle reabstraction differences.
1462
1479
if (Mval.getType () != loweredSubstParamTy) {
1463
1480
Mval = SGF.emitSubstToOrigValue (
1464
1481
loc, Mval, SGF.SGM .Types .getAbstractionPattern (field),
1465
- fieldType ->getCanonicalType ());
1482
+ fieldTy ->getCanonicalType ());
1466
1483
}
1467
1484
1485
+ auto newValueArgIdx = accessorConv.getNumIndirectSILResults ();
1468
1486
// If we need the argument in memory, materialize an address.
1469
- if (accessorConv.getSILArgumentConvention (0 ).isIndirectConvention () &&
1487
+ if (accessorConv.getSILArgumentConvention (newValueArgIdx)
1488
+ .isIndirectConvention () &&
1470
1489
!Mval.getType ().isAddress ()) {
1471
1490
Mval = Mval.materialize (SGF, loc);
1472
1491
}
@@ -1503,29 +1522,21 @@ namespace {
1503
1522
void set (SILGenFunction &SGF, SILLocation loc, ArgumentSource &&value,
1504
1523
ManagedValue base) &&
1505
1524
override {
1506
- VarDecl *field = cast<VarDecl>(Storage);
1507
- auto fieldType = field->getValueInterfaceType ();
1508
- if (!Substitutions.empty ()) {
1509
- fieldType = fieldType.subst (Substitutions);
1510
- }
1511
-
1525
+ auto *field = cast<VarDecl>(Storage);
1512
1526
// Emit the init accessor function partially applied to the base.
1513
1527
SILValue initFRef =
1514
1528
emitPartialInitAccessorReference (SGF, loc, getAccessorDecl ());
1515
1529
1516
1530
SILValue setterFRef;
1517
- CanSILFunctionType setterTy;
1518
-
1519
1531
if (auto *setter = field->getOpaqueAccessor (AccessorKind::Set)) {
1520
- std::tie ( setterFRef, setterTy) = SGF.emitApplyOfSetterToBase (
1521
- loc, SILDeclRef (setter), base, Substitutions);
1532
+ setterFRef = SGF.emitApplyOfSetterToBase (loc, SILDeclRef (setter), base,
1533
+ Substitutions);
1522
1534
} else {
1523
1535
setterFRef = SILUndef::get (initFRef->getType (), SGF.F );
1524
- setterTy = initFRef->getType ().castTo <SILFunctionType>();
1525
1536
}
1526
1537
1527
1538
auto Mval =
1528
- emitValue (SGF, loc, field, fieldType, std::move (value), setterTy );
1539
+ emitValue (SGF, loc, field, std::move (value), AccessorKind::Init );
1529
1540
1530
1541
SGF.B .createAssignOrInit (loc, base.getValue (), Mval.forward (SGF),
1531
1542
initFRef, setterFRef, AssignOrInitInst::Unknown);
@@ -1818,15 +1829,13 @@ namespace {
1818
1829
ManagedValue initFn = SGF.emitManagedRValueWithCleanup (initPAI);
1819
1830
1820
1831
// Create the allocating setter function. It captures the base address.
1821
- SILValue setterFn;
1822
- CanSILFunctionType setterTy;
1823
- std::tie (setterFn, setterTy) =
1832
+ SILValue setterFn =
1824
1833
SGF.emitApplyOfSetterToBase (loc, Accessor, base, Substitutions);
1825
1834
1826
1835
// Create the assign_by_wrapper with the initializer and setter.
1827
1836
1828
1837
auto Mval =
1829
- emitValue (SGF, loc, field, FieldType, std::move (value), setterTy );
1838
+ emitValue (SGF, loc, field, std::move (value), AccessorKind::Set );
1830
1839
1831
1840
SGF.B .createAssignByWrapper (loc, Mval.forward (SGF), proj.forward (SGF),
1832
1841
initFn.getValue (), setterFn,
0 commit comments