@@ -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 :
@@ -8516,10 +8517,21 @@ class CopyableToMoveOnlyWrapperValueInst
85168517 DebugLoc, operand, operand->getType ().addingMoveOnlyWrapper(),
85178518 kind == InitialKind::Guaranteed ? OwnershipKind::Guaranteed
85188519 : OwnershipKind::Owned),
8519- initialKind(kind) {}
8520+ initialKind(kind) {
8521+ assert (!operand->getType ().isMoveOnly () &&
8522+ " Cannot be moveonly or moveonly wrapped" );
8523+ }
85208524
85218525public:
85228526 InitialKind getInitialKind () const { return initialKind; }
8527+
8528+ bool hasGuaranteedInitialKind () const {
8529+ return getInitialKind () == InitialKind::Guaranteed;
8530+ }
8531+
8532+ bool hasOwnedInitialKind () const {
8533+ return getInitialKind () == InitialKind::Owned;
8534+ }
85238535};
85248536
85258537// / Convert from an @moveOnly wrapper type to the underlying copyable type. Can
@@ -8568,10 +8580,71 @@ class MoveOnlyWrapperToCopyableValueInst
85688580 DebugLoc, operand, operand->getType ().removingMoveOnlyWrapper(),
85698581 kind == InitialKind::Guaranteed ? OwnershipKind::Guaranteed
85708582 : OwnershipKind::Owned),
8571- initialKind(kind) {}
8583+ initialKind(kind) {
8584+ assert (operand->getType ().isMoveOnlyWrapped () &&
8585+ " Expected moveonlywrapped argument!" );
8586+ }
85728587
85738588public:
85748589 InitialKind getInitialKind () const { return initialKind; }
8590+
8591+ bool hasGuaranteedInitialKind () const {
8592+ return getInitialKind () == InitialKind::Guaranteed;
8593+ }
8594+
8595+ bool hasOwnedInitialKind () const {
8596+ return getInitialKind () == InitialKind::Owned;
8597+ }
8598+ };
8599+
8600+ // / Convert a ${ @moveOnly T } to $T. This is a forwarding instruction that acts
8601+ // / similarly to an object cast like upcast, unlike
8602+ // / MoveOnlyWrapperToCopyableValue which provides artificial semantics injected
8603+ // / by SILGen.
8604+ class MoveOnlyWrapperToCopyableBoxInst
8605+ : public UnaryInstructionBase<
8606+ SILInstructionKind::MoveOnlyWrapperToCopyableBoxInst,
8607+ FirstArgOwnershipForwardingSingleValueInst> {
8608+ friend class SILBuilder ;
8609+
8610+ MoveOnlyWrapperToCopyableBoxInst (SILDebugLocation DebugLoc, SILValue operand,
8611+ ValueOwnershipKind forwardingOwnershipKind)
8612+ : UnaryInstructionBase(
8613+ DebugLoc, operand,
8614+ operand->getType ().removingMoveOnlyWrapperToBoxedType(
8615+ operand->getFunction ()),
8616+ forwardingOwnershipKind) {
8617+ assert (
8618+ operand->getType ().isBoxedMoveOnlyWrappedType (operand->getFunction ()) &&
8619+ " Expected moveonlywrapped argument!" );
8620+ }
8621+ };
8622+
8623+ class CopyableToMoveOnlyWrapperAddrInst
8624+ : public UnaryInstructionBase<
8625+ SILInstructionKind::CopyableToMoveOnlyWrapperAddrInst,
8626+ SingleValueInstruction> {
8627+ friend class SILBuilder ;
8628+
8629+ CopyableToMoveOnlyWrapperAddrInst (SILDebugLocation DebugLoc, SILValue operand)
8630+ : UnaryInstructionBase(DebugLoc, operand,
8631+ operand->getType ().addingMoveOnlyWrapper()) {
8632+ assert (!operand->getType ().isMoveOnly () && " Expected copyable argument" );
8633+ }
8634+ };
8635+
8636+ class MoveOnlyWrapperToCopyableAddrInst
8637+ : public UnaryInstructionBase<
8638+ SILInstructionKind::MoveOnlyWrapperToCopyableAddrInst,
8639+ SingleValueInstruction> {
8640+ friend class SILBuilder ;
8641+
8642+ MoveOnlyWrapperToCopyableAddrInst (SILDebugLocation DebugLoc, SILValue operand)
8643+ : UnaryInstructionBase(DebugLoc, operand,
8644+ operand->getType ().removingMoveOnlyWrapper()) {
8645+ assert (operand->getType ().isMoveOnlyWrapped () &&
8646+ " Expected moveonlywrapped argument" );
8647+ }
85758648};
85768649
85778650// / Given an object reference, return true iff it is non-nil and refers
0 commit comments