@@ -717,20 +717,20 @@ SILValue SILGenFunction::emitEmptyTuple(SILLocation loc) {
717717
718718namespace {
719719
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 {
725725
726726 // / We store our own loc so that we can ensure that DI ignores our writeback.
727727 SILLocation loc;
728728
729729 SILValue lvalueAddress;
730730 SILValue value;
731731
732- DelegateInitSelfWritebackCleanup (SILLocation loc, SILValue lvalueAddress,
733- SILValue value)
732+ OwnedValueWritebackCleanup (SILLocation loc, SILValue lvalueAddress,
733+ SILValue value)
734734 : loc(loc), lvalueAddress(lvalueAddress), value(value) {}
735735
736736 void emit (SILGenFunction &SGF, CleanupLocation l, ForUnwind_t forUnwind) override {
@@ -749,14 +749,13 @@ struct DelegateInitSelfWritebackCleanup : Cleanup {
749749 lvalueObjTy);
750750 }
751751
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);
755754 }
756755
757756 void dump (SILGenFunction &) const override {
758757#ifndef NDEBUG
759- llvm::errs () << " SimpleWritebackCleanup "
758+ llvm::errs () << " OwnedValueWritebackCleanup "
760759 << " State:" << getState () << " \n "
761760 << " lvalueAddress:" << lvalueAddress << " value:" << value
762761 << " \n " ;
@@ -766,10 +765,9 @@ struct DelegateInitSelfWritebackCleanup : Cleanup {
766765
767766} // end anonymous namespace
768767
769- CleanupHandle SILGenFunction::enterDelegateInitSelfWritebackCleanup (
768+ CleanupHandle SILGenFunction::enterOwnedValueWritebackCleanup (
770769 SILLocation loc, SILValue address, SILValue newValue) {
771- Cleanups.pushCleanup <DelegateInitSelfWritebackCleanup>(loc, address,
772- newValue);
770+ Cleanups.pushCleanup <OwnedValueWritebackCleanup>(loc, address, newValue);
773771 return Cleanups.getTopCleanup ();
774772}
775773
@@ -815,8 +813,8 @@ RValue SILGenFunction::emitRValueForSelfInDelegationInit(SILLocation loc,
815813 // Forward our initial value for init delegation self and create a new
816814 // cleanup that performs a writeback at the end of lexical scope if our
817815 // value is not consumed.
818- InitDelegationSelf = ManagedValue (
819- self, enterDelegateInitSelfWritebackCleanup (*InitDelegationLoc, addr, self));
816+ InitDelegationSelf = ManagedValue::forExclusivelyBorrowedOwnedObjectRValue (
817+ self, enterOwnedValueWritebackCleanup (*InitDelegationLoc, addr, self));
820818 InitDelegationSelfBox = addr;
821819 return RValue (*this , loc, refType, InitDelegationSelf);
822820 }
0 commit comments