Data Layout
Part of the Sun ABI draft. These are proposed requirements, not guarantees of current releases. Open decisions must be resolved before stabilization.
Data layout
Imagine a library returning a rectangle. These offsets are hypothetical, not Sun's specified layout:
producer: width at offset 0, height at offset 8
consumer: reads height at offset 8 → agrees
consumer: reads height at offset 4 → wrong bytes; rejectEven if height is public and the preceding field is private, the consumer must
use the producer's layout. “Private” does not remove the bytes from the value.
| Minimal example | Level | Requirement |
|---|---|---|
area reads a Rectangle created by another bundle. | MUST | Define each type's layout for its ABI revision and target profile. |
A private field before height changes its offset. | MUST | Preserve the producer's layout, including private fields that determine a public value's size. |
| An array indexes its second rectangle using the element stride. | MUST | Specify size, alignment, field offsets, array stride, valid representations, and padding. |
| Two equal rectangles have different unused padding bytes. | MUST NOT | Treat padding as initialized application data or use it for semantic equality. |
| Metadata says offset 4; compiled code reads offset 8. | MUST | Reject it instead of silently recomputing a layout with a newer algorithm. |
Two unrelated Point types have identical bytes. | MUST NOT | Use them in place of nominal identity or a defined layout algorithm. |
Reordering x and y swaps what an old reader sees. | MUST NOT | Change field order, enum encoding, or alignment within an ABI revision unless the change is unobservable at every supported boundary. |
Layouts can be stored in metadata or derived from versioned rules. Internal types can be optimized when their representation does not escape through calls, fields, callbacks, generic bodies, or metadata.
Current representations
These are implementation observations, not stable layout guarantees.
| Category | Current representation |
|---|---|
| Class values | LLVM structures; field layout still needs a defined algorithm |
| Raw pointers and ordinary references | Pointers; validity and borrowing rules still apply |
| Named function values | Direct function pointers |
| Closures | Function pointer and environment pointer |
| Borrowed interface views | Object pointer and method-table pointer |
| Owned interface values | Owner pointer, object pointer, method-table pointer, and cleanup function |
| Static pointers | Data pointer and an i64 length |
Builtin slice | Two i64 bounds; an indexing range, not a data view |
| Unsized array references | Data pointer, i32 dimension count, and dimensions pointer |
| Payload enums | Tagged storage with size and alignment determined by variants |
Target profile requirements
Before stabilization, each target profile needs the following definitions.
| Minimal example | Level | Required definitions |
|---|---|---|
| A caller stores a Boolean that the callee reads. | MUST | Widths and alignment, Boolean storage and valid values, character representation, and floating-point formats. |
| A caller allocates storage for two consecutive rectangles. | MUST | Field order, tail padding, empty values, arrays and shapes, and vector alignment. |
| A consumer reads the tag before choosing a payload. | MUST | Discriminants and payload offsets. |
| An enum uses a reserved pointer value for its empty case. | MUST | Whether layouts may use spare bits or otherwise invalid values to encode variants. |