Kern
On this page

M0 S3: inspection profile and ABI classification

This is the authorized coherent subset of S3: storage layout, frontend checking, argument classification and fixtures. It does not implement executable 32-bit code generation. Both the Rust stage0 and the self-hosted compiler expose:

build/kern layout tests/layout/abi32.kn --target thumbv7m-none
build/kern layout compiler --target linux-arm64
build/kern check path/to/main.kn --target thumbv7m-none
python3 tests/layout/check.py build/kern-stage0 build/kern

layout accepts a file or project without requiring main. It performs semantic, contract and ownership checking; it does not enforce source style rules, load test input snapshots, generate assembly or create executables. check retains its entry-point and source-policy checks but no longer generates assembly. All seven embedded emitting/runner/API/format commands are rejected before loading source; the backend entry points also reject an embedded storage profile. No embedded command is admitted to the test cache. API and formatting can still be used with hosted target selection.

The internal profile separates the source argument-word limit (6) from argument register capacity (hosted 6; AA32 4). Target selection precedes primitive type creation and layout. usize/isize literals use target bounds; unannotated integer literals and negative literal ranges use i32 on AA32 and preserve hosted i64. Explicit checked casts from wider literals remain legal; their runtime narrowing traps await machine lowering. The six-word signature limit is enforced in both frontends, including instantiated generic functions, without calling an emitter.

Storage table

tests/layout/abi32.tsv is the independent 22-row fixture. Every stored type is word-aligned (4 bytes on AA32); void has zero size/alignment. Byte/bool elements have stride 1 even though their locals and fields occupy a full word.

TypeAA32 words / bytesHosted words / bytes
void0 / 00 / 0
i64, u642 / 81 / 8
i32, u32, usize, isize, u8, bool, internal pointer1 / 41 / 8
slice, including nested slices2 / 82 / 16
Arena3 / 123 / 24
Handle[i32]2 / 82 / 16
Pair {u32,u32}2 / 82 / 16
Mixed {u8,bool,u32,[]u64}5 / 205 / 40
Scalars {i64,u64,i32,u32,usize,isize,u8,bool}10 / 408 / 64
Choice {i32 or []u8}3 / 123 / 24
Wide {u32,u64,u8}4 / 163 / 24
WideChoice {empty or (i64,[]u8)}5 / 204 / 32

Struct sizes sum field words. Enum sizes are one tag word plus the largest payload. Wide.big starts at byte 4 and Wide.tail at byte 12; a wide enum payload starts at byte 4. Wide values are low-word first. The value rows specify signed canonical extension for i32/isize and zero extension for unsigned words; they are an inspection contract, not evidence of executing 32-bit extension code.

The original tests/layout/hosted.tsv is unchanged and all 60 rows are checked through the new CLI. Reports include every concrete type, field/payload byte offsets, concrete generic instances, fully qualified module paths, each argument word's location, local slot offsets, result/error locations, and frame storage. Uninstantiated generic templates, type parameters and interfaces have no concrete storage report.

Kern AAPCS word classification

The classifier implements M0-DESIGN D7/D8: r0-r3 in order, then caller stack words at stack+0, stack+4, and so on. An aggregate success or error reserves r0 as the shared hidden result pointer. Aggregate/reference parameters carry a single pointer word; owned slices still carry pointer and length. Success and error are alternative values using r0:r1, with the fallible flag in r2.

All stored types, including i64, align to four bytes under D7. Consequently there is no even-register skip for wide values: a pair may straddle r3 and stack+0. This is the specified Kern word ABI; C AAPCS interoperability and its natural 8-byte-aligned arguments have not been implemented or qualified.

Signature examplePlacement
(u32,u32,u32,u64) -> u64scalars r0,r1,r2; wide r3:stack+0; result r0:r1
(u32,u32,u32,[]u8) -> []u8slice r3:stack+0; result r0:r1
(u64,u64,u64) -> i64r0:r1, r2:r3, stack+0:stack+4; result r0:r1
(u32,[]u8,u64) -> Widesret r0; u32 r1; slice r2:r3; wide stack+0:stack+4
([]u8,u64) -> []u8 ! u64arguments r0:r1 and r2:r3; either result r0:r1; error flag r2
(u32,[]u8,u64) -> u64 ! Widesret r0 even for aggregate error only; success r0:r1; error in sret; flag r2
(&mut u64,Wide,own []u8)reference r0; aggregate pointer r1; owned slice r2:r3

incoming_stack_bytes is the raw incoming argument area, without final caller padding. storage_frame_bytes is the sum of all local slots, including parameter slots, rounded to the profile's frame alignment (8 on AA32, 16 hosted). It excludes hidden sret saves, outgoing call arguments, expression temporaries, register spills, callee saves and prologue records. It is deliberately not the final machine frame size. For example the five-word split signature reports 24 bytes of AA32 local storage, and three one-word locals report 16. Actual machine frame accounting is one of the remaining emitter tasks.

Validation

All requested acceptance commands passed on the final compiler source. Logs are in build/m0-s3-evidence/ (generated, not committed).

CheckResult
stage0 build; stage0 builds the self-hosted compilerPASS
Rust unit tests61 passed, 1 pre-existing ignored
self-hosted check and canonical format checkPASS
layout fixtures, literals, generics/projects, emitter guardsPASS in stage0, stage1 and official fixed-point compiler; complete report parity on all four profiles
original hosted layout tableall 60 rows unchanged
host language harness331/331
feature suitesall ten passed: runner29, audit25, structure13, ownership19, generics19, contracts17, writers18, runtime13, system18, safe OS6
differential optimizer corpus20/20
frozen hosted assembly36/36 raw hashes unchanged (18 per compiler)
full self-host proof86 source tests, byte-identical stage2/3/4, external tools blocked; harness331/331, all feature suites and policy144/144

The frozen manifests themselves are unchanged:

bd02efe8e95ece2e5c043065d95c60fc43c1746034b626ec9bff04f8325d7359  tests/golden/hosted.sha256
52559ad1af896e99fe0cda96954a1c0f8a61ca875c3932c1f4a76a6619756a06  tests/golden/stage0.sha256

The final fixed-point executable SHA-256 is 25ded6b726e1a6f81aeee229fe569bcb1a135d101a0f385459a7e77001597278. build/kern-selfhost (stage3) and compiler/build/compiler (stage4) were compared again after the proof and are identical; the proof also compared stage2. These are hosted compiler artifacts, not 32-bit target executables.

Exact remaining work

  1. Machine ABI lowering in both backends: stack argument allocation/padding and loads, caller/callee register placement, sret reservation/save, return/error transfers, r4-r11 preservation, and complete final frame accounting. The new classifier reports these obligations; it does not emit the transfers.
  2. Canonical 32-bit loads/stores, word arithmetic/overflow, checked word casts and 32-bit shift limits; low/high i64/u64 copies through locals, fields, slices, arguments and success/error returns; two-word arithmetic/comparisons and multiply/divide/modulo helpers. Existing shift/alloc_mem/esz/words/frame seams use the profile; remaining machine instructions and runtime assembly are hosted only. In particular stage0 ld_el, st_el and ld_inc still encode hosted eight-byte memory accesses, and Arena runtime alignment masks remain hosted. The stage0 for-in copy path now counts words with word_bytes and avoids its single-word fast path for a multiword integer.
  3. Audit all success/error result-area sizing (allocate max(success,error)) and shared hidden-pointer handling before admitting either 32-bit emitter. Frozen hosted assembly proves no hosted output change, not correctness of a future two-word return implementation.
  4. Thumb-2/RV32 textual emitters and clang link integration (M1), then native encoders and ELF32 headers/relocations/writers (M5). ELF64, Mach-O, A64 and x64 writers are unchanged. This subset selects only thumbv7m-none for inspection; thumbv7em-none and riscv32imac-none dispatch remain future work.
  5. Reset/vector table, stack initialization, data copy/BSS clearing, linker script, board trap hook and freestanding runtime. Validate actual ABI transfers and traps on QEMU/hardware; no 32-bit program has been executed here.
  6. Capability diagnostics, wide policy and target profile files remain S4. MMIO and board capabilities are outside this change. Before embedded test execution, add target identity to test-cache keys and keep hosted test images isolated.

No push, PR, release, deploy or MCU manufacturing/board qualification is part of this local commit.

Source: M0-S3-RESULTS.md in the repository.