Files
aji/docs/spec/02-types-and-values.md
T
dev 41b764ccfd spec: Phase 0 spec gate (P0-1, P0-2, P0-3)
- text AIR format 0: grammar (reference/air-text.ebnf) and module,
  block, SSA, type and canonical-form rules (spec 07 §8)
- instruction contracts for format 0 (new spec 07a)
- traps: stable T0xxx codes and trap records (spec 01 §6)
- integer edge cases and explicit casts (spec 02 §2.1)
- fixed verifier resource limits (spec 08 §7)
- target description with pointer_bits (spec 09 §9)
- new codes E0001-E0006, E1003, T0001-T0007
- resolves Q-001, Q-003..Q-008, Q-018; Q-002 resolved for format 0
2026-10-04 12:14:25 +03:00

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

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.

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