Files
aji/docs/spec/02-types-and-values.md
T
dev ca84ab4348 rfc: 0014 accepted (revision 2) and integrated into the spec
Owner review: D1-D4, D7-D9 accepted; D5 frozen.release, no thaw; D6
arc.from_frozen (island -> frozen -> arc, one graph identity), ArcSafe
(not Share alone; no arc<mutex>, no nested arc); D7 island Send, not
Share; D10 islands -> heap, arc -> islands; added: never-reused graph
identity, IslandSafe, the quota lifecycle, iref equality.

Integrated: spec 02 §6 (IslandSafe, ArcSafe), 03 §12-§14 and new
§22-§24 (instruction contracts, quota), 04 §13/§35/§38.1, 07a (features
islands, arc), 15 §8 (layer 9 syntax, explicit container borrows),
error codes (T0010, registered in src/diag.zig), type-properties. Phase 4
plan: P4-0, P4-1 done.
2026-10-05 21:57:08 +03:00

3.8 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.

2.1 Edge cases

  • Division and remainder truncate toward zero; the remainder has the sign of the dividend.
  • Division or remainder by zero traps (T0004). Signed MIN / -1 and MIN % -1 trap as overflow (T0003).
  • shl and shr take a shift amount of the same type as the shifted value. An amount that is negative or not less than the bit width traps (T0005). shl discards bits shifted out; shr is arithmetic for signed types and logical for unsigned types.
  • There are no implicit conversions. Explicit integer casts:
    • widen: only between types where every source value is representable in the target (unsigned to wider unsigned or wider signed, signed to wider signed); anything else is rejected statically (E1002). usize and isize are never valid widen operands or targets, so verification stays independent of the target; use checked.
    • checked: converts the numeric value; traps (T0006) if it is not representable in the target type.
    • wrap: takes the two's-complement bit pattern modulo 2^N of the target width.

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;
  • IslandSafe: may be stored in an island graph (spec 03 §22). Derived structurally: integers, bool, built-in enums and iref<U> are IslandSafe, and so are arrays, structs and enums of IslandSafe values. Borrows, owners, regions, graph owners (island, frozen, arc), resources, endpoints, task, scope, shield, guard, mutex and cap<K> are not;
  • ArcSafe: may be held by an arc (spec 03 §24). The last release destroys it by freeing memory only. In format 0 it is exactly IslandSafe.

These are semantic properties, not user-extensible traits in v0.1. Their derivation for the types of AIR format 0 is the table of spec 04 §35.

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(...)