ReviewOS

home-lang/home

Missing builtins (`@intToU64`, `@alignCast`, `@atomicFetchSub`, `@atomicFetchAdd`) + switch case pattern type coercion regression

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

Context

Two small follow-ups: 4 missing reflection builtins (~4 kernel files) + a typecheck regression introduced by home #20 (~2 files).

Sub-item A: 4 missing reflection builtins

Same shape as home #27. Needed by home-os kernel:

BuiltinPurposeSuggested signature
@intToU64Convert any integer to u64fn(value: anyInt) -> u64
@alignCastCast pointer to a more-aligned variantfn(comptime alignment: u64, ptr: *T) -> *align(alignment) T
@atomicFetchSubAtomic fetch-then-subtractfn(ptr: *T, val: T) -> T
@atomicFetchAddAtomic fetch-then-addfn(ptr: *T, val: T) -> T

Add to wherever home #27 added @addrOf/@atomicCmpXchg/@intFromEnum — same pattern.

Sub-item B: switch case pattern type coercion regression

home #20 introduced a regression: switch with => arms now requires the case patterns to exactly match the switch value's type. Previously, char/int literals coerced.

fn classify(c: u8): u32 {
  switch (c) {
    '(' => return 1,    // ERROR: "Case pattern type must match switch value type"
    ')' => return 2,
    else => return 0,
  }
}

'(' is a char literal; c is u8. The literal should coerce to u8. Similar issue for int literals (0 => against a u32 switch value).

Affected files: kernel/src/i18n/bidi.home, kernel/src/net/smb.home.

Approach

For sub-item B: in the switch typechecker, allow case patterns to coerce to the switch value's type using the same coercion rules as let/var/argument types (now improved by home #21/#26+27). A char literal is fundamentally a small int; it should fit u8.

Why this matters

6 kernel modules unblocked. Plus closing the regression keeps #20's scoreboard honest.

Reference

  • 2026-05-05 audit: `~/Desktop/home-os-kernel-audit-2026-05-05.tsv`
  • Predecessor for builtins: home #27 (closed)
  • Regression source: home #20 (closed)

Sign in to comment on this issue.