Skip to content

Commit ca16677

Browse files
authored
Merge pull request #70052 from atrick/comment_drop_deinit
SIL: comment drop_deinit instruction.
2 parents 5ba26d7 + 8bec26b commit ca16677

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
@@ -6410,6 +6410,23 @@ The instruction accepts an object or address type.
64106410
If its argument is an object type it takes in an `@owned T` and produces a new
64116411
`@owned T`. If its argument is an address type, it's an identity projection.
64126412

6413+
If the operand is an object type, then this is a pseudo type-cast. It
6414+
consumes its operand and produces a new value with the same nominal
6415+
struct or enum type, but as if the type had no user-defined
6416+
deinitializer. It's only use must be a an instruction that ends the
6417+
aggregate lifetime, such as `destroy_value`, `destructure_struct`, or
6418+
`switch_enum`. If the use is a `destroy_value`, then prevents the
6419+
destroy from invoking the deinitializer. For example::
6420+
6421+
%1 = drop_deinit %0 : $T
6422+
destroy_value %1 : $T // does not invoke deinit()
6423+
6424+
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::
6425+
6426+
%1 = drop_deinit %0 : $S
6427+
%2 = struct_element_addr %1 : $*T, #S.field
6428+
destroy_addr %2 : $T
6429+
64136430
The instruction is only valid in ownership SIL.
64146431

64156432
release_value

include/swift/SIL/SILInstruction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8410,6 +8410,9 @@ class MoveValueInst
84108410
bool isFromVarDecl() const { return sharedUInt8().MoveValueInst.fromVarDecl; }
84118411
};
84128412

8413+
/// Drop the user-defined deinitializer from a struct or enum. Takes either an
8414+
/// object or address operand and produces an object or address. See SIL.rst
8415+
/// for details. See SILVerifier.cpp for constraints on valid uses.
84138416
class DropDeinitInst
84148417
: public UnaryInstructionBase<SILInstructionKind::DropDeinitInst,
84158418
SingleValueInstruction> {

0 commit comments

Comments
 (0)