Skip to content

Tests: allocators coverage (§8) #481

Closed

Description

@ehartford

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

  1. Add a focused behavior test that can observe TempArena.drop without depending on allocator internals that First-class allocators: real Arena/FrameArena/Pool, Vec.new_in, ephemeral virality (§8.3) #437 will replace.
  2. If direct allocator observation is impossible, add a small test-only wrapper type in the test file whose drop calls TempArena.reset() and asserts that calling drop explicitly or leaving scope does not crash. Prefer exact observable assertions over "compiles only."
  3. Keep Tests: allocators coverage (§8) #481 scoped to coverage. Do not modify lib/std/alloc.w unless the test reveals that TempArena.drop does not actually run.
  4. 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 clears allocations and 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

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Blocked, with the root cause now identified. The acceptance criteria want an observable assertion that TempArena.drop runs reset() on scope exit. It does not: with run --debug-alloc on a scoped scratch_arena() reports the allocations and the internal allocations: Vec as leaks. Root cause is #641 — lib/std/alloc.w declares its destructors as naked fn 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=0 behavior test) should be added once #641 converts those destructors to impl Drop. The existing test/behavior/behav_temp_arena.w still covers the no-crash path.

  2. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    Update: root cause is #641 and it is not a quick fix. Converting the alloc types to impl Drop was attempted and reverted — the allocator API uses by-value mut self: Arena receivers everywhere, which move+drop the arena once the type is Drop (arena.alloc() would free the arena mid-call). #481's observable TempArena.drop -> reset fixture must wait on the allocator-ownership rework in #641. The existing behav_temp_arena.w still covers the no-crash path.

  3. ehartford commented on Jul 4, 2026

    @ehartford
    ContributorAuthor

    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.

  4. added a commit that references this issue on Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions