Repository navigation
Description
Maintainer-scheduled 2026-07-19 as the headline campaign of the next cycle (post-v0.16.0), sequenced AFTER #685 (arenas attack the same memory pool for the 8 GB goal with zero semantic risk, and de-risk this campaign's perf story). Supersedes the provisional by-design ruling in #608 (which explicitly said "refile as that project when it's actually scheduled" — it now is). Context: #606, #608, #689 investigation.
The problem
Sema.type_needs_drop (A5): Vec[T] needs drop iff T does, so POD-element containers (Vec[i32], Vec[str], …) never free their buffers — not at scope exit, not at reassignment. Every long-running With program (e.g. #658's TCP servers) accumulates buffers forever; migrated C libraries inherit the leak; part of the compiler's own 4.9 GB frontend envelope is never-reclaimed buffers.
The leak is currently load-bearing: the compiler pervasively copies POD Vec headers as cheap value handles (e.g. Backend's per-unit backend_intern copies). If drop glue freed buffers today, stale header copies would be use-after-free and realloc-through-one-copy would strand the others. The flip is therefore an ownership migration first, a drop-glue change second.
Direction (ruled): Rust/Vale unique ownership, not ARC/GC
- Move-only container headers + drop elaboration (assign-site + scope-exit), the Rust/Vale destination. Vale is the ownership reference (single ownership, deterministic destruction / Higher RAII).
- NOT Swift-style ARC/CoW: pays runtime cost (atomic retain/release under the Compiler: window codegen-unit fan-out; dispose base LLVM module and MIR before fan-out (study delta 2) #681 emit threads) on every user forever to save compiler-side migration — inverts the mission's trade ("With pays COMPILER complexity").
- NOT GC ("native by default").
- App developers type zero new characters.
f(xs)is already a D5 share-place borrow — the header-copy-as-borrow idiom is compiler-internal, and D5 is the migration tool: most compiler header copies become the real borrows the language already has. True snapshot sites (per-unit intern copies) become explicitcopy/clone — visible, priced, confined to the library-maintainer tier.
Shape (increments, each battery-gated)
- Inventory: find every POD-container header copy in src/ via
with analyzefacts (effect summaries already classify share-place vs owned) — classify borrow-shaped vs snapshot-shaped. - Migrate compiler source: borrow-shaped copies → share-place params; snapshot-shaped → explicit clone. Compiler must be green under BOTH ownership regimes (dual-compatible window, Parser: inner if-chain ending in 'else if' swallows the outer chain's next else at the same column #629-style flip protocol with prompt reseed).
- Flip the gate:
type_needs_dropwide (containers always); drop glue frees POD buffers; assign-site + scope-exit + partially-moved-field paths all covered (the Place reassignment never drops the old contents — plain 'v = w' on a local leaks (shipped) #689 session's MirLower prototype showed the drop-statement side already works — the gates are at Sema+glue). - Re-pin the lane:
test/debug_alloc/da_pod_vec.wexpectation flips to leak count=0; the Place reassignment never drops the old contents — plain 'v = w' on a local leaks (shipped) #689 reassignment matrix (session transcript) lands asda_reassign_drops_old_value.w; full battery + allocator lane + fixpoint; measure compiler RSS delta (expect meaningful frontend-envelope reduction — quantify vs the 4.9 GB baseline).
Acceptance
var v: Vec[i32] = Vec.new(); v.push(1)→ allocator-clean at scope exit.- Reassignment matrix (root/field/whole-struct/branch/loop/move-then-reassign/partial-move) allocator-clean.
- Fixpoint byte-identical; full battery; compiler self-hosts with measured RSS reported.
- D12 heap-owner bare-self (enabled by the gate-removal commit) becomes leak-free automatically through the same assignment path.
Activity
Sema: mut self binds mutable for every owner type (D12 uniformity); d…
Docs: handoff — both 2026-07-19 rulings executed (#691 filed; D12 gat…
Sema: mut fn on str owners lowers via share-place over the fat pointe…
Tools: drop-audit matrix as a repo-committed With tool + :drop-audit …
ehartford commentedon Jul 20, 2026
INVENTORY DONE — empirically, and it reframes this campaign. The #608 "coordinated migration, pervasive header copies would double-free" premise is wrong; the flip is bounded and its core is proven sound.
The core flip is ~10 lines, two coupled gates:
Sema.type_needs_drop(Vec[T])→1(was: iff T needs drop — the A5 narrow gate).CodegenDispatch.mir_emit_drop_vec_ptr: free the buffer unconditionally; run the element-drop loop only when the element needs drop (was: return false / no-op for POD elements — the codegen half of A5). This second gate is why flipping Sema alone was inert (Place reassignment never drops the old contents — plain 'v = w' on a local leaks (shipped) #689's observation confirmed).Generated code is double-free-free. With both gates flipped, built through stage1:
Vec[i32]scope-exit,Vec[str]reassign (was leak=2), nestedVec[Vec[i32]]→ allleak count=0.tools/drop_audit.w: 58/58 correctness cells still PASS; the only movers are the two POD-leak cells flipping to leak-free (their POD Vec[i32] buffer never freed at scope exit (debug-allocator finding) #608 expectation is now stale). Zero new double-frees. This is the key result — becauseVecis already non-Copy (noimpl Copy for Vecexists; by-value passing is D5 share-place, not duplication), single-ownership already holds and the flip is sound in generated code.The compiler-source cost is a statically-enumerated flag-day, not runtime landmines. A full self-host under the flip fails to compile (not crash) with ~140 unique sites across ~18 files (main.w 69, CodegenDispatch 67, CodegenTraits 22, MirLower 19, …):
takes ownership of a non-Copy value(§3.8) anduse of moved value. These are places the compiler's own code passed/moved a now-owning POD-Vec-bearing value relying on the old non-drop "effectively free" behavior. The effect system hands every one back at compile time — the #629/D7 "red build is the instrument" protocol.So #691 is: the 10-line flip + a 140-site ownership migration (move/copy/borrow per site), each verified by the flipped stage1 checker, gated by drop-audit + fixpoint + battery. Bounded, mechanism-proven, and — since it frees the frontend's never-freed POD buffers — a direct hit on the #685 8 GB target too. Not a post-release unknown; an in-scope flag-day. Increment 2 (the migration) starting now.
ehartford commentedon Jul 20, 2026
MAJOR UPDATE — the flip's correctness is trivial; the real obstacle is compile-memory, which vindicates the #685-before-#691 sequencing on memory grounds (not correctness).
The 140-site "migration" was one bug. After landing #695 (move checker: partial/field moves on a divergent branch wrongly poisoned the fall-through — the
return builder.body-in-branch pattern), re-applying the two-gate Vec flip drops the compiler-source migration from 140 sites → 0. The flipped compiler checks its own source clean. #608's "coordinated migration, pervasive header copies" premise is fully refuted: #691-for-Vec = a ~10-line two-gate change + the already-landed #695, nothing else. Generated code stays double-free-free (drop-audit 58/58 correctness cells; POD cells flip leak-free); user Vecs (scalar/str-reassign/nested) allleak count=0.But the flip roughly DOUBLES compile memory. A full self-host under the flip does not crash (correctness holds) — it exceeds the 32 GiB tripwire during stage2's build (
committed=33.1 GB, reproducible without contention). Cause: making every PODVecneed drop propagates through the type graph — every struct/enum/compiler-table that contains a Vec (AstPool, MirBody, every Sema/Codegen table) now emits buffer-free drop glue at every scope exit. That's a combinatorial codegen-size explosion (inline drop glue, emitted per-site).So the flip is correctness-complete but memory-blocked. Two ways forward, both in the #679/#685 memory family:
__drop_Tfunction per type and call it, instead of inlining the glue at every scope exit. This is a codegen-size win independent of the flip and likely what makes the flip fit; candidate to file under Runtime: return empty small-object slabs to the OS; phase-scoped arenas (study delta 7) #685.Confirming now whether it self-hosts + fixpoints byte-identically with the cap lifted (correctness under memory). If yes: the Vec flip is done modulo the drop-glue-size work — exactly the #685-first ordering, now proven necessary on the numbers.
ehartford commentedon Jul 21, 2026
CORRECTION — two claims in the "MAJOR UPDATE" comment above were wrong. Retracting both.
1. "140 sites → 0" was mis-measured. The site-count check OOM'd before it reported; a
grepover the truncated output saw 0 and I read that as "flipped compiler checks its own source clean." It does not. The flip is not a single-#695 fix — it unmasked a family of latent move-checker bugs, because wideningtype_needs_drop(Vec[T])turns every POD Vec into a drop-tracked, single-owner value and routes a large swath of previously-untracked code through the loop/branch move checker for the first time. Two are now fixed:set_moved_field_unionconcatenated instead of dedup'ing.continueback-edge): a value moved before a loop with acontinuewas wrongly flagged as moved inside it — a day-one Loop maybe-init dataflow: accept reinit (§2.4) and move-then-break; reject only genuine use-after-move #613 bug, independent of the flip (a plain Drop struct on the seed reproduces it).Residual sites remain to be worked. The migration is a small number of shared checker root causes, not 140 independent edits — but it is not zero.
2. The "flip doubles compile memory via drop-glue combinatorial explosion" diagnosis was wrong. The ~100 GB was not codegen-size from inlined drop glue. It was #695's concat-without-dedup in the move checker (my own uncommitted code): a field moved on both arms was re-added to the moved-field set at every branch merge, growing the arrays ~2^N across nested branches, and
sema_clone_i32_vec(called per branch) then blew to ~100 GB. The dedup fix (membership check before union, committed ee4e5f4) takes the flipped self-host from ~100 GB → ~1.1 GB. The drop-glue outlining I built (4295801) is a real, behavior-neutral codegen-size win, but it did not reduce the flip's memory — measured identical before/after. So the flip is not memory-blocked on drop-glue; that whole line was a misdiagnosis from reasoning instead of profiling. (samplenaming my own function was what finally settled it.)Corrected picture: the flip's blocker is a family of latent move-checker bugs, not codegen size. #695 and #696 are fixed and committed; the class is now guarded by a move-checker verdict matrix (
tools/move_audit.w/with build :move-audit, the compile-time analog of:drop-audit). Next: work the residual sites and re-measure the flipped self-host end to end.ehartford commentedon Jul 21, 2026
STATUS after #695/#696 fixes + reseed — the memory blocker is SOLVED, and the residual is (again) mostly a shared checker bug, not a migration.
Memory: peak 1.16 GB (was ~100 GB) for the flip-enabled compiler checking its own 160k-line source. The #695 partial-move-merge dedup fix holds under the full flip. This was the actual blocker; it's gone.
Method: reseed to the #695/#696-fixed compiler, apply the two-gate flip (Sema.type_needs_drop(Vec) → 1; CodegenDispatch.mir_emit_drop_vec_ptr → always free the buffer, drop elements only when the element needs drop), build a flip-enabled stage1, run
stage1 check src/main.w.118 residual errors, in three classes:
mut receiver is too weak; requires move fn— a SHARED CHECKER BUG, not 57 edits. The flip makes Vec fields drop-bearing, and the effect inference then wrongly escalatesmut fn→move fnfor any method that reassigns/drops such a field. Confirmed onZcu.reset_for_new_invocation, which is a pure in-place reset (self.extra_source_names = Vec.new()…) — unambiguouslymut, never consumingself. Runningmigrate_receivershere would wrongly consumeselfon 57 compiler methods and break everything. Root-cause this like Move checker: partial (field) move on a divergent branch wrongly poisons the fall-through #695/Move checker: value moved BEFORE a loop is wrongly flagged at the loop's back-edge #696 (effect inference over-escalating on drop-bearing-field reassignment); expect it to clear most of the 57.this parameter takes ownership … pass move/copy— the predicted move-arg sites.migrate_method_arg_moveshandles these, but it (correctly) refuses while unrelated errors exist, so the receiver bug must be fixed first. Some of these 52 may also be false once the receiver bug is fixed — re-check before migrating.use of moved value— likely genuine use-after-move; hand-fix.Takeaway: the flip is still a family of shared checker bugs surfaced by widening
type_needs_drop, not 111 independent edits. Generated code is already correct (drop-audit 58/58). The flip itself is 2 edits (reverted to keep the tree clean). Next focused session: root-cause the receiver-escalation bug, re-check, then migrate whatever genuine move-args remain + the 2 real moves.Sema: divergence-aware branch merge for the partial-move set (#695)
Codegen: outline structural drop into per-type functions (#679/#691)
Sema: correct loop-carried move checking — continue back-edge guard (#…
Sema+MirLower: D17 — field consumption writes the root; `move place` …
Sema: static calls pair arg_i with param_i; Backend: sema take-and-re…
Analysis: move-sites classifier + explain:effect provenance (#691 ste…
Build: fingerprint memory discipline + serial action workers (#702)
3 remaining items
D22: contextual-Copy semantics, view arithmetic, and post-flip owners…
D22: fix the three remaining spec-lane regressions (ss10_5, ss13_3, s…
Retire pre-flip handle-aliasing helpers: compiler self-checks under i…
Foundation modules: fix copy-view-drop double frees; re-pin masked ph…
Debug-alloc lane: retire the two #608 leak-by-design pins (#691 flip …
Backend: take-and-return the pools lent to the analysis codegen run (#…
Lsp: document cache reads are views; ensure_doc_* rebuild instead of …
Lsp: get_parsed returns a fresh caller-owned parse, never the cached …
D27 rulings 1+3 implementation: JsonView is a Copy token; a typed let…
D27 E1+E2: cross-file migrate stores owned copies of session type text (
c-migrate: index decl-name lookups; memoize decl cursors (#744)
ehartford commentedon Aug 31, 2026
Triage 2026-08-31: CLOSE (campaign complete). The wide flip landed and verifies: POD Vec buffers free at scope exit AND at reassignment (--debug-alloc leak count=0), test/debug_alloc/da_pod_vec.w expects leak count=0, and 8dc76fa retired the #608 leak-by-design pins. The RSS/8GB follow-through is tracked by the open #679 campaign.
Copy glue of a struct is one per-type function; `move x` of a binding…
D120 stage 3: a struct of values is a value (no impl Copy written); s…