ReviewOS

zig-utils/zig-gc

GC: add failure-atomic relocation planning and commit hooks

#35
Open chris opened this 8 days ago ·
8 days ago

Downstream: zig-utils/zig-js#334\nDepends on downstream contract: zig-utils/zig-js#333\n\nAdd an opt-in, generic stop-the-world relocation mechanism without changing non-moving embedders.\n\n## Scope\n\n- Let a binding declare whether a marked cell kind is movable.\n- Reserve all same-size destinations before any old cell, root, edge, index, or publication metadata is mutated.\n- Roll back every unpublished destination on allocation failure with exact backing accounting.\n- Record old/new payloads, kind, size, and a stable logical ID for the complete plan.\n- Expose infallible strong/weak/atomic/interior resolver hooks to the binding for root and cell-edge rewriting.\n- Commit copied headers/payloads, indexes, owned-storage publication, and old-storage release in one world-stopped phase.\n- Preserve mark, age/generation, remembered-set, live-byte/cell, finalizer, and collection accounting.\n- Keep the default collector byte-for-byte non-moving when the binding omits relocation hooks.\n\n## Acceptance\n\n- [ ] Exact generic tests cover zero cells, mixed pinned/movable cells, all size classes, cycles, weak survivors/deaths, and stable identity.\n- [ ] Failure injection at every destination reservation proves the old graph, indexes, ownership, and accounting are unchanged.\n- [ ] Successful compaction releases evacuated storage without running live-cell finalizers.\n- [ ] Repeated normal, ReleaseSafe, and suppression-free TSan gates pass with zero leaks.\n- [ ] README/API documentation defines the binding contract and downstream zig-js consumes an exact commit.

8 days ago

Generic relocation core landed in e6ea569.

Implemented:

  • opt-in binding contract and public stable-ID/record/visitor types;
  • full collect followed by failure-atomic destination planning;
  • all scratch/index capacity plus every destination reserved before mutation;
  • exact rollback of every unpublished reservation on OOM;
  • complete live-graph rewriting, including pinned parents that point at moved children;
  • intrusive-list/index repair, optional owned-backing reserve/release/commit trio, and old-storage release without live-cell finalization;
  • unchanged default behavior for bindings without all graph hooks.

Focused coverage includes empty/all-pinned heaps, moved cycles, pinned edges, weak survivor/death, stable identities, exact accounting, and each destination-reservation failure boundary. Full local normal, ReleaseSafe, and suppression-free TSan suites pass. Keeping the issue open for GitHub Actions acceptance and downstream owned-backing consumption in zig-js#334.

Sign in to comment on this issue.