@@ -832,25 +832,33 @@ class LetValueInitialization : public Initialization {
832
832
ConsumableAndAssignable);
833
833
}
834
834
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 (
839
844
PrologueLoc, value,
840
- /* isLexical= */ SGF. F . getLifetime (vd, value-> getType ()). isLexical (),
841
- /* hasPointerEscape= */ false , /* fromVarDecl= */ true );
845
+ MarkUnresolvedNonCopyableValueInst::CheckKind::
846
+ ConsumableAndAssignable );
842
847
}
843
848
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 );
854
862
}
855
863
856
864
void bindValue (SILValue value, SILGenFunction &SGF, bool wasPlusOne,
@@ -2176,6 +2184,11 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
2176
2184
return ;
2177
2185
}
2178
2186
2187
+ if (auto *mvi = dyn_cast<MoveValueInst>(Val.getDefiningInstruction ())) {
2188
+ B.emitDestroyValueOperation (silLoc, mvi);
2189
+ return ;
2190
+ }
2191
+
2179
2192
if (auto *mvi = dyn_cast<MarkUnresolvedNonCopyableValueInst>(
2180
2193
Val.getDefiningInstruction ())) {
2181
2194
if (mvi->hasMoveCheckerKind ()) {
@@ -2192,14 +2205,10 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
2192
2205
2193
2206
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
2194
2207
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 ;
2203
2212
}
2204
2213
}
2205
2214
}
0 commit comments