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