Skip to content

Commit 0752ea5

Browse files
committed
Add OwnershipTransitionInstruction.
These instructions carry lifetime dependence from a single operand to a single result. They are not forwarding instructions because we use them to indicate the boundaries of a forwarded lifetime.
1 parent d7205ed commit 0752ea5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

SwiftCompilerSources/Sources/SIL/ForwardingInstruction.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,33 @@ extension LinearFunctionExtractInst: ForwardingInstruction {
397397
public var canForwardGuaranteedValues: Bool { true }
398398
public var canForwardOwnedValues: Bool { true }
399399
}
400+
401+
// -----------------------------------------------------------------------------
402+
// ownership transition instructions
403+
404+
/// An instruction that transfers lifetime dependence from a single operand to a single result. The operand and result
405+
/// have the same identity, but they are not part of the same forwarded lifetime:
406+
/// copy_value, move_value, begin_borrow.
407+
public protocol OwnershipTransitionInstruction: UnaryInstruction {
408+
var ownershipResult: Value { get }
409+
}
410+
411+
extension OwnershipTransitionInstruction where Self: SingleValueInstruction {
412+
public var ownershipResult: Value { self }
413+
}
414+
415+
// CopyingInstruction implies OwnershipTransitionInstruction
416+
417+
extension MoveValueInst: OwnershipTransitionInstruction {}
418+
419+
extension BeginBorrowInst: OwnershipTransitionInstruction {}
420+
421+
extension BeginCOWMutationInst: OwnershipTransitionInstruction {
422+
public var ownershipResult: Value { instanceResult }
423+
}
424+
425+
extension EndCOWMutationInst: OwnershipTransitionInstruction {}
426+
427+
extension EndInitLetRefInst: OwnershipTransitionInstruction {}
428+
429+
extension BeginDeallocRefInst: OwnershipTransitionInstruction {}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ final public class ProjectBoxInst : SingleValueInstruction, UnaryInstruction {
10411041

10421042
final public class ProjectExistentialBoxInst : SingleValueInstruction, UnaryInstruction {}
10431043

1044-
public protocol CopyingInstruction : SingleValueInstruction, UnaryInstruction {}
1044+
public protocol CopyingInstruction : SingleValueInstruction, UnaryInstruction, OwnershipTransitionInstruction {}
10451045

10461046
final public class CopyValueInst : SingleValueInstruction, CopyingInstruction {
10471047
public var fromValue: Value { operand.value }

0 commit comments

Comments
 (0)