Data Layout

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; reject

Even 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 exampleLevelRequirement
area reads a Rectangle created by another bundle.MUSTDefine each type's layout for its ABI revision and target profile.
A private field before height changes its offset.MUSTPreserve the producer's layout, including private fields that determine a public value's size.
An array indexes its second rectangle using the element stride.MUSTSpecify size, alignment, field offsets, array stride, valid representations, and padding.
Two equal rectangles have different unused padding bytes.MUST NOTTreat padding as initialized application data or use it for semantic equality.
Metadata says offset 4; compiled code reads offset 8.MUSTReject it instead of silently recomputing a layout with a newer algorithm.
Two unrelated Point types have identical bytes.MUST NOTUse them in place of nominal identity or a defined layout algorithm.
Reordering x and y swaps what an old reader sees.MUST NOTChange 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.

CategoryCurrent representation
Class valuesLLVM structures; field layout still needs a defined algorithm
Raw pointers and ordinary referencesPointers; validity and borrowing rules still apply
Named function valuesDirect function pointers
ClosuresFunction pointer and environment pointer
Borrowed interface viewsObject pointer and method-table pointer
Owned interface valuesOwner pointer, object pointer, method-table pointer, and cleanup function
Static pointersData pointer and an i64 length
Builtin sliceTwo i64 bounds; an indexing range, not a data view
Unsized array referencesData pointer, i32 dimension count, and dimensions pointer
Payload enumsTagged storage with size and alignment determined by variants

Target profile requirements

Before stabilization, each target profile needs the following definitions.

Minimal exampleLevelRequired definitions
A caller stores a Boolean that the callee reads.MUSTWidths and alignment, Boolean storage and valid values, character representation, and floating-point formats.
A caller allocates storage for two consecutive rectangles.MUSTField order, tail padding, empty values, arrays and shapes, and vector alignment.
A consumer reads the tag before choosing a payload.MUSTDiscriminants and payload offsets.
An enum uses a reserved pointer value for its empty case.MUSTWhether layouts may use spare bits or otherwise invalid values to encode variants.