ReviewOS

home-lang/home-os

Add explicit init to kernel module-scope `var` declarations

#13
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Context

148 of 170 typecheck failures in the 2026-05-01 kernel audit are `error: use of possibly uninitialized variable` from module-scope mutable globals like:

```home var pci_devices: [64]PCIDevice var process_table: [MAX_PROCS]Process var keyboard_state: [128]u8 ```

home-lang/home #14 evaluated whether to relax the typechecker (option a) or migrate the kernel to explicit init (option b). Option (b) wins — Home is following Zig's "no implicit init at module scope" philosophy, so the kernel sources need to be explicit about initialization rather than the typechecker getting a special BSS-aware rule.

home-lang/home #14 is closed as by-design. This issue tracks the kernel-side migration.

Scope

  • ~150 module-scope `var` declarations in `kernel/src/**/*.home` need explicit initializers added
  • Per-type strategy:
    • Arrays of POD or large structures (most kernel buffers, tables, bitmaps): `= undefined`. Matches kernel reality — BSS is zeroed by the bootloader, not by a runtime initializer. Writing `= [_]T{0} ** N` would suggest the compiler should emit a zeroing constructor, which is wasted work for kernel code.
    • Small scalar globals where zero is the meaningful value (counters, flags): `= 0` / `= false` / etc.
    • Globals with a non-zero initial value: use that literal (rare, but happens for sentinel values, version constants, etc.)

Approach

  • Find all module-scope `var <name>: <type>` (no init expression) under `kernel/src/`. Don't touch `let` declarations — those are required to have init already.
  • Apply per-type strategy above.
  • Validate on 5 sample files first with `perl -e 'alarm 5; exec @ARGV' .../home-debug check <file>` to confirm the `use of possibly uninitialized variable` error is gone for the touched declarations. Only then sweep the full set.
  • Commit incrementally (every ~20 files) so the work is recoverable if the agent stalls.

Don't do these things

  • Don't run bulk `home check` across all 404 modules — parser hangs per home-lang/home #16 will stall the run
  • Don't change the syntactic form of array types (they're `[N]T` already; do NOT touch the home-lang/home-os #10 closed-wrong-premise area)
  • Don't refactor anything else in the touched files

Why this matters

This single migration unblocks ~150 kernel modules from the typecheck-failure bucket of the audit. Combined with home-lang/home-os #11 (now landed, removed dangling-import noise), the parse-failure bucket may also shrink because parse errors that were hidden behind import errors will now surface.

Audit reference

`~/Desktop/home-os-kernel-audit-2026-05-01.tsv` on the maintainer's machine.

Sign in to comment on this issue.