Skip to content

Commit 8f22966

Browse files
committed
[move-function] Emit mark_unresolved_move_addr when we inline Builtin._move in a generic context.
This turns off the diagnostic that prevented the user from calling _move in such contexts. I left that in for _copy.
1 parent d74299e commit 8f22966

File tree

10 files changed

+39
-34
lines changed

10 files changed

+39
-34
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,10 +1271,11 @@ class SILBuilder {
12711271
MoveValueInst(getSILDebugLocation(loc), operand));
12721272
}
12731273

1274-
MarkUnresolvedMoveAddrInst *createMarkUnresolvedMoveAddr(SILLocation loc, SILValue srcAddr,
1275-
SILValue takeAddr) {
1276-
return insert(new (getModule()) MarkUnresolvedMoveAddrInst(getSILDebugLocation(loc),
1277-
srcAddr, takeAddr));
1274+
MarkUnresolvedMoveAddrInst *createMarkUnresolvedMoveAddr(SILLocation loc,
1275+
SILValue srcAddr,
1276+
SILValue takeAddr) {
1277+
return insert(new (getModule()) MarkUnresolvedMoveAddrInst(
1278+
getSILDebugLocation(loc), srcAddr, takeAddr));
12781279
}
12791280

12801281
UnconditionalCheckedCastInst *

include/swift/SIL/SILCloner.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,11 +1342,12 @@ SILCloner<ImplClass>::visitCopyAddrInst(CopyAddrInst *Inst) {
13421342
}
13431343

13441344
template <typename ImplClass>
1345-
void SILCloner<ImplClass>::visitMarkUnresolvedMoveAddrInst(MarkUnresolvedMoveAddrInst *Inst) {
1345+
void SILCloner<ImplClass>::visitMarkUnresolvedMoveAddrInst(
1346+
MarkUnresolvedMoveAddrInst *Inst) {
13461347
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1347-
auto *MVI = getBuilder().createMarkUnresolvedMoveAddr(getOpLocation(Inst->getLoc()),
1348-
getOpValue(Inst->getSrc()),
1349-
getOpValue(Inst->getDest()));
1348+
auto *MVI = getBuilder().createMarkUnresolvedMoveAddr(
1349+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getSrc()),
1350+
getOpValue(Inst->getDest()));
13501351
recordClonedInstruction(Inst, MVI);
13511352
}
13521353

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7439,7 +7439,7 @@ class MarkUnresolvedMoveAddrInst
74397439
FixedOperandList<2> Operands;
74407440

74417441
MarkUnresolvedMoveAddrInst(SILDebugLocation DebugLoc, SILValue srcAddr,
7442-
SILValue takeAddr)
7442+
SILValue takeAddr)
74437443
: InstructionBase(DebugLoc), Operands(this, srcAddr, takeAddr) {}
74447444

74457445
public:

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,8 @@ bool SILInstruction::mayRelease() const {
11671167
return CopyAddr->isInitializationOfDest() ==
11681168
IsInitialization_t::IsNotInitialization;
11691169
}
1170-
// mark_unresolved_move_addr is equivalent to a copy_addr [init], so a release does not
1171-
// occur.
1170+
// mark_unresolved_move_addr is equivalent to a copy_addr [init], so a release
1171+
// does not occur.
11721172
case SILInstructionKind::MarkUnresolvedMoveAddrInst:
11731173
return false;
11741174

lib/SIL/Utils/MemoryLocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ bool MemoryLocations::analyzeLocationUsesRecursively(SILValue V, unsigned locIdx
367367
break;
368368
case SILInstructionKind::MarkUnresolvedMoveAddrInst:
369369
// We do not want the memory lifetime verifier to verify move_addr inst
370-
// since the MarkUnresolvedMoveAddrChecker will validate that its uses are
371-
// correct.
370+
// since the MarkUnresolvedMoveAddrChecker will validate that its uses
371+
// are correct.
372372
return false;
373373
default:
374374
return false;

lib/SIL/Verifier/LoadBorrowImmutabilityChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
177177
}
178178

179179
// This operand is the move source, we just return true. This is because
180-
// mark_unresolved_move_addr semantically is treated as a copy_addr of the source. The
181-
// checker determines if we can convert it to a move.
180+
// mark_unresolved_move_addr semantically is treated as a copy_addr of the
181+
// source. The checker determines if we can convert it to a move.
182182
return true;
183183

184184
// If this value is dependent on another, conservatively consider it a write.

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,9 @@ struct ImmutableAddressUseVerifier {
593593
case SILInstructionKind::EndAccessInst:
594594
break;
595595
case SILInstructionKind::MarkUnresolvedMoveAddrInst:
596-
// We model mark_unresolved_move_addr as a copy_addr [init]. So no mutation can
597-
// happen. The checker will prove eventually that we can convert it to a
598-
// copy_addr [take] [init].
596+
// We model mark_unresolved_move_addr as a copy_addr [init]. So no
597+
// mutation can happen. The checker will prove eventually that we can
598+
// convert it to a copy_addr [take] [init].
599599
break;
600600
case SILInstructionKind::CopyAddrInst:
601601
if (isConsumingOrMutatingCopyAddrUse(use))

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ MemBehavior MemoryBehaviorVisitor::visitCopyAddrInst(CopyAddrInst *CAI) {
302302
return MemBehavior::None;
303303
}
304304

305-
MemBehavior
306-
MemoryBehaviorVisitor::visitMarkUnresolvedMoveAddrInst(MarkUnresolvedMoveAddrInst *MAI) {
305+
MemBehavior MemoryBehaviorVisitor::visitMarkUnresolvedMoveAddrInst(
306+
MarkUnresolvedMoveAddrInst *MAI) {
307307
bool mayWrite = mayAlias(MAI->getDest());
308308
bool mayRead = mayAlias(MAI->getSrc());
309309

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -660,24 +660,27 @@ void SILInlineCloner::visitBuiltinInst(BuiltinInst *Inst) {
660660
auto otherResultAddr = getOpValue(Inst->getOperand(0));
661661
auto otherSrcAddr = getOpValue(Inst->getOperand(1));
662662
auto otherType = otherSrcAddr->getType();
663-
664-
if (!otherType.isLoadable(*Inst->getFunction())) {
665-
// If otherType is not loadable, emit a diagnostic since it was used
666-
// on a generic or existential value.
667-
diagnose(Inst->getModule().getASTContext(),
668-
getOpLocation(Inst->getLoc()).getSourceLoc(),
669-
diag::move_operator_used_on_generic_or_existential_value);
670-
return SILCloner<SILInlineCloner>::visitBuiltinInst(Inst);
671-
}
663+
auto opLoc = getOpLocation(Inst->getLoc());
672664

673665
// If our otherType is loadable, convert it to move_value.
674666
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
675-
// We stash otherValue in originalOtherValue in case we need to
676-
// perform a writeback.
677-
auto opLoc = getOpLocation(Inst->getLoc());
667+
668+
if (!otherType.isLoadable(*Inst->getFunction())) {
669+
// If otherType is not loadable, convert the builtin to a
670+
// mark_unresolved_move_addr. This builtin is a +1, but
671+
// mark_unresolved_move_addr simulates a +0, so we put in our own
672+
// destroy_addr.
673+
getBuilder().createMarkUnresolvedMoveAddr(opLoc, otherSrcAddr,
674+
otherResultAddr);
675+
getBuilder().createDestroyAddr(opLoc, otherSrcAddr);
676+
auto *tup = getBuilder().createTuple(opLoc, {});
677+
return recordFoldedValue(Inst, tup);
678+
}
678679

679680
assert(otherType.isAddress());
680681

682+
// We stash otherValue in originalOtherValue in case we need to
683+
// perform a writeback.
681684
SILValue otherValue = getBuilder().emitLoadValueOperation(
682685
opLoc, otherSrcAddr, LoadOwnershipQualifier::Take);
683686

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,8 +2107,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
21072107
case SILInstructionKind::MarkUnresolvedMoveAddrInst: {
21082108
auto Ty = MF->getType(TyID);
21092109
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory, Fn);
2110-
ResultInst = Builder.createMarkUnresolvedMoveAddr(Loc, getLocalValue(ValID, addrType),
2111-
getLocalValue(ValID2, addrType));
2110+
ResultInst = Builder.createMarkUnresolvedMoveAddr(
2111+
Loc, getLocalValue(ValID, addrType), getLocalValue(ValID2, addrType));
21122112
break;
21132113
}
21142114

0 commit comments

Comments
 (0)