feat: Epoch nursery allocator with @compact primitive#43
Open
gavlooth wants to merge 1 commit intoHigherOrderCO:mainfrom
Open
feat: Epoch nursery allocator with @compact primitive#43gavlooth wants to merge 1 commit intoHigherOrderCO:mainfrom
gavlooth wants to merge 1 commit intoHigherOrderCO:mainfrom
Conversation
Epoch-based memory reclamation for iterative HVM4 programs. Leverages IC's cycle-freedom guarantee: after normalization to SNF, all nursery data except the result tree is dead, making O(1) bulk reclaim provably safe without tracing. New files: - heap/epoch.c: Epoch nursery infrastructure (stable/nursery split, begin/reset lifecycle, nesting support, benchmarks) - heap/free.c: Stub for heap_free_reset() backward compatibility - prim/fn/compact.c: @compact(term) primitive — normalize, deep-copy to stable region, reset nursery - docs/EPOCH_ALLOCATOR.md: Architecture documentation Safety hardening (9 fixes from production audit): 1. CRITICAL: Nested @compact nesting support via EPOCH_DEPTH counter 2. HIGH: Null sentinel guard (loc==0) in compact_deep_copy DP/VAR loop 3. HIGH: COMPACT_MAX_DEPTH (64K) recursion limit with graceful fallback 4. MEDIUM: epoch_init validates stable_fraction >= 2 5. MEDIUM: epoch_reset_zero warns about spin-wait amplification 6. MEDIUM: F_EQL_R ext-field stale pointer documented 7. MEDIUM: epoch_bench calls thread_set_count(1) before running 8. LOW: epoch_reset_stable() helper replaces direct STABLE_NEXT access 9. LOW: Removed dead EPOCH_NUM variable CLI: --epoch, --epoch=N, --epoch-bench Test results: 190 ST PASS, 187 MT PASS, zero regressions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@compact(term)normalizes to SNF, deep-copies live result to stable region, resets nursery. Enables iterative algorithms (Bellman-Ford, etc.) that would otherwise exhaust the heap.@compactsupport viaEPOCH_DEPTHcounter — inner compacts don't corrupt outer epochloc==0) incompact_deep_copy— prevents infinite spin-wait on HEAP[0]COMPACT_MAX_DEPTH(64K) recursion limit — prevents stack overflow on deep SNF treesepoch_initvalidatesstable_fraction >= 2epoch_reset_zerowarns about spin-wait amplificationF_EQL_Rext-field stale pointer documentedepoch_benchcallsthread_set_count(1)before runningepoch_reset_stable()helper replaces directSTABLE_NEXTmanipulationEPOCH_NUMvariableNew files
clang/heap/epoch.cclang/heap/free.cheap_free_reset()backward compatibilityclang/prim/fn/compact.c@compactprimitive with epoch-aware deep copyclang/docs/EPOCH_ALLOCATOR.mdCLI
Test results
--epochBenchmark (--epoch-bench)
🤖 Generated with Claude Code