Standard Library: Vec

std.vec is a growable Vec over i64-shaped slots, written entirely in MIND. It bottoms out in seven host-supplied __mind_* intrinsics, so there is no built-in pointer type, no hidden allocator, and no implementation magic above the intrinsic layer.

Warning

Availability: first shipped with mindc 0.4.0+; as of mindc 0.7.1 the std-surface layer is the shipped default (no opt-in flag). Auto-bundled into the compiler since 0.4.2 so use std.vec resolves with zero external file dependency.

Layout

Vec (heap record)

  1. data_addri64
  2. leni64
  3. capi64

data_addr points to slots of 8 bytes

  1. +0
  2. +8
  3. +16
  4. +24
  5. +32
  6. …
Three i64 fields; data_addr points to i64 slots at a stride of 8 bytes.

Struct (heap record)

Three i64 fields: data_addr, len, cap.

Stride

8 bytes per slot.

Growth

Doubling, starting at 16 slots.

Allocation

__mind_alloc on construction, __mind_realloc on growth, __mind_free on drop.

Public API

  • vec_new() -> Vec
  • vec_push(v: Vec, x: i64) -> Vec
  • vec_pop(v: Vec) -> (Vec, i64)
  • vec_get(v: Vec, i: i64) -> i64
  • vec_set(v: Vec, i: i64, x: i64) -> Vec
  • vec_len(v: Vec) -> i64
  • vec_capacity(v: Vec) -> i64
  • vec_free(v: Vec) -> i64

Example

use std.vec;

fn main() -> i64 {
    let v = vec_new();
    let v = vec_push(v, 10);
    let v = vec_push(v, 20);
    let v = vec_push(v, 30);

    let n = vec_len(v);          // 3
    let x = vec_get(v, 1);       // 20

    vec_free(v);
    return x;
}

Every operation returns the (possibly reallocated) Vec handle — there is no hidden mutation. The use std.vec declaration resolves against the bundled stdlib, with last-write-wins shadowing if your crate defines its own std.vec module.

Intrinsics this rests on

  • __mind_alloc(size: i64) -> i64
  • __mind_realloc(addr: i64, new_size: i64) -> i64
  • __mind_free(addr: i64) -> i64
  • __mind_load_i64(addr: i64, offset: i64) -> i64
  • __mind_store_i64(addr: i64, offset: i64, value: i64) -> i64

Forking the stdlib (Phase D)

  1. MIND_STDLIB_PATHset to path/to/stdlib at project-load time
  2. Project loaderreads vec.mind, string.mind, map.mind, io.mind from that directory
  3. Fallback to bundledmissing files, missing directory, or parse failure

Set MIND_STDLIB_PATH=path/to/stdlib to override the bundled blobs at project-load time — the project loader will read vec.mind, string.mind, map.mind, and io.mind from that directory instead. Missing files, missing directory, or parse failure silently fall back to bundled.

Use case: a regulated deployment that needs a stricter std.string (inline UTF-8 validation, length bound) without forking mindc itself. Same fork-without-recompile escape hatch Rust’s RUSTC_BOOTSTRAP provides.

Release history: Phase D₁ and D₂a

Shipped in mindc v0.4.3 (RFC 0005 Phase D₁). Phase D₂a (mindc v0.4.4) adds a diagnostic refinement: arity/type errors on imported pub fns preserve Named struct parameter names rather than collapsing them to the lowered ScalarI64 ABI (e.g. “expects Vec (heap-record i64 addr), got tensor<f32[3]>”).