Files
aji/docs/spec/02-types-and-values.md
T
dev 2bbbd2135c rfc: 0015 scalar atomics and the Aji memory model accepted (revision 2) and integrated into the spec
The Aji RC11 profile (RC11 with NO-THIN-AIR; stronger than ISO C11/C++20) as
normative axioms in spec 04 §20; DRF-SC; linear atomic<T> for AtomicScalar
with atomic.new/atomic.take; ref<atomic<T>> operands; ordering tables incl.
cmpxchg failure table and two results; effects [atomic] / [atomic, atomic.weak];
target atomic_widths and E4203; E4202; enumerator as oracle (observed ⊆ allowed,
exact equality on the normative litmus corpus). Feature atomics stays reserved
until P5-2a. Q-015 resolved; record/replay and Q-017 moved to Phase 8.
RFC 0003 superseded. AIR bundle +1.9 %.
2026-10-06 00:30:35 +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, atomic<T> 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(...)