Skip to content

Fix Zig glue ownership helpers and capture collection#9685

Open
lukewilliamboswell wants to merge 4 commits into
mainfrom
glue-patches
Open

Fix Zig glue ownership helpers and capture collection#9685
lukewilliamboswell wants to merge 4 commits into
mainfrom
glue-patches

Conversation

@lukewilliamboswell

Copy link
Copy Markdown
Collaborator

Summary

  • Emit recursive Zig glue retain/release helpers for named records, tag unions, boxed payloads, and erased callables, with tests for generated helper symbols, opaque boxes, and natural entrypoint declarations.
  • Guard platform/app relation merging when both sides resolve to the same checked root.
  • Cache Monotype Lifted free sets per function/SCC and restore LLVM pipeline tuning to avoid unbounded compile-time growth on shared call graphs.

Testing

  • zig build run-test-cli -- --suite glue
  • zig build run-test-zig-lir-inline
  • zig build run-test-zig-module-layout
  • zig build run-test-zig-module-check
  • zig build minici

lukewilliamboswell and others added 4 commits June 17, 2026 16:48
Capture collection in Monotype lifting re-walked each callee body at
every call site with only a recursion guard and no solved capture table,
so a diamond-shaped call graph with shared callees re-derived the same
free sets along every distinct call path. Build time on such graphs grew
as 2^depth even though `roc check` completed normally.

A function's free-local (capture) set is independent of any caller, so it
is now computed once and cached in `free_sets`, and every call site
consumes the cached set instead of re-walking the callee. Mutually
recursive capturing functions are solved together as a strongly connected
component via Tarjan with a least-fixed-point pass, so each member reaches
its full transitive capture set rather than caching a partially explored
one. Capture collection now scales with the number of function bodies and
call edges instead of the number of call paths.
The LLVM inline-threshold experiment cranked PipelineTuningOptions.InlinerThreshold
to 1000000 for all --opt=speed builds, which defeats LLVM's inliner cost model and
inlines call graphs without bound. On a diamond call graph (each function calling
the one below it twice) this expands to 2^depth inlined code in a single function,
and the O3 passes (notably the SLP vectorizer) then spend exponential time on it.

Restore the pipeline tuning to match upstream Zig's zig_llvm.cpp: drop the inliner
threshold override, gate the remaining options on !is_debug, and keep loop
vectorization disabled per llvm/llvm-project#186922 (a miscompilation present in the
LLVM 21 we build against, fixed only on newer LLVM).
@lukewilliamboswell lukewilliamboswell marked this pull request as ready for review June 17, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants