ReviewOS

home-lang/home

Typechecker cleanups omnibus — pointer arithmetic, string→[u8;N] coercion, deref-index, let-binding tracing, scoping

#22
Closed glennmichael123 opened this 24 days ago · 0 comments
24 days ago

Context

The 2026-05-04-pm home-os audit triage surfaced 6 distinct small typechecker bugs. None individually justifies a separate issue, but bundled they unblock ~10 kernel files. All home-compiler-side fixes.

Sub-items

1. Pointer + integer arithmetic (5 files unblocked)

```home let ptr: *u8 = data + i // currently fails: "Addition requires numeric or string types" ```

Decision: allow. Standard C/Zig idiom; kernel assumes it works in 5 places (boot/initramfs.home, core/driver_init.home, mm/zram.home, perf/boot_opt.home, perf/targets.home). Permit `*T + integer → *T` in the typechecker.

2. String literal → `[u8; N]` coercion (3 files unblocked)

```home var oem_ntfs: [u8; 4] = "NTFS" // currently fails: expected [u8;4], found string ```

Decision: keep `[u8; N]` syntax; add coercion. The audit confirmed kernel uses `[u8; N]` and `[N]u8` ~50/50 (817 vs 815 occurrences); deprecating either means an ~800-site codemod. Add coercion: a string literal of length ≤ N coerces to `[u8; N]` with zero-pad.

3. `(*dest)[i]` deref-then-index (2 files: opcua.home, zigbee.home)

```home fn copy_string(dest: *[u8; 64], ...) { (*dest)[i] = ch // currently fails: typechecker can't resolve through deref-index combo } ```

Pattern is shared between two files. Fix the checker to recognize `(*ptr)[i]` where `ptr` is a pointer to a fixed-size array.

4. `let X = &arr.field[i]` type tracing (1 file: drivers/storage/nvme.home)

```home let ns = &ctrl.namespaces[ns_idx] // ns inferred type loses field info *block_size = ns.block_size // fails: "Undefined variable" on ns.block_size ```

The typechecker drops field information when binding through & + array index. Trace the type through.

5. `var X: usize = N` at module scope (1 file: serial.home)

Other module-level `let X: u8/u16/u32 = N` lines in the same file pass; `usize` specifically is rejected. Add `usize` to the numeric-coercion list (or unify it with int-coercion).

6. Forward-declared local in same block (1 file: core/vfs_large_files.home line 67/68)

```home let blocks_per_double = ... // line 67 *triple_ind = block_num / blocks_per_double // line 68 fails: "Undefined variable" ```

Local-scope tracking bug; `blocks_per_double` is in scope by line 68.

Why this matters

10 home-os kernel modules unblocked once these land. Each sub-item is a small surgical change to the typechecker; bundle them in one PR for ergonomic review.

Reference

  • 2026-05-04-pm audit: `~/Desktop/home-os-kernel-audit-2026-05-04-pm.tsv`
  • Triage report (scout agent): file references and line numbers per sub-item

Sign in to comment on this issue.