From 96f150b05516bc254c4035821c0119db1ecce301 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 21 Nov 2026 22:00:10 -0800 Subject: Simple loops, loop escapes and loop scratch Move LoopTree finding earlier. KeepAlive to force raw ptr->int to keep bytes handed to native code alive. (not sure this is worth it, alternative is to just pass the ptr) --- docs/automatic-memory-management-survey.md | 31 ++++++++++++++++++++++++++---- docs/roadmap.md | 27 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/automatic-memory-management-survey.md b/docs/automatic-memory-management-survey.md index 925fb6a2..d6fbd0c0 100644 --- a/docs/automatic-memory-management-survey.md +++ b/docs/automatic-memory-management-survey.md @@ -63,10 +63,15 @@ references, and array layouts reviewed and accepted 2026-11-19; see the - Classes explicitly opt into being deletable; the spelling is undecided. `delete` permits storage recycling rather than immediately invalidating the storage. Automatic reclamation still governs the enclosing region's lifetime. -- Arrays are never user-deletable. Their storage follows automatic lifetimes. - A container's obsolete backing storage may be internally recycled only when - the compiler proves no usable references into it survive. This is distinct - from class-slot recycling with permitted stale references after `delete`. +- Ordinary arrays are not deletable; their storage follows automatic lifetimes. + Agreed extension, 2026-11-21: deletable arrays have a distinct type (spelling + undecided), disallow interior references, and require unique access and no + escaping aliases. The compiler must establish that no usable aliases or + outstanding borrows survive `delete`; deletion consumes the owning access. + Growable library containers can use this type for power-of-two backing arrays, + explicitly deleting replaced buffers into a buddy allocator. Such arrays do + not permit the stale-reference behavior of deletable class slots. Separate + length storage remains a layout design, not a safety requirement for recycling. - `new E[N]` creates a fixed-length array, with N possibly computed at runtime. `new E[]` starts empty and permits append with `es += elem`. Access and indexed assignment are checked against the current length and do not extend @@ -238,6 +243,24 @@ the compiler can check those promises against its body; for native code the FFI declaration is trusted. A mismatch is a bug in the binding contract or its implementation, not a reason to weaken the ordinary call-site lifetime rules. +Update 2026-11-21: for the first native-call implementation, assume native code +borrows passed references only until the call returns. It does not hide, escape, +or retain them. Keep the existing pointer-to-integer ABI conversion (Plan A), +while preserving the storage lifetime through the native call. A raw address +does not itself grant a longer lifetime: using the containing lexical scope as +the keep-alive bound is acceptable, and storage may be reclaimed/reused when +that scope ends. This limitation belongs in the user documentation. Changing +native signatures to typed pointers with correctly extended machine arguments +is a fallback, not required for this first cut. + +The current analysis tracks raw-address SSA expressions, including arithmetic +and Phis, in its function/iteration frames. Brace-level lifetime markers are not +present after Opto. Raw-address returns, memory stores, and forwarding through +Simple integer parameters remain conservative rejections; typed-reference +wrappers can perform the conversion at the native boundary. Native-produced +Simple pointers still need a result-storage contract. These are implementation +limits, not a claim that all such programs inherently require unbounded storage. + #### Returned-borrow syntax and FFI boundary — agreed 2026-11-19 `from` introduces a result's borrowed-storage origin in a function type. diff --git a/docs/roadmap.md b/docs/roadmap.md index e012eae3..89504830 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -44,6 +44,15 @@ and the supporting libraries. ## Compilation and optimization +### Inferred global result storage + +Chapter 33's `testAllocationLoopWinnerAndScratch` exposes a pre-existing bug if +its top-level `Thing? t=find_noInline(arg)` is changed to `val t=...`. The nullable +winner's optimized result type is correct, but the canonical class field remains +`BOTTOM`; its Store never resolves a width and fails `StoreNode.err`. Reproduced +with the Allocation phase skipped. Fix inferred global field/layout finalization; +an explicit field type currently avoids the failure. + ### General cleanup Keep the recursive-descent path aligned with the grammar. Review moving `TYPES` @@ -55,8 +64,26 @@ convention. ### Phase ordering and incremental analysis +Required before closing Chapter 33 (deferred for now): + +- Insert NeverExits during the original LoopTree build, before Allocation. + Preserve nonreturning-function semantics through TypeCheck and serialization; + synthetic scheduling exits must not make a function appear to return. +- With those exits present, remove Allocation's special support for zero-exit + bodies, including the extra forward CFG traversal added for them. +- Maintain LoopTree membership with local edits when Lower changes the CFG; + remove the full loop-tree rebuild before scheduling. + Remaining work: +- Recognize `_exit` as nonreturning without dropping the call or its memory + dependencies. The current native-borrowing analysis accepts it, but does not + change CFG behavior. Preferred direction under discussion: connect a synthetic + live-control/TOP-value path to the function's existing Return merge, preserving + ordinary function walks, while killing the source continuation. Share the + NeverExit merge machinery if practical. Check synthetic-only return diagnostics, + serialization, and propagation through callers; do not merely set CallEnd to + dead control or introduce an unhandled edge to StopCU. - Review the remaining node-ID bitset costs in Eval2 scheduling. Scratch arrays now retain capacity and reset only touched entries, but bitsets still span previously allocated node IDs. Scheduling a newly loaded -- cgit v1.2.3