Skip to content

Commit 02d7fe5

Browse files
committed
Document the difference of embedded swift's swift_allocBox
1 parent 84501bd commit 02d7fe5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ public func swift_allocEmptyBox() -> Builtin.RawPointer {
261261
return box
262262
}
263263

264+
/// The embedded swift_allocBox version is different to the standad one in that
265+
/// we want to avoid building metadata for the box type. Instead we store the
266+
/// metadata of the contained type in the heap object. To make this work when
267+
/// destroying the box the release needs to be special i.e `swift_releaseBox`.
268+
/// It does not call the the heap object metadata's destroy function. Rather, it
269+
/// knows that the allocBox's metadata is the contained objects and calls an
270+
/// appropriate implementation: `_swift_embedded_invoke_box_destroy`.
271+
/// Therefore, one cannot not use `swift_release` but rather must use
272+
/// `swift_releaseBox` to implement the "release" function of a box object.
264273

265274
@_silgen_name("swift_allocBox")
266275
public func swift_allocBox(_ metadata: Builtin.RawPointer) -> (Builtin.RawPointer, Builtin.RawPointer) {

0 commit comments

Comments
 (0)