1077. allocation_cache: what an outside maintainer would fix before the move and the first tag
Raised by a read-only outside review of crates/allocation_cache, as a stranger meeting it for the
first time would. It changes nothing; it lists what the next lanes change. The number is the
recording lane's to assign.
The crate has no review package under notes/crate-reviews/, no row in the review index, and no
step in the journey that moves the contract crates. Its one Name: block says no architect has
ruled on the crate name, and helpers/name_release.py --draft allocation_cache lists 20 names, 17
with no block at all. So this review has no settled baseline to defer to: nothing below reopens a
ruling, because none exists for this crate. The review used script/crate-review-packet and
script/crate-standalone as the fact base and read every caller in the tree, which is one: the
std overlay (patches/std-nife/overlay/std/src/sys/alloc/nife/), reached through the file the
std farm copies (xtask/src/farm/copied.rs), not through any Cargo.toml.
Reuse: the template partsfoundry/crate-workflows and its scaffold, helpers/crate_move.py,
cargo-mutants, Miri, Kani, and the crate's own talc-backed host test. No new tool.
Goal
A stranger who finds allocation_cache in its own repository can tell in one screen what it is for. The crate is a bounded per-owner stash of freed small blocks in front of any locked heap, so most allocations
and frees never take the lock. The same stranger can build and test it from the README alone. One example shows how to drop it in front of a heap of their own. The repository's gates are green on the first pull request for the crate's own reasons. The public surface at the first tag is
the surface the crate means to keep.
What was checked, and how
The tools run, the sources read and what was not run are in the appendix.
Prior art
The comparison with nearby work is in the appendix.
The items
Effort: S is under half a day for a lane, M a day or two, L longer. A door is one-way when somebody outside the repository acts on it after the first tag (a public name, a published behavior, a layout, a dependency). Everything else is two-way, and the maintainer decides it. The crate has no release, so a public rename is one-way only from the tag on; the items say "one-way at the tag" for those.
P0: blocks the move
-
The manifest and the files do not stand alone. Finding:
standalone.pyfrom the template lists ten findings, andscript/crate-standaloneagrees. The crate has no README, noLICENSE-MIT, noLICENSE-APACHEand norust-version. It setslicense.workspace = trueandlints.workspace = true, which inherit from a workspace the repository will not have. A manifest comment cites a milestone (Cargo.tomlline 14). The crate documentation holds a path into this tree (src/lib.rsline 8). The crate also carries three provenance blocks and one architect's name (src/lib.rslines 32 to 34, 84 and 99).cargo packageadds that the manifest names norepository,documentationorhomepage, and it has nodescription,keywordsorcategories. Thepublish = falsecomment points atcrates/publish-allowlist.txt, a file of this tree. Change: the scaffold's README shape (README-crate.md) filled from this crate. It holds one line of purpose,## EXAMPLESwith the doc example and a second one that puts the cache in front of a heap,## Building and testingwith the three bare-metal targets,## BUGS,## Minimum Rust versionand## License. Add the two license files. Setlicense = "MIT OR Apache-2.0",rust-version = "1.88"(verified to build),description,repositoryandcategories = ["no-std", "memory-management"]. Add an inline[lints]table carryingunsafe_op_in_unsafe_fn,missing_docsandunexpected_cfgswithcfg(kani). Thepublish = falsecomment says what a stranger can act on. The move strips theName:blocks (helpers/crate_move.py,moved_source); the rest is the lane's. Door: two-way. Effort: S. -
The crate documentation addresses one consumer, and names it. Finding: the crate root says what
stddoes with the cache and howcargo xtask std-srccopies the file, and under which path (src/lib.rslines 3 to 4). It sends the reader tonotes/std/allocation.mdfor why one thread owns a cache (src/lib.rsline 8). TheBUGSentry says "A thread's cache is spilled at its end" (src/lib.rsline 29), which is the consumer's behavior and not the crate's. The crate hasdrain, and nothing calls it.heap_layout's doc explains the rule by talc's chunk grid (src/lib.rslines 95 to 97), while the rule is general. A heap sees one layout at both ends of a block. The manifest's dev-dependency comment names thestdcopy anduser_mode_runtime(Cargo.tomllines 14 to 16). A stranger reads the whole thing as a fragment of another project. The standing rule for crates that leave is that they do not talk about their consumers. Change: rewrite the crate documentation for a stranger. It says what a class is and states the three obligations of the owner. First, one owner at a time. Second,refillandspillrun under whatever excludes other users of the heap. Third, every block aspillordrainhands back goes to the heap underclass_layout(class). It says why a cached block is fungible within its class. It also says whyheap_layoutmust shape the uncached path too (any heap that rounds or tags its own way). The talc tag and chunk grid become the README's example.BUGSsays the crate-level fact: aCachedropped while it holds blocks leaks them, because it cannot free, and the owner mustdrainfirst. The reasons for a per-owner design belong in the README's design section, not in a link. Door: two-way. Effort: S. -
No workspace member depends on the crate, so the
stdfarm loses it on the day it moves. Finding:grep -rn allocation_cache --include=Cargo.tomlfinds only the workspace member list (Cargo.tomlline 106) and the crate's own manifest. The review packet's dependents table is empty. Thestdfarm finds each copied package throughcargo metadataover the workspace (xtask/src/farm/copied.rs,copied_package_directories), and the move runbook states the consequence. With no member depending on the moved crate,cargo xtask std-srcstops and names the missing package. Every other copied crate has a dependent in the tree; this one is the case the runbook describes and no crate has yet hit. Change: the move's nife-side pull request gives one workspace member a git dependency on the crate at the tag's commit, socargo metadatalists it. The natural owner isxtask, the package that copies the file. A dependency there costs one host build of a 431-line crate and states the relationship in the one manifest that already names the file. The alternative, astd_farm_sourcesmanifest that depends on every copied crate, is a general fix for the other thirteen when they leave, and is a separate milestone if wanted. The runbook's expected checks (cargo tree --locked -i allocation_cacheprints the git source,cargo xtask std-srcexits 0) already cover it. Door: two-way. Effort: S.
P2: later
The P2 items are in the appendix.
P1: before the tag
The P1 items are in the appendix.
Decisions for the architect
Each is plain background first, the recommendation, then prior art and one example. The architect ruled decisions 1 and 2. Decision 3 is two-way before the first tag, and the maintainer decided it.
Decision 1: Whether the crate gets a repository of its own
Background: the standing rule narrows which crates leave. A crate gets its own repository only if it would earn a crates.io publication on its merits or more than one repository consumes it. Otherwise it stays in its package's repository, and promoting it later is a split, the easy direction. This crate has
one consumer, the std overlay in the runtime package, reached by a generated copy rather than a
dependency. On merits: the survey behind it found no pure-Rust no_std per-thread cache on
crates.io, so the crate fills a gap, and it is 150 lines with no dependency. Against: its parameters follow one consumer's choices (item 13). Its documentation addresses that consumer (item 2). It has no proof (item 8). No allocator in the prior-art table publishes its thread cache as a library.
Ruled 2026-11-16 (UTC): the crate gets no repository of its own now. It moves with the runtime
package's repository when that package leaves. Items 1 to 9 still land in this tree, because
strangers read the crate wherever it lives, and a later split then costs one afternoon. The basis is
one consumer reached by a generated copy, parameters and documentation tied to that consumer, and no
proof yet. Splitting later is the easy direction, and the rule for crates that leave only if useful or
shared applies.
Example: nifeos/runtime holds allocation_cache/ beside user_mode_runtime/ in one workspace;
nife's xtask depends on it by git and rev on that repository, and cargo xtask std-src reads
the copied file from Cargo's checkout.
Decision 3: A Class newtype in the public signatures
Background: item 4. Every method takes the class as a bare usize that the caller got from
class, and the crate trusts it: an index past CLASSES panics on bounds, and class_bytes on
one overflows. The highest rung the tree's own ladder offers is to make the wrong state
unrepresentable: class returns Option<Class>, where Class is a #[repr(transparent)] newtype over u8 with a private field. Every method, class_bytes and class_layout take it. The
consumer's cache_for already carries the pair (&mut Cache, usize) and changes one type.
Recommendation: the newtype, before the tag. It removes two panic paths from the allocator's hot code and costs no instruction (the index is still a byte). It also reads as the API means: a class is something class mints, not a number a caller makes up. The alternative, bare usize with a
documented contract, is a one-way door the other way, because adding the newtype after the tag
breaks every caller.
Prior art: slotmap and thunderdome mint their keys and refuse a raw integer. jemalloc's szind_t is a typedef that the code never derives from user arithmetic. heapless indexes by
usize because its collections are general, which this one is not.
Example: pub struct Class(u8); pub const fn class(size: usize, align: usize) -> Option<Class>; pub fn pop(&mut self, class: Class) -> Option<NonNull<u8>>; pub const fn class_bytes(class: Class) -> usize;
Decided by the maintainer on 2026-11-14 (UTC), and ratified with decision 2: class returns Option<Class>, where Class is a #[repr(transparent)] newtype over
u8 with a private field, and class_bytes, class_layout, count, pop, push, spill and
refill take it. Item 4 is the work.
Decision 2: The crate name, the constant and method names, and Class
Ruled 2026-11-19 (UTC), option A: every name stands as built. The crate is allocation_cache. The
constants are GRID_BYTES, MAXIMUM_CLASS_BYTES, CLASSES, BLOCKS_PER_CLASS, BATCH_BLOCKS and
MAXIMUM_CACHED_BYTES. The methods are push, pop and give_back_all, and the type is Class.
The crate names what it holds and not its owner, each constant names its unit or the thing it
counts, and push and pop take std's spelling. give_back_all stays because std's drain returns
an iterator and this one takes a closure. The glibc spellings tcache_put and tcache_get are
doc(alias) search terms on push and pop.
Not brought
Items 5, 6, 8, 9 and 12 change no public name and carry a recommendation; the maintainer decides them. Item 3's choice of which manifest carries the dependency is two-way. Item 13 waits for a second consumer.
Done when
The checks are in the appendix.
Finding status
Each line was checked against crates/allocation_cache on main and the pull request that changed it.
- P0-1, manifest and files stand alone: At the move. The README, both license files, a literal
license,
rust-version,description,keywords,categoriesand an inline lints table landed in #3565 and #3660. Therepositoryanddocumentationfields name theruntimepackage's repository, and the move strips theName:blocks. - P0-2, documentation names no consumer: Done, #3565 and #3660.
- P0-3, a workspace member depends on the crate: At the move. The move's nife-side pull request
gives
xtaskagitdependency on the crate at theruntimerepository's tag, socargo xtask std-srcstill finds it. - P1-4, arithmetic edges on bare
usize: Done, #3565 and #3660.classcompares before it rounds, and theClassnewtype of decision 3 replaces the bare index. - P1-5, zeroed is empty: Done, #3565.
- P1-6, the owner's rule beyond
push: Done, #3565 and #3660. - P1-7, constant and method names: Done, #3660.
- P1-8, proofs: Done, #3565 and #3660. Five harnesses, each with a falsification patch.
- P1-9,
Freealignment asserted: Done, #3565. - P2-10, the
talcpatch left behind: At the move. Theruntimerepository builds the host test against unpatchedtalc5.1.1, and its Miri job on the move's first pull request settles the record invendor/README.md. - P2-11,
proofson an empty harness set: Done, #3565. The crate has five harnesses, so the set is not empty. - P2-12,
Debugand a leak-noticingDrop: Done, #3565 and #3660. - P2-13, constants not tunable: Done, #3565. A
BUGSline says the constants do not move. - P2-14, cross-owner free in the crate's
BUGS: Done, #3565. - P2-15, the
uncachedtest name: Done, #3565. - Decision 1, own repository: Done, #3670. The crate
moves with the
runtimepackage. - Decision 2, crate, constant and method names: Done, #3660.
- Decision 3, a
Classnewtype: Done, #3660.
Open decisions
None. The publishing hold stands.
Follow-on
- Recorded. Items 1, 3 and 10 finish when the
runtimepackage moves. No milestone schedules that move, which needs its own review clearance, and nifeos/runtime does not exist.
BUGS
- The architect ruled decision 1: the crate stays with its package, so items 3, 10 and 11 apply to the
runtimepackage's repository when it leaves, and items 1, 2 and 4 to 9 land in this tree. - The prior-art table's bin counts and depths come from memory, unverified. The shapes (a cache per owner, a batch under the lock, a flush at the owner's end) are the point, and one sitting with each source settles the figures.
- Item 10 did not reproduce the undefined behavior
vendor/README.mdrecords on the unpatched talc. The review cannot say whether the record is stale or Miri's current build misses it; the weekly job will. - The review did not run Kani, a mutation census, the stranger test or the
stdfarm after a simulated move. Item 3's failure mode comes from readingcopied.rsand the runbook, not from a run. - The renamed call sites in the
stdoverlay (entry.rs,thread_cache.rs,mod.rsand the thread block) were edited by hand and checked only by the host test and a read; thestdbuild gates are their first compile. - The tests assume
u128is 16-byte aligned, which holds on current toolchains for the host; the tests do not run on the bare-metal targets.
Index row
An outside review of allocation_cache before any move. Three items would turn the new
repository's first pull request red or stop the std farm, six land before the first tag, and six
follow later. The six cover three arithmetic edges on bare usize indices and a zeroed-is-empty contract the consumer relies on. They also cover the owner's obligations put leaves unstated, five constant names without units or things, the absence of any proof, and an alignment the code relies on without asserting. The architect ruled decision 1 (the crate moves with the runtime package, not on its own) and decision 2 (every crate, constant and method name stands, Class included). Decision 3, a Class newtype in the public signatures, is built.