ReviewOS

home-lang/home

fix(types): infer reflection cast and pointer builtin result types

#825
Closed glennmichael123 opened this 8 days ago ·
8 days ago

Problem

The authoritative Home checker visits reflection builtin operands but returns void for every ReflectExpr. Valid systems expressions such as @as(u64, width), @intFromPtr(ptr), context-typed @intCast(value), and @as(*u8, @ptrFromInt(addr)).* consequently produce false arithmetic, assignment, and call-argument errors.

Evidence

TypeChecker.inferExpression currently handles .ReflectExpr by traversing its arguments and unconditionally break :blk Type.Void. The parser already preserves each builtin kind and optional target type, and kernel codegen already lowers these casts. On current home-os origin/main, the first post-never failures at kernel/src/main.home:201, :257, :266, and :318 all flow from the lost result type.

Scope

  • Infer explicit cast target types from ReflectExpr.target_type.
  • Use contextual result types for target-elided casts such as @intCast(value).
  • Give fixed-result pointer/integer and metadata builtins their semantic types.
  • Preserve operand traversal, unsafe raw-pointer checks, and uninitialized-storage tracking.
  • Add focused checker coverage for the kernel cast chain.

Acceptance criteria

  • Explicit @as/@intCast results retain the declared target type.
  • @intFromPtr is integer-typed.
  • Contextual @ptrFromInt can flow into an explicit pointer cast and dereference inside unsafe.
  • The focused checker suite remains green and the kernel corpus loses the related false diagnostics.

Blocks the remaining kernel-corpus acceptance item in #787. Part of #814.

8 days ago

Implemented and pushed directly to main in a5e7f84 (fix(types): infer reflection builtin results (#825)).\n\nVerification:\n- focused control-flow checker suite: 68/68 passed\n- AST-owned reflection target types are now released; the suite reports no allocator leaks\n- no-JSC debug compiler build passed under the 3,840 MB guard (2,887 MB peak)\n- current archived home-os origin/main kernel corpus: semantic failures fell from 82 to 31\n- commit contains exactly four files and was authored/committed by glennmichael123 gtorregosa@gmail.com with no coauthors

Sign in to comment on this issue.