Repository navigation
feat!: give fast safe code a heap of per-thread pool entries - #82
Merged
Merged
Conversation
RFC 0055, accepted as drafted. A fast safe unit's heap is one design for C and C++: - Each thread keeps an entry of free slots for each pool it uses. A typed allocation (__weavec_rt_take) is a pop and one stored word; a typed release (__weavec_rt_give) compares the slot's word, stores the released one, zeroes the object and pushes. No compare-and-swap, no records, no counters. Refills and flushes move half an entry, and a pool that grows takes fresh slots by the half entry. - A realloc keeps its block's type (__weavec_rt_realloc_typed). - The reference test (O4) belongs to the checked build in Safe C as in Safe C++, so a program with Safe C keeps its pooled slots' shadow. - Pools are keyed by layout as well as name. The in-line forms (section 6) were measured in S0 and not shipped. Breaking: runtime ABI 50, ledger 15. The library table's typed clauses name take, give, calloc_typed and realloc_typed. A fast Safe C build no longer stops at a stale reference before the slot is reused; test with -fweavec-safe-checks=full.
A full entry whose room is odd (the classes of 3072, 3584, 5120, 10240, 12288 and 28672 bytes) gave half its slots to its pool's shared list and kept half, losing the last one: it stayed claimed in its pool and was never reused. The flush now gives the larger half. rt_test entries-odd-room pins it. A typed release no longer reads the table of the slots' pools when it could not be mapped. The comment on an entry's room names its real bound, 256 KiB.
A checked unit loaded with dlopen while other threads run fast code does not see every released block as released: slots pooled before it loaded, and those another thread releases before its next slow pool operation, keep their shadow. Amendment 7 and (O4) now say so.
owenthcarey
added a commit
that referenced
this pull request
Nov 30, 2026
RFC 0055 (#82) took ABI 50, which this branch had also used for __weavec_rt_cast's new signature. RFC 0054 amendment 22.
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.
Implements RFC 0055 — A heap for safe code, which was accepted as drafted. Its Implementation amendments (1–15) and Measured gates record what was built and measured.
What changes
__weavec_rt_takepops a slot and stores the live word.__weavec_rt_givecompares the word with the expected live word, stores the released word, zeroes the object and pushes the slot.refillEntry,flushEntry). A pool that grows takes fresh slots by the half entry (joinPool).reallockeeps a block's type (§3, D3).__weavec_rt_realloc_typedgives a block from the old block's pool. The site's record types only a null or untyped block.bad-cast).tests_released.definition-mismatchnever sees, shared a pool. This is also true on main.typed(take, F),typed(give, F)(a clause a release row may now carry) andtyped(realloc_typed, 0).typedReleases, and the summary line counts typed releases).guarantees.md(O4, Y1), the Safe C and Safe C++ guides, the CLI reference, architecture, AGENTS.md, the roadmap.The in-line forms (§6) were built and measured in S0 (c). They gained 1.7% and 1.3% on two programs and nothing on the other two, short of the bar of 2% on two, so per D4 they are not shipped.
Measured (darwin-arm64, Release compilers, medians of 9; ratio to Clang -O2)
Gates not met as written, so the RFC stays Accepted:
-falign-functions=64on both builds the gap is 0.9%.Tests
rt_testpasses.rt_testgainsentries-on-and-off,entries-refill-and-flush,entries-across-threads(1,000 runs pass) andrealloc-keeps-type.test/Guards/realloc-typed.candtest/Guards/pool-layouts.cpp.entries-across-threadspasses 200 runs.GuardLibrary.cpp:1007andGuardSafe.cpp:1164.Follow-ups noticed
realloc, so a read of a grown block's new element is a falsepointer-out-of-bounds. This is on main too and is not this RFC's.