Skip to content

Commit 2194aa5

Browse files
committed
ABI.rst: Document enum reflection metadata
1 parent ca7254c commit 2194aa5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

docs/ABI.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,23 @@ layout is as follows:
612612

613613
* For an enum:
614614

615-
+ TODO: Offsets 2-5 are always zero.
615+
+ The **number of payload cases** and **payload size offset** are stored
616+
at **offset 2**. The least significant 24 bits are the number of payload
617+
cases, and the most significant 8 bits are the offset of the payload
618+
size in the type metadata, if present.
619+
+ The **number of no-payload cases** is stored at **offset 3**.
620+
+ The **case names** are referenced as a doubly-null-terminated list of
621+
C strings at **offset 4**. The names are ordered such that payload cases
622+
come first, followed by no-payload cases. Within each half of the list,
623+
the order of names corresponds to the order of cases in the enum
624+
declaration.
625+
+ The **case type accessor** is a function pointer at **offset 5**. If
626+
non-null, the function takes a pointer to an instance of type metadata
627+
for the enum, and returns a pointer to an array of type metadata
628+
references for the types of the cases of that instance. The order matches
629+
that of the case name list. This function is similar to the field type
630+
accessor for a struct, except also the least significant bit of each
631+
element in the result is set if the enum case is an **indirect case**.
616632

617633
- If the nominal type is generic, a pointer to the **metadata pattern** that
618634
is used to form instances of the type is stored at **offset 6**. The pointer
@@ -1047,6 +1063,8 @@ the outermost depth::
10471063
Value Witnesses
10481064
~~~~~~~~~~~~~~~
10491065

1066+
TODO: document these
1067+
10501068
::
10511069

10521070
value-witness-kind ::= 'al' // allocateBuffer
@@ -1065,11 +1083,11 @@ Value Witnesses
10651083
value-witness-kind ::= 'pr' // projectBuffer
10661084
value-witness-kind ::= 'xs' // storeExtraInhabitant
10671085
value-witness-kind ::= 'xg' // getExtraInhabitantIndex
1068-
value-witness-kind ::= 'ug' // getEnumTag
1069-
value-witness-kind ::= 'up' // inplaceProjectEnumData
10701086
value-witness-kind ::= 'Cc' // initializeArrayWithCopy
10711087
value-witness-kind ::= 'Tt' // initializeArrayWithTakeFrontToBack
10721088
value-witness-kind ::= 'tT' // initializeArrayWithTakeBackToFront
1089+
value-witness-kind ::= 'ug' // getEnumTag
1090+
value-witness-kind ::= 'up' // destructiveProjectEnumData
10731091

10741092
``<value-witness-kind>`` differentiates the kinds of value
10751093
witness functions for a type.

0 commit comments

Comments
 (0)