@@ -1397,6 +1397,7 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
13971397 case SILInstructionKind::InitExistentialRefInst:
13981398 case SILInstructionKind::MarkDependenceInst:
13991399 case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
1400+ case SILInstructionKind::MoveOnlyWrapperToCopyableBoxInst:
14001401 case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
14011402 return true ;
14021403 default :
@@ -8482,10 +8483,21 @@ class CopyableToMoveOnlyWrapperValueInst
84828483 DebugLoc, operand, operand->getType ().addingMoveOnlyWrapper(),
84838484 kind == InitialKind::Guaranteed ? OwnershipKind::Guaranteed
84848485 : OwnershipKind::Owned),
8485- initialKind(kind) {}
8486+ initialKind(kind) {
8487+ assert (!operand->getType ().isMoveOnly () &&
8488+ " Cannot be moveonly or moveonly wrapped" );
8489+ }
84868490
84878491public:
84888492 InitialKind getInitialKind () const { return initialKind; }
8493+
8494+ bool hasGuaranteedInitialKind () const {
8495+ return getInitialKind () == InitialKind::Guaranteed;
8496+ }
8497+
8498+ bool hasOwnedInitialKind () const {
8499+ return getInitialKind () == InitialKind::Owned;
8500+ }
84898501};
84908502
84918503// / Convert from an @moveOnly wrapper type to the underlying copyable type. Can
@@ -8534,10 +8546,71 @@ class MoveOnlyWrapperToCopyableValueInst
85348546 DebugLoc, operand, operand->getType ().removingMoveOnlyWrapper(),
85358547 kind == InitialKind::Guaranteed ? OwnershipKind::Guaranteed
85368548 : OwnershipKind::Owned),
8537- initialKind(kind) {}
8549+ initialKind(kind) {
8550+ assert (operand->getType ().isMoveOnlyWrapped () &&
8551+ " Expected moveonlywrapped argument!" );
8552+ }
85388553
85398554public:
85408555 InitialKind getInitialKind () const { return initialKind; }
8556+
8557+ bool hasGuaranteedInitialKind () const {
8558+ return getInitialKind () == InitialKind::Guaranteed;
8559+ }
8560+
8561+ bool hasOwnedInitialKind () const {
8562+ return getInitialKind () == InitialKind::Owned;
8563+ }
8564+ };
8565+
8566+ // / Convert a ${ @moveOnly T } to $T. This is a forwarding instruction that acts
8567+ // / similarly to an object cast like upcast, unlike
8568+ // / MoveOnlyWrapperToCopyableValue which provides artificial semantics injected
8569+ // / by SILGen.
8570+ class MoveOnlyWrapperToCopyableBoxInst
8571+ : public UnaryInstructionBase<
8572+ SILInstructionKind::MoveOnlyWrapperToCopyableBoxInst,
8573+ FirstArgOwnershipForwardingSingleValueInst> {
8574+ friend class SILBuilder ;
8575+
8576+ MoveOnlyWrapperToCopyableBoxInst (SILDebugLocation DebugLoc, SILValue operand,
8577+ ValueOwnershipKind forwardingOwnershipKind)
8578+ : UnaryInstructionBase(
8579+ DebugLoc, operand,
8580+ operand->getType ().removingMoveOnlyWrapperToBoxedType(
8581+ operand->getFunction ()),
8582+ forwardingOwnershipKind) {
8583+ assert (
8584+ operand->getType ().isBoxedMoveOnlyWrappedType (operand->getFunction ()) &&
8585+ " Expected moveonlywrapped argument!" );
8586+ }
8587+ };
8588+
8589+ class CopyableToMoveOnlyWrapperAddrInst
8590+ : public UnaryInstructionBase<
8591+ SILInstructionKind::CopyableToMoveOnlyWrapperAddrInst,
8592+ SingleValueInstruction> {
8593+ friend class SILBuilder ;
8594+
8595+ CopyableToMoveOnlyWrapperAddrInst (SILDebugLocation DebugLoc, SILValue operand)
8596+ : UnaryInstructionBase(DebugLoc, operand,
8597+ operand->getType ().addingMoveOnlyWrapper()) {
8598+ assert (!operand->getType ().isMoveOnly () && " Expected copyable argument" );
8599+ }
8600+ };
8601+
8602+ class MoveOnlyWrapperToCopyableAddrInst
8603+ : public UnaryInstructionBase<
8604+ SILInstructionKind::MoveOnlyWrapperToCopyableAddrInst,
8605+ SingleValueInstruction> {
8606+ friend class SILBuilder ;
8607+
8608+ MoveOnlyWrapperToCopyableAddrInst (SILDebugLocation DebugLoc, SILValue operand)
8609+ : UnaryInstructionBase(DebugLoc, operand,
8610+ operand->getType ().removingMoveOnlyWrapper()) {
8611+ assert (operand->getType ().isMoveOnlyWrapped () &&
8612+ " Expected moveonlywrapped argument" );
8613+ }
85418614};
85428615
85438616// / Given an object reference, return true iff it is non-nil and refers
0 commit comments