@@ -1560,7 +1560,7 @@ namespace {
1560
1560
ArgumentList *subscriptArgList,
1561
1561
PreparedArguments &&indices,
1562
1562
bool isOnSelfParameter,
1563
- Optional<ActorIsolation> actorIso)
1563
+ llvm:: Optional<ActorIsolation> actorIso)
1564
1564
: AccessorBasedComponent(
1565
1565
InitAccessorKind, decl, accessor, isSuper, isDirectAccessorUse,
1566
1566
substitutions, baseFormalType, typeData, subscriptArgList,
@@ -1587,9 +1587,14 @@ namespace {
1587
1587
1588
1588
SILValue setterFRef;
1589
1589
CanSILFunctionType setterTy;
1590
- std::tie (setterFRef, setterTy) = applySetterToBase (
1591
- SGF, loc, SILDeclRef (field->getOpaqueAccessor (AccessorKind::Set)),
1592
- base);
1590
+
1591
+ if (auto *setter = field->getOpaqueAccessor (AccessorKind::Set)) {
1592
+ std::tie (setterFRef, setterTy) =
1593
+ applySetterToBase (SGF, loc, SILDeclRef (setter), base);
1594
+ } else {
1595
+ setterFRef = SILUndef::get (initFRef->getType (), SGF.F );
1596
+ setterTy = initFRef->getType ().castTo <SILFunctionType>();
1597
+ }
1593
1598
1594
1599
auto Mval =
1595
1600
emitValue (SGF, loc, field, fieldType, std::move (value), setterTy);
@@ -1618,7 +1623,7 @@ namespace {
1618
1623
// / the same dynamic PathComponent type as the receiver) to see if they are
1619
1624
// / identical. If so, there is a conflicting writeback happening, so emit a
1620
1625
// / diagnostic.
1621
- Optional<AccessStorage> getAccessStorage () const override {
1626
+ llvm:: Optional<AccessStorage> getAccessStorage () const override {
1622
1627
return AccessStorage{Storage, IsSuper,
1623
1628
Indices.isNull () ? nullptr : &Indices,
1624
1629
ArgListForDiagnostics};
@@ -3095,8 +3100,12 @@ namespace {
3095
3100
case AccessorKind::DidSet:
3096
3101
llvm_unreachable (" cannot use accessor directly to perform an access" );
3097
3102
3098
- case AccessorKind::Init:
3099
- llvm_unreachable (" init accessor not yet implemented" );
3103
+ case AccessorKind::Init: {
3104
+ auto typeData =
3105
+ getLogicalStorageTypeData (SGF.getTypeExpansionContext (), SGF.SGM ,
3106
+ AccessKind, FormalRValueType);
3107
+ return asImpl ().emitUsingInitAccessor (accessor, isDirect, typeData);
3108
+ }
3100
3109
}
3101
3110
3102
3111
llvm_unreachable (" bad kind" );
@@ -3257,6 +3266,11 @@ void LValue::addNonMemberVarComponent(
3257
3266
llvm_unreachable (" cannot dispatch non-member var via distributed thunk" );
3258
3267
}
3259
3268
3269
+ void emitUsingInitAccessor (SILDeclRef accessor, bool isDirect,
3270
+ LValueTypeData typeData) {
3271
+ llvm_unreachable (" cannot dispatch non-member var via init accessor" );
3272
+ }
3273
+
3260
3274
} emitter(SGF, loc, var, subs, accessKind, formalRValueType, options,
3261
3275
actorIso, *this );
3262
3276
@@ -3789,6 +3803,13 @@ struct MemberStorageAccessEmitter : AccessEmitter<Impl, StorageType> {
3789
3803
BaseFormalType, typeData, ArgListForDiagnostics, std::move (Indices),
3790
3804
IsOnSelfParameter);
3791
3805
}
3806
+
3807
+ void emitUsingInitAccessor (SILDeclRef accessor, bool isDirect,
3808
+ LValueTypeData typeData) {
3809
+ LV.add <InitAccessorComponent>(
3810
+ Storage, accessor, IsSuper, isDirect, Subs, BaseFormalType, typeData,
3811
+ ArgListForDiagnostics, std::move (Indices), IsOnSelfParameter, ActorIso);
3812
+ }
3792
3813
};
3793
3814
} // end anonymous namespace
3794
3815
0 commit comments