M0 S0-S2 hosted integer model
Branch: m0-s0-types. Baseline: 42427ba. Local commit only; no push or release.
Delivered
Both compilers accept nominal usize, isize, i32, and u32 in declarations,
literals, conversions, arithmetic, comparisons, matches, generic instantiations,
API output, and canonical formatting. Type spellings remain ordinary lexer
identifiers, so no new keyword tokens are needed. usize has the hosted u64
representation but is a distinct type.
len, arg_count, indexes, subslice bounds, allocation counts, arena capacities,
and truncate lengths use usize. The compiler's table indexes, offsets and hosted
word accumulators and the affected examples/tests were migrated. Fixed OS builtin
signatures remain intact, with explicit conversions at compiler boundaries.
Hosted profiles carry word_bytes=8, stack_align=16, and arg_words=6. They feed
address shifting, allocation, element stride, scalar/composite words and frame
rounding. Struct offsets remain word indexes. The self-hosted driver selects the
profile before parsing/checking; backend frame/offset arithmetic uses that profile.
Arithmetic on the new fixed-width types uses canonical hosted 64-bit intermediates
and checked 32-bit result bounds. This keeps one 8-byte slot per scalar and avoids
truncation: i32 is sign-extended, u32 zero-extended. Casts reject values outside
the destination range. Arithmetic overflow (including i32::MIN / -1, remainder
and negation), division by zero, and width-specific shift counts have runtime
fixtures. Bit operations retain matching unsigned operand types and mask discarded
bits to that width. New casts are admitted in read-only contract predicates.
Count ranges default to usize. Explicit integer bounds retain their nominal type,
including signed ranges; comparison signedness follows the operand type. This
preserves existing negative ranges in core.kn and enums.kn and their frozen
assembly. Requiring every range to be unsigned would contradict the brief's
unchanged-semantics and byte-identical-output requirements.
Hosted layout table
Each target column is words / storage bytes. All stored types align to 8 bytes.
void has no storage. u8 and bool slice elements have stride 1; their locals and
fields still occupy a whole slot. Other slice element strides equal storage bytes.
| Type | macos-arm64 | linux-arm64 | linux-x64 |
|---|---|---|---|
void | 0 / 0 | 0 / 0 | 0 / 0 |
i64 | 1 / 8 | 1 / 8 | 1 / 8 |
u64 | 1 / 8 | 1 / 8 | 1 / 8 |
i32 | 1 / 8 | 1 / 8 | 1 / 8 |
u32 | 1 / 8 | 1 / 8 | 1 / 8 |
usize | 1 / 8 | 1 / 8 | 1 / 8 |
isize | 1 / 8 | 1 / 8 | 1 / 8 |
u8 | 1 / 8 | 1 / 8 | 1 / 8 |
bool | 1 / 8 | 1 / 8 | 1 / 8 |
| internal pointer | 1 / 8 | 1 / 8 | 1 / 8 |
| any slice, including nested slices | 2 / 16 | 2 / 16 | 2 / 16 |
Arena | 3 / 24 | 3 / 24 | 3 / 24 |
Handle[T] | 2 / 16 | 2 / 16 | 2 / 16 |
| struct | sum of field words / 8 × words | same | same |
| enum | (1 + largest payload words) / 8 × words | same | same |
The 60-row executable fixture table is tests/layout/hosted.tsv. It additionally
pins Pair {u32,u32} to 2 words/16 bytes, Mixed {u8,bool,u32,[]u64} to 5/40,
eight scalar fields to 8/64, and an enum with a slice payload to 3/24. The Rust
unit test parses tests/layout/hosted.kn and checks the actual generation helpers.
Self-hosted frontend/profile tests check its independent records and prevent fake
reserved-kind entries from being interned as one-slot Arena/Handle types.
Golden proof
Before implementation, both compilers were built from 42427ba. Six original
sources were frozen on all three hosted targets: core, enums, sieve, slices,
wc, and the calc project. The two sources without main use asm-test; the
other four use asm. tests/golden/fixtures.tsv records that choice.
All 36/36 raw assembly hashes match, without normalization or regenerated expected values. Each compiler has 18 independently frozen hashes:
| Manifest | SHA-256 of the manifest |
|---|---|
tests/golden/hosted.sha256 | bd02efe8e95ece2e5c043065d95c60fc43c1746034b626ec9bff04f8325d7359 |
tests/golden/stage0.sha256 | 52559ad1af896e99fe0cda96954a1c0f8a61ca875c3932c1f4a76a6619756a06 |
Run sh tests/golden.sh build/kern hosted and
sh tests/golden.sh build/kern-stage0 stage0. The existing CIP stage0 and feature
jobs now enforce these checks. SPEC.md and self-hosted kern spec are identical;
.cip/gen-spec.py regenerates the printer reproducibly.
Validation
| Check | Result |
|---|---|
| stage0 build | PASS |
| Rust unit tests, including layout table | 60 passed, 1 pre-existing ignored |
| stage0 builds self-hosted compiler | PASS |
self-hosted check compiler and fmt compiler --check | PASS |
| host language harness | 331/331 |
| feature suites | all 10 passed: runner 29, audit 25, structure 13, ownership 19, generics 19, contracts 17, writers 18, runtime 13, system 18, safe OS 6 |
| full self-host proof on final source | PASS: 85 source tests, byte-identical stage2/3/4, blocked external tools, harness 331/331, all feature suites, policy 144/144 |
| differential optimizer corpus | 20/20 |
| frozen hosted assembly | 36/36 |
| extra Linux arm64/x64 width and trap executions | 96/96, both compilers; four runtime tests and 23 exact trap fixtures per compiler/architecture |
The verified fixed-point executable SHA-256 is
d9f6350797ba50582d27e637b9fa5eb7a394be2574dcbbef7c828c79a787a177.
The preserved build/kern-selfhost (stage3) and compiler/build/compiler (stage4)
are byte-identical; the proof script also compared stage2. Full local logs are in
build/m0-s0-evidence/ (generated, excluded from git).
The full bootstrap proof verifies stage2 = stage3 = stage4 byte-for-byte, external compiler/assembler/linker tools blocked, all 85 compiler source tests, the language harness, all feature suites, and the 144-case self-host policy suite. Host-only acceptance does not claim a full Linux regression run; the extra Linux run is limited to the new fixed-width runtime and trap fixtures.
Files changed
M0-S0-CHANGES.txt is the complete file inventory. The substantive changes are:
- Rust:
ast.rs,parse.rs,check.rs,contracts.rs,gen.rs,gen/expr.rs,gen/stmt.rs,main.rs,profile.rs,test_hash.rs; embedded source-test migrations ingeneric.rs,ownership.rs, andcontracts.rs. - Kern: model kind/type records, parser, typing, builtin IDs, integer helpers, profile module, backend arithmetic/casts/layout, contract effect admission, API output and spec printer; mechanical count/index annotations throughout the hosted compiler.
- Fixtures: nine nominal/literal error cases, 23 traps, four runtime tests, an API project, the hosted layout table, and the frozen golden table/manifests/checker.
- Existing examples, optimizer/ownership/index fixtures and hosted feature-script
source snippets needed by the nominal
usizemigration. SPEC.md, the spec-printer generator, and golden checks in existing CI jobs; job selection includes the new fixture dependencies.
The pre-existing untracked M0-S0-BRIEF.md is excluded from the commit.
CONCURRENCY.md and all MCU runtime scripts are untouched. No new target,
4-byte storage, capabilities, kern.target, or 32-bit ABI was introduced.
Exact work remaining for S3 and the 32-bit ABI
The design calls S3 the layout/profile step; the machine ABI implementation is S5/S6. This lane leaves those boundaries explicit:
- Add non-host profile selection, thread it through all frontends (including
test/API/check paths), and make integer literal widths/default integer type
profile-dependent. Current
usize/isizewidth and defaulti64remain hosted 64-bit; the profile constructors expose only the existing three targets. - Implement 4-byte slots and
words(i64/u64)=2; recompute struct/enum offsets, slice(ptr32,len32), Arena/Handle storage, element strides and alignments. Currentscalar_wordsand primitive records deliberately remain one hosted word. Audit address/load/store scaling and Arena alignment masks for 4-byte words; hosted machine prologues and runtime assembly still encode the 64-bit ABI. - Split both drivers so
checkand a newkern layoutcommand do not call code generation. Add the per-type slots/bytes/alignment CLI and non-host layout/literal fixtures before depending on a 32-bit emitter. Move the six-word argument check out of codegen into the checker using profile data. - Implement AAPCS argument placement in r0-r3 plus stack, still bounded to six
source argument words. Reserve r0 for aggregate
sret; use r0:r1 for results, r2 for the fallible flag, preserve r4-r11, and align frames to 8 bytes. Define stack argument/result storage and the caller/callee paths in both backends. - Implement canonical 32-bit loads/stores and arithmetic, checked word conversions
and 32-bit shift limits. Implement
i64/u64as low-word-first pairs in locals, fields, slices, arguments, returns and errors; provide two-word arithmetic, comparisons and division/multiplication helpers. No such two-word path exists here. - Add Thumb/RV32 emission and target dispatch, freestanding reset/vector/data/BSS startup, linker scripts, the board trap hook, and either the planned clang link path or later ELF32/native encoders. Validate call-convention fixtures, ELF class and machine, and arithmetic/traps under QEMU; assembly hashes on hosts cannot establish those properties.
- Keep capability/profile-file work separate (S4), including
widepolicy and E170-E175. Add target identity to test-cache versioning before admitting any non-host test run. Nothing in this commit grants or diagnoses MCU capabilities.