Skip to content

Commit 8bec26b

Browse files
committed
SIL: comment drop_deinit instruction.
1 parent badac8f commit 8bec26b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

docs/SIL.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6396,6 +6396,23 @@ The instruction accepts an object or address type.
63966396
If its argument is an object type it takes in an `@owned T` and produces a new
63976397
`@owned T`. If its argument is an address type, it's an identity projection.
63986398

6399+
If the operand is an object type, then this is a pseudo type-cast. It
6400+
consumes its operand and produces a new value with the same nominal
6401+
struct or enum type, but as if the type had no user-defined
6402+
deinitializer. It's only use must be a an instruction that ends the
6403+
aggregate lifetime, such as `destroy_value`, `destructure_struct`, or
6404+
`switch_enum`. If the use is a `destroy_value`, then prevents the
6405+
destroy from invoking the deinitializer. For example::
6406+
6407+
%1 = drop_deinit %0 : $T
6408+
destroy_value %1 : $T // does not invoke deinit()
6409+
6410+
If the operand and result are addresses, drop_deinit ends the lifetime of the referenced memory value while keeping the value's fields or enum cases alive. The deinit of the value is not called. The returned address can be used to access the value's field, e.g. with struct_element_addr, or enum cases with switch_enum_addr. After the drop_deinit, it is illegal to destroy its operand or result address with destroy_addr. For example::
6411+
6412+
%1 = drop_deinit %0 : $S
6413+
%2 = struct_element_addr %1 : $*T, #S.field
6414+
destroy_addr %2 : $T
6415+
63996416
The instruction is only valid in ownership SIL.
64006417

64016418
release_value

include/swift/SIL/SILInstruction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8402,6 +8402,9 @@ class MoveValueInst
84028402
}
84038403
};
84048404

8405+
/// Drop the user-defined deinitializer from a struct or enum. Takes either an
8406+
/// object or address operand and produces an object or address. See SIL.rst
8407+
/// for details. See SILVerifier.cpp for constraints on valid uses.
84058408
class DropDeinitInst
84068409
: public UnaryInstructionBase<SILInstructionKind::DropDeinitInst,
84078410
SingleValueInstruction> {

0 commit comments

Comments
 (0)