#406

refactor(zero-c): consolidate duplicated dynamic-array grow helpers (#390)

OpenOsamaali313wants to merge intofrom

Summary

Fixes #390.

The same dynamic-array grow helper was duplicated across four files in native/zero-c/src:

  • ir_grow_items (ir.c), lower_grow_items (program_graph_lower.c), and checker_grow_items (checker.c) shared an identical body.
  • ir_grow_tracked_items (the variant that also accounts ir->mir_bytes) was defined verbatim in both ir.c and program_graph_mir.c.

As the issue notes, the duplicated mir_bytes accounting can silently diverge if one copy is edited without the others.

Change

Hoist both helpers into include/zero.h as shared static inline functions (z_grow_items and ir_grow_tracked_items), placed right after the IrProgram definition so the tracked variant can reference ir->mir_bytes. The five local definitions are removed and their call sites repointed at the shared helpers.

Pure refactor — the helper bodies are byte-for-byte the originals, so there is no behavior change. Net +61 / -81 lines across 5 files.

Validation

  • make -C native/zero-c builds clean under -Wall -Wextra -Wpedantic.
  • Host-target end-to-end works: zero build --emit exe --target linux-x64 on conformance/run/pass/hello.graph produces an exe that runs and prints the expected output.
  • All conformance/check/pass/*.graph fixtures pass zero check (this is the path that exercises the modified checker.c and ir.c lowering).

Transparency per AGENTS.md: I developed this on Linux (Ubuntu via WSL) where the linux-x64 host target is fully runnable, but pnpm run agent:checks could not complete because the linux-musl-x64 build steps require a musl-capable C compiler that isn't installed in my environment. That step fails identically on a clean checkout (BLD003: cross target 'linux-musl-x64' requires a target-capable C compiler ... install the bundled-toolchain default), so it is pre-existing and unrelated to this change. CI (with the musl toolchain) should exercise the full matrix.

Activity

3
vercel[bot]5mo ago

@Osamaali313 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

copilot-pull-request-reviewer[bot]reviewed5mo ago
copilot-pull-request-reviewer[bot]5mo ago

Pull request overview

NOTE

Copilot was unable to run its full agentic suite in this review.

Refactors dynamic array growth helpers by centralizing them into shared inline functions, reducing duplicated logic across several C source files.

Changes:

  • Removed per-file *_grow_items helpers in ir.c, program_graph_lower.c, checker.c, and program_graph_mir.c.
  • Introduced shared z_grow_items (and ir_grow_tracked_items) helpers in include/zero.h.
  • Updated call sites to use z_grow_items.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
native/zero-c/src/program_graph_mir.cRemoves local tracked grow helper in favor of shared header implementation.
native/zero-c/src/program_graph_lower.cReplaces local grow helper usage with z_grow_items.
native/zero-c/src/ir.cRemoves local grow helpers and switches call sites to z_grow_items.
native/zero-c/src/checker.cRemoves local grow helper and switches call sites to z_grow_items.
native/zero-c/include/zero.hAdds shared inline grow helpers (z_grow_items, ir_grow_tracked_items).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.