Files
aji/docs/spec/02-types-and-values.md
T
dev 17a55a7fef Initial import: Aji 0.1 draft spec and Zig scaffolding
Draft specification, RFCs, reference registries and examples, plus the
reference-implementation skeleton: build.zig, diagnostic envelope with
error-code registry synced to docs, aji CLI, conformance runner with seed
tests, CI and contributor docs.
2026-10-04 11:59:13 +03:00

2.2 KiB

02. Types and Values

1. Primitive types

Unsigned integers:

u8 u16 u32 u64 u128 usize

Signed integers:

i8 i16 i32 i64 i128 isize

Floating point:

f32 f64

Other primitives:

bool byte void never

byte is an alias of u8.

usize and isize match the target pointer width.

2. Integer semantics

Normal arithmetic is checked.

let c = a + b;

Overflow traps unless the compiler proves it impossible.

Explicit alternatives:

wrap_add(a, b)
saturating_add(a, b)
checked_add(a, b) // Option<T>

Release/debug modes MUST NOT change these semantics.

3. Composite types

[u8; 4096]
slice<u8>
slice_mut<u8>
(u32, u64)
Option<T>
Result<T, E>

Structures:

struct Header {
    len: u32,
    crc: u32,
    sequence: u64,
}

Enums:

enum State {
    Ready,
    Running,
    Failed(Error),
}

4. Nullability

Safe references cannot be null.

Nullable references use:

Option<ref<T>>
Option<mut<T>>

Raw nullable addresses are unsafe-only.

5. Value ownership categories

A value is one of:

  • copyable value;
  • move-only value;
  • linear resource;
  • borrow.

Linear resources must be consumed exactly once.

6. Structural properties

The compiler derives:

  • Copy: may be duplicated without changing semantics;
  • Send: may be moved to another concurrent execution context;
  • Share: may be observed concurrently through immutable access;
  • Freeze: can be converted to deeply immutable state;
  • Local: tied to its current execution context.

These are semantic properties, not user-extensible traits in v0.1.

Manual unsafe declarations MAY exist only for FFI/runtime wrappers and MUST state proof obligations.

7. Layout

Default struct layout is implementation-defined and must not be used for external ABI assumptions.

ABI-sensitive declarations use explicit representation attributes such as:

@repr(C)
struct PacketHeader { ... }

@repr(packed) and @align(N) MAY be supported.

Packed fields do not yield normal aligned references unless alignment is established.

8. Endianness

Serialization must be explicit:

u32.from_le(...)
u32.from_be(...)
u32.to_le(...)
u32.to_be(...)