@@ -832,25 +832,33 @@ class LetValueInitialization : public Initialization {
832832 ConsumableAndAssignable);
833833 }
834834
835- // Otherwise, if we do not have a no implicit copy variable, just follow
836- // the "normal path": perform a lexical borrow if the lifetime is lexical.
837- if (!vd->isNoImplicitCopy ()) {
838- return SGF.B .createBeginBorrow (
835+ // If we have a no implicit copy lexical, emit the instruction stream so
836+ // that the move checker knows to check this variable.
837+ if (vd->isNoImplicitCopy ()) {
838+ value = SGF.B .createMoveValue (PrologueLoc, value, /* isLexical*/ true ,
839+ /* hasPointerEscape=*/ false ,
840+ /* fromVarDecl=*/ true );
841+ value =
842+ SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (PrologueLoc, value);
843+ return SGF.B .createMarkUnresolvedNonCopyableValueInst (
839844 PrologueLoc, value,
840- /* isLexical= */ SGF. F . getLifetime (vd, value-> getType ()). isLexical (),
841- /* hasPointerEscape= */ false , /* fromVarDecl= */ true );
845+ MarkUnresolvedNonCopyableValueInst::CheckKind::
846+ ConsumableAndAssignable );
842847 }
843848
844- // If we have a no implicit copy lexical, emit the instruction stream so
845- // that the move checker knows to check this variable.
846- value = SGF.B .createBeginBorrow (
847- PrologueLoc, value,
848- /* isLexical*/ true , /* hasPointerEscape=*/ false , /* fromVarDecl=*/ true );
849- value = SGF.B .createCopyValue (PrologueLoc, value);
850- value = SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (PrologueLoc, value);
851- return SGF.B .createMarkUnresolvedNonCopyableValueInst (
852- PrologueLoc, value,
853- MarkUnresolvedNonCopyableValueInst::CheckKind::ConsumableAndAssignable);
849+ // Otherwise, if we do not have a no implicit copy variable, just follow
850+ // the "normal path".
851+
852+ auto isLexical = SGF.F .getLifetime (vd, value->getType ()).isLexical ();
853+
854+ if (value->getOwnershipKind () == OwnershipKind::Owned)
855+ return SGF.B .createMoveValue (PrologueLoc, value, /* isLexical*/ isLexical,
856+ /* hasPointerEscape=*/ false ,
857+ /* fromVarDecl=*/ true );
858+
859+ return SGF.B .createBeginBorrow (PrologueLoc, value, /* isLexical*/ isLexical,
860+ /* hasPointerEscape=*/ false ,
861+ /* fromVarDecl=*/ true );
854862 }
855863
856864 void bindValue (SILValue value, SILGenFunction &SGF, bool wasPlusOne,
@@ -2176,6 +2184,11 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21762184 return ;
21772185 }
21782186
2187+ if (auto *mvi = dyn_cast<MoveValueInst>(Val.getDefiningInstruction ())) {
2188+ B.emitDestroyValueOperation (silLoc, mvi);
2189+ return ;
2190+ }
2191+
21792192 if (auto *mvi = dyn_cast<MarkUnresolvedNonCopyableValueInst>(
21802193 Val.getDefiningInstruction ())) {
21812194 if (mvi->hasMoveCheckerKind ()) {
@@ -2192,14 +2205,10 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21922205
21932206 if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
21942207 mvi->getOperand ())) {
2195- if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand ())) {
2196- if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand ())) {
2197- if (bbi->isLexical ()) {
2198- B.emitDestroyValueOperation (silLoc, mvi);
2199- B.createEndBorrow (silLoc, bbi);
2200- B.emitDestroyValueOperation (silLoc, bbi->getOperand ());
2201- return ;
2202- }
2208+ if (auto *move = dyn_cast<MoveValueInst>(copyToMove->getOperand ())) {
2209+ if (move->isLexical ()) {
2210+ B.emitDestroyValueOperation (silLoc, mvi);
2211+ return ;
22032212 }
22042213 }
22052214 }
0 commit comments