a4be1e58a3
Iteration-discipline milestone, 2 of 3. Strictly additive (nothing tail-related removed; that is it.3). New whole-body pass verify_structural_recursion sibling of verify_tail_positions (DD-1): smaller-set algorithm with implicit candidate inference + unconstrained accumulators (DD-2, foldl=structural), self/mutual via inline ADT-family union-find (DD-3), it.2-only tail==false grandfather. CheckError::NonStructuralRecursion. term_contains_loop (stops at Term::Lam, DD-4) injects Diverge so existing UndeclaredEffect enforces it, no new variant; lam-arrow + LetRec sub-effect sites wired. DESIGN.md Decision 3 synced. Four it.1 loop fixtures gained !Diverge. Two spec-premise boundary defects surfaced + resolved within the additive invariant (corpus clean, check not weakened), recorded as corrected it.3 corpus-migration scope: (1) the "21 tail-app fixtures" grandfather premise under-counts the corpus — no-ADT-candidate counter recursions have no structural position to verify, deferred to it.3; (2) two RC-regression fixtures joined the spec's transitional tail-app grandfather as the other 20 do (RC==GC guards verified still green). cargo test --workspace 622/0; 9 acceptance pins non-vacuous. Specfda9b78, planbc9f512.
88 lines
2.9 KiB
Plaintext
88 lines
2.9 KiB
Plaintext
; Iter 18g tidy follow-up RED-test fixture: a let-binder whose
|
|
; value is a Term::Var referencing a non-Own fn-param must
|
|
; inherit the param's mode for codegen's drop-emission gates.
|
|
;
|
|
; The carve-out documented in 18d.4's Iter A fix: the gate
|
|
; checks `scrutinee_is_owned` against `current_param_modes`,
|
|
; but only fn-params are recorded there. A let-binder aliasing
|
|
; an Implicit-mode fn-param passes the gate (its lookup
|
|
; misses, default = owned), so the arm-close drop fires on
|
|
; memory the caller still references.
|
|
;
|
|
; Pattern: `pin_aliased` takes `t` as Implicit-mode (default,
|
|
; no annotation); aliases it via `(let a t ...)`; matches `a`.
|
|
; In the TNode arm the pattern-bindings `l` / `r` would be
|
|
; dec'd at arm close because `a` looks owned to the gate —
|
|
; corrupting the caller's tree.
|
|
;
|
|
; Pre-fix under --alloc=rc: refcount underflow at the second
|
|
; iteration of `loop`, where the recursive call into
|
|
; `pin_aliased(t)` re-loads cells the previous iteration
|
|
; freed.
|
|
; Post-fix: clean exit, output `0`. Stats are not the focus
|
|
; here (the caller's tree leaks under the Implicit-mode
|
|
; back-compat lane); the test asserts only correctness.
|
|
|
|
(module rc_let_alias_implicit_param
|
|
|
|
(data Tree
|
|
(ctor TLeaf)
|
|
(ctor TNode (con Int) (con Tree) (con Tree)))
|
|
|
|
(fn build
|
|
(type
|
|
(fn-type
|
|
(params (con Int))
|
|
(ret (own (con Tree)))))
|
|
(params d)
|
|
(body
|
|
(if (app == d 0)
|
|
(term-ctor Tree TLeaf)
|
|
(term-ctor Tree TNode 1
|
|
(app build (app - d 1))
|
|
(app build (app - d 1))))))
|
|
|
|
; Pin via let-alias: the alias `a` is a Var-binding on the
|
|
; Implicit-mode (default) param `t`. Codegen's gate must
|
|
; recognise that `a` inherits `t`'s mode and skip the arm-
|
|
; close drop that would otherwise fragment the caller's
|
|
; tree.
|
|
(fn pin_aliased
|
|
(type
|
|
(fn-type
|
|
(params (con Tree))
|
|
(ret (con Int))))
|
|
(params t)
|
|
(body
|
|
(let a t
|
|
(match a
|
|
(case (pat-ctor TLeaf) 0)
|
|
(case (pat-ctor TNode v l r) 1)))))
|
|
|
|
; Iter it.2: integer-counter recursion holding the ADT param `t`
|
|
; constant — non-structural by the it.2 guardedness check (D2). The
|
|
; recursive call is in tail position, so it joins the transitional
|
|
; `tail-app` grandfather (spec it.2 "Transitional grandfather") as
|
|
; the rest of the corpus does until it.3 migrates such recursions
|
|
; to `(loop …)`. The 18g let-alias-mode regression this fixture
|
|
; guards lives in `pin_aliased`'s match arm-close, unaffected by
|
|
; this tail marking.
|
|
(fn loop
|
|
(type
|
|
(fn-type
|
|
(params (con Int) (con Tree))
|
|
(ret (con Int))))
|
|
(params n t)
|
|
(body
|
|
(if (app == n 0)
|
|
0
|
|
(let _v (app pin_aliased t)
|
|
(tail-app loop (app - n 1) t)))))
|
|
|
|
(fn main
|
|
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
|
(params)
|
|
(body
|
|
(let t (app build 2)
|
|
(app print (app loop 3 t))))))
|