Skip to content

List.new_in(allocator): allocator-parameterized builtin List (§8.3) #570

Done

Description

@ehartford

Restated (2026-10-25 triage)

Builtin List.new_in(allocator) (§8.3; Vec is List since D118): a List whose growth uses the supplied allocator, ephemeral when the allocator is borrowed, storable when owned.


Original report

Summary

#437 implemented the honest first step from its plan: real Arena, FrameArena, PoolAllocator, and an ephemeral ArenaVec[T] that stores elements in a borrowed arena. The remaining spec end-state is builtin standard-container allocator support: Vec.new_in(allocator) should construct a normal Vec[T] whose growth path uses the supplied allocator instead of the global heap.

Spec

§8.3 says standard containers accept an optional allocator parameter. The example uses:

fn example(arena: &FrameArena):
    var candidates = Vec.new_in(arena)
    candidates.push(1)

A container initialized with a borrowed allocator stores the borrow and becomes ephemeral; a container initialized with an owned allocator handle is storable.

Current state

  • lib/std/alloc.w now has real region/frame/pool allocators and ArenaVec[T] coverage.
  • Builtin Vec[T] is still a compiler/runtime-owned layout: { ptr, len, cap, elem_size } in lib/std/collections.w and rt/rt_core.w.
  • Runtime growth (with_vec_*) uses the global allocator unconditionally.
  • There is no allocator slot in the builtin Vec header and no codegen lowering for Vec.new_in.

Required implementation

  1. Decide and document the builtin Vec allocator ABI. Likely extend the Vec header with an allocator kind/handle slot, or introduce a side table if layout stability is required.
  2. Update the runtime with_vec_* allocation/growth/free paths to dispatch through the selected allocator. Borrowed arena/frame allocators must not individually free element buffers; global heap Vecs keep current behavior.
  3. Add compiler lowering for Vec.new_in(arena) and Vec.new_in(owned_handle).
  4. Preserve bootstrap discipline: if rt/*.w layout/runtime changes are required, follow AGENTS.md bootstrap rules and keep runtime/link-consumer changes independently fixpoint-green.
  5. Apply allocator ephemerality: Vec.new_in(&Arena) / Vec.new_in(&FrameArena) is ephemeral; owned allocator handles become storable once owned handles exist.
  6. Keep Vec.new() behavior and existing Vec tests unchanged.

Tests

  • Positive: Vec.new_in(&arena) push/get/len works and uses arena-backed growth.
  • Negative: borrowed-allocator Vec cannot be stored in a non-ephemeral struct or returned beyond the allocator scope.
  • Positive: ordinary Vec.new() remains heap-backed and storable.
  • Runtime: arena reset/drop semantics are not violated by Vec growth.
  • Bootstrap: full with build, with build :fixpoint, with build :test, and with build :test-green pass.

Dependencies / notes

Activity

  1. changed the title [-]Builtin Vec.new_in allocator ABI (§8.3)[/-] [+]List.new_in(allocator): allocator-parameterized builtin List (§8.3)[/+] on Oct 25, 2026
  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still reproduces. §8.3's example (now spelled List, D118) is refused:

    use std.alloc
    fn example(arena: &FrameArena) -> i32:
        var candidates = List.new_in(arena)
        candidates.push(1)
        candidates.len() as i32
    
    error: unknown method 'new_in' for type 'List'
    

    post-release: allocator-parameterized builtin containers are a runtime and lowering campaign.

  3. added this to the post-v0.16.0 milestone on Oct 28, 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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions