Files
AILang/examples/fieldtest/rbx_4_int_two_borrow_helpers.ail
T
Brummel 1b2d23ec42 fieldtest: raw-buf comprehensive — 4 examples, 8 findings (refs #7)
Comprehensive usability re-test of the RawBuf kernel extension in
natural LLM-author decompositions the prior field test (0058) did not
exercise: a Float RawBuf in a user ADT read through two borrow helpers,
a Bool flag buffer filled with a computed value, an Int fib buffer whose
fill reads its own writes plus two composed borrow summaries, and a
forbidden core-primitive element. All three working fixtures build, run
to expected values, and report live=0 across Float/Bool/Int widths —
the core RawBuf surface (borrow-helper composition, fill loops,
RawBuf-in-ADT, element widths) genuinely holds together.

Orchestrator triage corrected the fieldtester's run, which executed a
stale target/release/ail (built before the #50 fix). Every outcome was
re-verified against a fresh build:

- F2 (bare RawBuf ADT field unresolved) — RETRACTED: a stale-binary
  false positive. On a fresh build the bare name resolves in every
  configuration (ctor name == or != type name; builds/runs live=0). The
  #50 fix is correct and general.
- F7 (NEW, issue #51) — a `check`-clean program crashes `build`: a
  buffer whose element type is never observed by a later get/set
  defaults its element to Unit in monomorphisation and hits an
  unregistered `RawBuf_new__Unit` intercept. Affects a legitimate
  `RawBuf<Int>` used only for its size AND a forbidden locally-
  constructed element. Root: the `(new T ...)` desugar drops the
  explicit element annotation; honouring it reverses the milestone's
  § Term::New desugar decision, so it routes through brainstorm.
- F8 (process) — the field test ran stale; the fieldtester agent now
  builds from the current tree before running (plugin fix).

F1 (spec_gap) resolved here: the design ledger's §Series substrate ctor
wrote the storage field `(own (RawBuf a))`, which does not parse (`own`
is fn-param/ret only). Rewritten to the verified-authorable `(con RawBuf
a)`. The rest of the §Series listing is illustrative and its element-
less `(new RawBuf lookback)` construction is entangled with #51; a full
compile-verification of that listing belongs with the Series-substrate
work.

F5 (param-in rejects a forbidden core primitive, message names the set)
and F4/F3 (borrow composition; substrate composite) carry on. F6
(param-in set rendered as a Rust-debug list) filed as #52.

refs #7
2026-05-30 18:29:00 +02:00

77 lines
3.3 KiB
Plaintext

; Fieldtest raw-buf comprehensive .4 (Axes 1+2+3 — Int buffer, an
; own->own fill helper across a function boundary, plus TWO distinct
; borrow-receiver helpers composed over the same buffer).
;
; Task an LLM author is naturally given: "fill a buffer of N slots with
; the Fibonacci sequence, then report both the total and the index of
; the largest element." The natural decomposition is three helpers:
; - `fill` : (own RawBuf, Int) -> own RawBuf (loop/recur, runtime N)
; - `total` : (borrow RawBuf) -> Int (read loop off .size)
; - `argmax`: (borrow RawBuf) -> Int (read loop, tracks idx)
; and a main that threads the owned buffer through `fill`, then borrows
; it TWICE in sequence (`total buf`, then `argmax buf`) — the natural
; "compute several summaries of one read-only buffer" shape.
;
; This stresses the #46 borrow-receiver fix under composition: two
; independent borrows of the same owned binder, each a helper that does
; multiple RawBuf.get / RawBuf.size calls on its borrow parameter. The
; prior rawbuf_1 had a single borrow helper; this has two, called back
; to back on the same buffer, with the buffer still owned (and dropped)
; by main afterwards.
;
; Fib(0..5) = 1,1,2,3,5,8 (seeding fib(0)=fib(1)=1).
; total = 1+1+2+3+5+8 = 20
; argmax = index 5 (value 8 is largest)
; Expected stdout: "20" then "5".
(module rbx_4_int_two_borrow_helpers
(fn fill
(doc "Fill slot i with fib(i) for i in 0..n. Linear own->own.")
(type (fn-type (params (own (con RawBuf (con Int))) (con Int)) (ret (own (con RawBuf (con Int))))))
(params buf n)
(body
; Seed slots 0 and 1 to 1, then each later slot = sum of prior two,
; read back from the buffer itself via RawBuf.get on the owned `b`.
(loop (b (con RawBuf (con Int)) buf) (i (con Int) 0)
(if (app ge i n)
b
(recur (app RawBuf.set b i
(if (app le i 1)
1
(app + (app RawBuf.get b (app - i 1))
(app RawBuf.get b (app - i 2)))))
(app + i 1))))))
(fn total
(doc "Sum every slot, borrow receiver.")
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (con Int))))
(params buf)
(body
(loop (acc (con Int) 0) (i (con Int) 0)
(if (app ge i (app RawBuf.size buf))
acc
(recur (app + acc (app RawBuf.get buf i))
(app + i 1))))))
(fn argmax
(doc "Index of the largest slot, borrow receiver. Tracks (best_i, best_v).")
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (con Int))))
(params buf)
(body
(loop (best_i (con Int) 0) (best_v (con Int) (app RawBuf.get buf 0)) (i (con Int) 0)
(if (app ge i (app RawBuf.size buf))
best_i
(if (app gt (app RawBuf.get buf i) best_v)
(recur i (app RawBuf.get buf i) (app + i 1))
(recur best_i best_v (app + i 1)))))))
(fn main
(type (fn-type (params) (ret (con Unit)) (effects IO)))
(params)
(body
(let buf (new RawBuf (con Int) 6)
(let buf (app fill buf 6)
(seq (seq (app print (app total buf)) (do io/print_str "\n"))
(seq (app print (app argmax buf)) (do io/print_str "\n"))))))))