Repository navigation
Description
Summary
Add missing test coverage for allocator cleanup behavior, specifically that TempArena.drop calls reset. This is a test-only issue for an implemented behavior, not the larger first-class allocator project.
Spec
§8.3 says standard containers accept optional allocators and allocator-borrowed containers become ephemeral (docs/with-specification.md:2904-2926). The requirements campaign additionally tracks 8.3.2.5: TempArena has a destructor that calls reset() so a scoped scratch arena created for a frame is cleaned up automatically (docs/requirements.md:2660).
Current state
lib/std/alloc.w defines TempArena { allocations: Vec[i64] }, records allocations in TempArena.alloc / alloc_zeroed, resets by freeing each recorded allocation and clearing the vector, and implements TempArena.drop as self.reset() (lib/std/alloc.w:11-13, lib/std/alloc.w:40-58). The requirements campaign notes this behavior is unasserted (out/req-campaign/g04.tsv:20). The larger allocator model is incomplete and tracked by #437; this issue should not try to implement Arena, FrameArena, PoolAllocator, or Vec.new_in.
Implementation plan
- Add a focused behavior test that can observe
TempArena.dropwithout depending on allocator internals that First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 will replace. - If direct allocator observation is impossible, add a small test-only wrapper type in the test file whose
dropcallsTempArena.reset()and asserts that callingdropexplicitly or leaving scope does not crash. Prefer exact observable assertions over "compiles only." - Keep Tests: allocators coverage (§8) #481 scoped to coverage. Do not modify
lib/std/alloc.wunless the test reveals thatTempArena.dropdoes not actually run. - If the current drop scheduler bug from Bug: Drop expression temporaries are never dropped (§2.4) #430 makes scoped destructor assertions unreliable, mark this test blocked by Bug: Drop expression temporaries are never dropped (§2.4) #430 and add the test after drop scheduling is corrected.
Test plan
Add test/behavior/behav_temp_arena_drop_resets.w:
- create a
TempArena, allocate at least two pointers, let it leave scope, and verify no double-free/crash under the behavior harness. - explicitly call
scratch.reset()and then allow drop, proving reset clearsallocationsand drop does not free old pointers twice.
If the harness supports memory sanitization later, add a leak/double-free variant around this file.
Acceptance criteria
- There is a dedicated test covering
TempArena.drop -> reset. - The test does not depend on the incomplete first-class allocator API from First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437.
- Any failure caused by known Drop scheduling issues is linked to Bug: Drop expression temporaries are never dropped (§2.4) #430 instead of hidden.
with build && with build :fixpoint && with build :testpass.
Dependencies
#430 if Drop scheduling prevents reliable destructor tests. #437 for the broader allocator implementation, but not for this narrow test unless TempArena is rewritten.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 8.3.2.5.
Activity
ehartford commentedon Jul 3, 2026
Blocked, with the root cause now identified. The acceptance criteria want an observable assertion that
TempArena.droprunsreset()on scope exit. It does not:with run --debug-allocon a scopedscratch_arena()reports the allocations and the internalallocations: Vecas leaks. Root cause is #641 —lib/std/alloc.wdeclares its destructors as nakedfn Type.drop(mut self)methods, which are not the §2.4 destructor mechanism (impl Drop) and never fire.Note: #481 named #430 as the possible blocker, but #430 is closed — #641 is the real cause. Keeping #481 open; the observable drop→reset fixture (a
//! expect-debug-alloc: leak count=0behavior test) should be added once #641 converts those destructors toimpl Drop. The existingtest/behavior/behav_temp_arena.wstill covers the no-crash path.ehartford commentedon Jul 4, 2026
Update: root cause is #641 and it is not a quick fix. Converting the alloc types to
impl Dropwas attempted and reverted — the allocator API uses by-valuemut self: Arenareceivers everywhere, which move+drop the arena once the type is Drop (arena.alloc()would free the arena mid-call). #481's observableTempArena.drop -> resetfixture must wait on the allocator-ownership rework in #641. The existingbehav_temp_arena.wstill covers the no-crash path.ehartford commentedon Jul 4, 2026
Covered by
test/debug_alloc/da_temp_arena_drop_resets.w(3362ccd): TempArena's destructor runs reset() at scope exit — user allocations freed exactly once across an explicit mid-scope reset() + further allocs (no leak, no DOUBLE FREE; the two remaining counts are #608's by-design POD Vec backings, same class da_pod_vec pins). Unblocked by #641; acceptance criteria met without touching the #437 allocator project.Fix #641: std allocator destructors actually run (impl Drop conversions)