ReviewOS

home-lang/home

Teach `home check` about BSS zero-init for module-scope mutable globals

#14
Closed glennmichael123 opened this 24 days ago · 1 comment
24 days ago

Context

A 2026-05-01 audit of the home-os kernel (404 modules) found that 148 of 170 typecheck failures are the same diagnostic:

error: use of possibly uninitialized variable

triggered on reads of module-scope mutable globals like:

var pci_buses: [256]PciBus
var keyboard_state: [128]u8
var process_table: [MAX_PROCS]Process

These are kernel BSS-section globals — implicitly zero-initialized by the kernel image at boot. The current typechecker treats them as possibly uninitialized and rejects every read.

Impact

This single rule blocks ~150 kernel modules in home-os from typechecking. Includes load-bearing files: core/foundation.home, core/memory.home, core/process.home, core/filesystem.home, the entire core/vfs_* family, mm/mm_integration.home, sched/scheduler.home, sys/signal.home, net/socket.home, net/tcp.home, net/udp.home, boot/initramfs.home, most of arch/arm64/.

Proposal

Two reasonable directions:

  1. Teach the checker about BSS zero-init. Module-scope var x: T for any T whose layout permits zero-initialization (POD types, fixed-size arrays of POD, structs of POD) should be considered initialized at first read. Behind --kernel or always, depending on what fits the language model.
  2. Require an explicit zero-init expression. Force var x: [N]u64 = .{0} ** N (or similar) and migrate. Keeps the checker simple but adds source noise to every kernel global.

(1) is the lower-friction option for kernel work. (2) is closer to Zig's philosophy.

Audit data

  • TSV with the full per-module breakdown is at ~/Desktop/home-os-kernel-audit-2026-05-01.tsv on the maintainer's machine
  • Caveat: `home check` is non-transitive in the audit — module-local OK status doesn't include imports
  • Ran against `home-debug` built from `zig build debug` on macOS arm64

Why this matters

The home-os kernel cannot meaningfully be built end-to-end today; this is one of the two highest-leverage items in the audit (the other is `home build`'s lack of a freestanding target — separate issue).

24 days ago

Closing — going with option (b) instead of (a)

Decided to keep the typechecker's current strict behavior (every module-scope `var` must have an explicit initializer, including `= undefined` if the kernel relies on BSS zero-init). Following Zig's "no implicit init" philosophy.

Kernel-side migration tracked in home-lang/home-os: this is a codemod task, not a compiler change.

The typechecker is correct as-is; the home-os kernel sources are what need updating. Reopen if a different language-design path emerges later — the two approaches are additive, not mutually exclusive (could later add an "implicit BSS zero-init for module-scope arrays of POD" rule on top of the explicit form, but the explicit form is the foundation).

Sign in to comment on this issue.