Spec-ID: x07.spec.internal.x07-memory-management@0.1.0 Status: draft Applies-to: toolchain >= v0.0.95 Related schemas: []
Memory management (native C backend)
Core model (ABI v2)
bytesis an owned heap allocation (move-only) that is dropped automatically by compiler-emitted drop glue.vec_u8is an owned growable heap allocation (move-only) that is dropped automatically; finalize withstd.vec.as_bytes(consumes the vec, wrapsvec_u8.into_bytes).bytes_viewis a borrowed read-only view intobytes/vec_u8/ runtime input buffers.- Copy a view into owned bytes with
view.to_bytes.
- Copy a view into owned bytes with
input is a bytes_view. solve must return owned bytes.
Allocator
- All allocations go through a fixed-capacity deterministic heap (
X07_MEM_CAP) that supportsalloc/freewith coalescing. - Allocations are zero-initialized.
reallocis an “allocate-new” operation; callers preserve old contents explicitly somem_stats.memcpy_bytesis deterministic.
Metrics and leak gates
- The runtime resets
mem_statsafter reading the input payload (epoch reset), so input bytes and runtime init are excluded from memory gates/scoring. - Suites can require:
assertions.mem_stats_required(must emitmem_stats)assertions.leak_free_required(enforced asmem_stats.live_bytes == 0 && live_allocs == 0at exit)
Debug borrow checks
- Debug builds can enable runtime borrow checks (
--debug-borrow-checks) and emitdebug_stats.borrow_violations. - In release builds, borrow rules are enforced statically by the compiler (lexical borrows).
Related
- ABI and execution model:
docs/spec/internal/x07-c-backend.md - Allocator interface:
docs/spec/abi/allocator-v1.md - Sanitizer gate:
./scripts/ci/check_asan_c_backend.sh