You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the program of record for memory soundness and structured concurrency.
Each ID has a status, contract, and acceptance bar. Work stays fast by
default: checks that cost cycles on the hot path stay compile-time, cold
abort, or explicit opt-in — never a silent tax on steady-state code.
Spec text + examples under hold / share / arena / unsafe.
SAFE-003 — Compiler-generated drops for core slices — Done
Contract
Owning slices free at scope exit / reassign (when backing pointer changes). Views use cap==0. Arena slices grow into arena storage and are released only by the enclosing arena. Nested [][]T free outer + scalar inners at final drop; free-on-reassign uses *_release_replaced so shared inners after append/grow are not double-freed.
own_drop_slice_test, slice_return_own_test, nested_arr_drop_test, ASan reassign/break/append probes. slice_alias_test.mko gates owned-field value copies, consuming append, and zero leaks.
Also
Return transfers ownership + materialize-before-free; view escape/return type errors; stack POD lits (cap==0) heapify on escape.
Alias concurrency
Slice Views are NLL borrows, with one live View per base; mut Views are exclusive and may mutate their range. Their base cannot mutate, reassign, move, drop, detach, or be borrowed again while live. Slices/Views remain non-Send; refcount uniqueness never grants mutation authority. Checked retain/release abort on overflow, underflow, or resurrection.
SAFE-003b — Raw array drops (raw []T) — Done
Contract
Raw arrays use plain malloc/free (no refcount header). Single-owner; auto-freed at scope exit or reassignment via unconditional free(data). String elements are freed individually before backing. No COW, no detachment, no shared check.
Code
mako_raw_*_array_free, mako_raw_slice_append, mako_raw_*_array_make; codegen own_free_fn dispatches MakoRaw*Array types to their free functions.
SAFE-004 — Compiler-generated drops for maps — Done
Contract
Built-in and monomorph map[K]V heap handles free on scope exit (mako_map_*_free / {fnp}_free).
Code
emit_map_heap_free for monomorphs; built-ins in mako_rt.h / mako_goext.h. All 15 flavors are mapped explicitly in own_free_fn, with a MakoMapXY* fallback.
Evidence
map_* suite including nested/helpers; map pointer arrays free shallowly (no alias double-free).
SAFE-005 — String ownership / view annotations and drop verification — Done
Done
Owning string free on scope exit / reassign. Surface type string_view: zero-copy lit binding, str_as_view(s), str_to_owned(v); views never free. Empty singleton never freed.
Evidence
string_drop_test, string_view_test.
SAFE-006 — Branch / return / loop / ? / match correct drop insertion — Done (core)
Done
Block exit free; return transfer + materialize-before-free; break/continue free owns in loop-body scopes without clearing compiler tracking scopes (preserving loop-body fallthrough tracking, issue #56); ? early-return frees all live owns/shares/fn-envs + runs defers; match Result/Option Own payloads free at arm exit (or move into match result); fresh discarded bags free resolved payload shapes while indexed/field bags remain borrowed; if/match arm-local free via pop-before-restore.
Double-free guards
Live Own moves on store/arm value; aliases and field/index borrows clone. Free attaches to bind scope (not nested if/match arm). Alias muts (let mut out = path) use a runtime {name}__own flag so path-insensitive free never frees a still-aliased caller/param buffer when a reassign arm is not taken. Builtin argument temporaries (scope_drop_safe) and binary concat temps disarm immediate frees on moves and dest-destroys.
Path-local free
Early-return free only names whose bind scope is still on the stack (bind_scope_active). Sequential if-arms reusing let blob rebind own_bind_scope per arm; finished arms clear freer flags so sibling early-returns do not emit free(blob) for an undeclared C local (leba admin).
Move when the source is the registered freer (no extra alloc). Clone only for aliases / field-index borrows. Conditional free is one branch per alias mut.
Residual
Payload cleanup for discarded expressions whose source type cannot yet be recovered by codegen; labeled multi-loop edge cases if/when multi-level labels land.
SAFE-007 — Reject borrowed and arena value escapes — Done (core)
Done
Arena return escape; slice view store/return escape; arena store into fields/outer assigns (arena_store_field.mko).
CMap uses a portable readers/writer gate: concurrent readers, exclusive writers for probe+mutate and grow. No lock-free unsynchronized read of open-addressed tables.
Code
runtime/mako_cmap.h — mako_rwmutex_rlock / lock around get/set/del/incr/grow.
Speed
Readers share; writers exclusive; grow under write lock. Prefer batching sets off hot paths.
SAFE-010 — Publish the concurrency memory model — Done
The iterated collection is marked as borrowed during for-loop body type checking. Reassignment, append, or mutation of the collection inside the loop is a compile-time error. Mutating a different collection is allowed.
Code
shared_borrows insert in Stmt::For handler (types/mod.rs); assignment check rejects writes to borrowed names.
Leaving crew → cancel flag + join all ordinary kicks. Cooperative cancel; blocked C/FFI may delay join. New kicks after cancel do not start threads. First child Err recorded.
SAFE-006 (break/continue/return/?/match) — loop-exit cleanup; return transfer + materialize; ? early free; match Own free; bind-scope free; alias-mut __own flag; move/clone store rules (no double-free).
Actors isolate mutable state by construction: each actor's fields are private
and never shared across threads. The mailbox is a bounded channel (sized at
spawn via Name_spawn_cap(cap)). Named ports (receive Msg on port) add more
mailboxes to that same loop; they do not share self. Receive-arm return continues the actor loop
after dropping that arm's owned envelope fields; shutdown drain unboxes leftover
envelopes by tag and frees nested owners. Scalar int payloads that do not fit
signed 48-bit packing abort. Combined with structured crew scoping, actors do
not race on actor state; envelope lifetime is enforced by those drop paths, not
by a tracing GC.
Non-goals
Tracing GC
Disabling bounds checks in “safe release”
Free go without a crew
Making Sync handles the default for ordinary locals