@@ -717,20 +717,20 @@ SILValue SILGenFunction::emitEmptyTuple(SILLocation loc) {
717
717
718
718
namespace {
719
719
720
- // / This is a simple cleanup class that is only meant to help with delegating
721
- // / initializers. Specifically, if the delegating initializer fails to consume
722
- // / the loaded self, we want to write back self into the slot to ensure that
723
- // / ownership is preserved .
724
- struct DelegateInitSelfWritebackCleanup : Cleanup {
720
+ // / This is a simple cleanup class that at the end of a lexical scope consumes
721
+ // / an owned value by writing it back to memory. The user can forward this
722
+ // / cleanup to take ownership of the value and thus prevent it form being
723
+ // / written back .
724
+ struct OwnedValueWritebackCleanup final : Cleanup {
725
725
726
726
// / We store our own loc so that we can ensure that DI ignores our writeback.
727
727
SILLocation loc;
728
728
729
729
SILValue lvalueAddress;
730
730
SILValue value;
731
731
732
- DelegateInitSelfWritebackCleanup (SILLocation loc, SILValue lvalueAddress,
733
- SILValue value)
732
+ OwnedValueWritebackCleanup (SILLocation loc, SILValue lvalueAddress,
733
+ SILValue value)
734
734
: loc(loc), lvalueAddress(lvalueAddress), value(value) {}
735
735
736
736
void emit (SILGenFunction &SGF, CleanupLocation l, ForUnwind_t forUnwind) override {
@@ -749,14 +749,13 @@ struct DelegateInitSelfWritebackCleanup : Cleanup {
749
749
lvalueObjTy);
750
750
}
751
751
752
- auto &lowering = SGF.B .getTypeLowering (lvalueAddress->getType ());
753
- lowering.emitStore (SGF.B , loc, valueToStore, lvalueAddress,
754
- StoreOwnershipQualifier::Init);
752
+ SGF.B .emitStoreValueOperation (loc, valueToStore, lvalueAddress,
753
+ StoreOwnershipQualifier::Init);
755
754
}
756
755
757
756
void dump (SILGenFunction &) const override {
758
757
#ifndef NDEBUG
759
- llvm::errs () << " SimpleWritebackCleanup "
758
+ llvm::errs () << " OwnedValueWritebackCleanup "
760
759
<< " State:" << getState () << " \n "
761
760
<< " lvalueAddress:" << lvalueAddress << " value:" << value
762
761
<< " \n " ;
@@ -766,10 +765,9 @@ struct DelegateInitSelfWritebackCleanup : Cleanup {
766
765
767
766
} // end anonymous namespace
768
767
769
- CleanupHandle SILGenFunction::enterDelegateInitSelfWritebackCleanup (
768
+ CleanupHandle SILGenFunction::enterOwnedValueWritebackCleanup (
770
769
SILLocation loc, SILValue address, SILValue newValue) {
771
- Cleanups.pushCleanup <DelegateInitSelfWritebackCleanup>(loc, address,
772
- newValue);
770
+ Cleanups.pushCleanup <OwnedValueWritebackCleanup>(loc, address, newValue);
773
771
return Cleanups.getTopCleanup ();
774
772
}
775
773
@@ -815,8 +813,8 @@ RValue SILGenFunction::emitRValueForSelfInDelegationInit(SILLocation loc,
815
813
// Forward our initial value for init delegation self and create a new
816
814
// cleanup that performs a writeback at the end of lexical scope if our
817
815
// value is not consumed.
818
- InitDelegationSelf = ManagedValue (
819
- self, enterDelegateInitSelfWritebackCleanup (*InitDelegationLoc, addr, self));
816
+ InitDelegationSelf = ManagedValue::forExclusivelyBorrowedOwnedObjectRValue (
817
+ self, enterOwnedValueWritebackCleanup (*InitDelegationLoc, addr, self));
820
818
InitDelegationSelfBox = addr;
821
819
return RValue (*this , loc, refType, InitDelegationSelf);
822
820
}
0 commit comments