ReviewOS

home-lang/home-os

Codemod: replace `!u32` / `!ptr` C-style truthiness with explicit `== 0` / `== null`

#20
Open glennmichael123 opened this 10 days ago ·
10 days ago

Context

Per the design decision on home #39, the Home compiler keeps strict typing for the logical-not operator: ! is only valid on bool and optional types. C-style truthiness (!some_u32 meaning "is zero", !some_ptr meaning "is null") is rejected at type-check time as error: Logical not requires boolean or optional operand.

The 2026-05-06 kernel audit found four kernel modules using the C-style pattern. They need a codemod to the explicit form.

Affected files

From the 2026-05-06 audit (first_error = Logical not requires boolean or optional operand):

  • kernel/src/arch/arm64/rpi/boot.home
  • kernel/src/arch/arm64/rpi/emmc.home
  • kernel/src/arch/arm64/rpi/gic400.home
  • kernel/src/arch/arm64/rpi/mailbox.home
BeforeAfter
!some_u32some_u32 == 0
!some_i32some_i32 == 0
!some_ptr (raw *T)some_ptr == null
!some_optionalleave as-is — !Optional is already valid

Walk each call-site manually; the integer-vs-pointer distinction matters for the chosen comparator.

Reference

  • Design call on home #39: option 2 (codemod kernel, not change compiler).
  • Compiler keeps the strict-typing posture in line with Home's "explicit init" / Zig-philosophy direction.

Sign in to comment on this issue.