feat(lang): eliminate the Implicit ownership default — totality + the drop-soundness it demasks (#55)
Deletes `ParamMode::Implicit`. `ParamMode` is now `{Own, Borrow}`:
every fn-type slot on every signature carries an explicit `own` or
`borrow`, no defaulted position survives anywhere (model 0008 §2,
spec 0062). The parser rejects a bare fn-type slot; `borrow-return`
and `borrow-over-value` reject at the signature; the corpus is
migrated to minimal-ownership modes (consumed ⇒ own, read-only-heap
⇒ borrow, value ⇒ trivial-own). The documented `Implicit`-ret-mode
leak is fixed: an owned heap return now drops exactly once (live=0,
acceptance criterion 5).
This was the easy half. Removing the default ACTIVATED a family of
drop paths that `Implicit` had silently skipped — the pre-cutover
language was leaking (and in places mis-dropping) here rather than
crashing, because an Implicit scrutinee turned the drop off. Making
the modes explicit (Own) turned those paths on and exposed two
latent-bug clusters, all fixed RED-first as part of this cutover:
Drop-soundness family (four legs):
A. lit-sub-pattern double-free — the desugar re-matched the same
owned scrutinee in the lit fall-through; fixed by grouping
consecutive same-ctor arms into one match (bind fields once),
in ailang-core desugar.
B. Cons-husk leak on non-tail arm bodies — the lit-sub-pattern
desugar rebound the owned scrutinee via `Let $mp = xs`, which
bumped consume_count and suppressed the existing fn-return
partial_drop. Fixed by not rebinding a bare-Var scrutinee
(one husk-freeing mechanism, not two).
C. polymorphic `drop_<T>` rc_dec'd monomorphised value fields —
the per-ADT drop fn was emitted once from the polymorphic
TypeDef, defaulting type-var fields to ptr and rc_dec'ing
inline Ints (segfault). Fixed with per-monomorph drop
functions (new ailang-codegen::dropmono): the drop set is
collected from the lowered MIR, value-type fields are skipped,
heap fields still freed once; monomorphic-concrete ADTs keep
their byte-identical un-suffixed drop symbol.
D. static Str literal passed to an `(own Str)` param — the
literal lowers to a header-less rodata constant; the callee's
now-active rc_dec read its length field as a refcount and
freed a static address (segfault). Fixed with the missing
fourth StrRep::Static→Heap promotion in lower_to_mir's App arm,
gated on Own mode (borrow args stay static, no regression).
over-strict-mode lint over-fired: it suggested `(borrow V)` for
value-typed params (which `borrow-over-value` rejects — own is the
only legal mode there) and fired on `(intrinsic)` bodies (whose
consumption the linearity walk cannot observe). Tightened to skip
both; contract 0008 updated to the narrowed firing scope.
Irreversible step — canonical-form hash reset (model 0008 §6,
acceptance criterion 6). Every signature now carries explicit modes,
so the hashable canonical JSON changed for every module. RATIFY:
the corpus-wide hash-pin reset (hash_pin, prelude_module_hash_pin,
mono_hash_stability, eq_ord_e2e, embed_export_hash_stable, the
ct4/iter*/loop_recur schema-extension pins) and the list ir_snapshot
golden were regenerated once, deliberately, as the intended one-time
consequence of removing the mode elision from the canonical form —
not a regression. Each regenerated hash verified deterministic across
two runs.
Also fixes a pre-existing latent failure surfaced by the verification
gate, unrelated to this cutover: the `every_contract_names_a_resolvable_
ratifying_test` resolver (design_index_pin) could not resolve the
" + " dual-link ratifying-test form (`uniqueness.rs + linearity.rs`)
that the #57 audit-close (dfdc65f) introduced — it shipped red on that
commit. Resolver taught the dual-link form, mirroring its sibling.
Verification: cargo test --workspace = 731 passed, 0 failed (twice,
stable); e2e 102 passed, no binary exits non-zero (corpus crash-free);
grep-clean for Implicit/fn_implicit/mode_eq across crates; every drop
fix confirmed via emitted IR + AILANG_RC_STATS balance on the head==K,
head!=K, and Nil paths. Three BLOCKEDs en route (the unsound first
husk-dec attempt, the over-strict derivation premise, the leg-B fix
direction) were each treated as a real design/spec gap and rediagnosed,
not patched over.
Supersedes #54 (return-position-only leak patch). Precondition #57
(linearity hardening) was already met. Spec docs/specs/0062, plan
docs/plans/0121.
closes #55
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
(module bare_slot_reject
|
||||
|
||||
(fn id
|
||||
(doc "MUST FAIL post-cutover: bare `(con Int)` slot carries no mode.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))))
|
||||
(params x)
|
||||
(body x)))
|
||||
@@ -28,9 +28,9 @@
|
||||
(doc "Higher-order: apply f three times to seed.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (fn-type (params (con Int)) (ret (con Int)))
|
||||
(con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params f seed)
|
||||
(body
|
||||
(app f (app f (app f seed)))))
|
||||
@@ -39,15 +39,15 @@
|
||||
(doc "For each i in [n-1, n-2, ..., 0], build a closure capturing i, pass to apply_thrice, accumulate. Tail-recursive on i and acc.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params i acc)
|
||||
(body
|
||||
(if (app lt i 0)
|
||||
acc
|
||||
(let-rec helper
|
||||
(params x)
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(body i)
|
||||
(in
|
||||
(let r (app apply_thrice helper i)
|
||||
@@ -55,12 +55,12 @@
|
||||
|
||||
(fn run
|
||||
(doc "Drive run_loop from i=n-1 down to 0.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body (app run_loop (app - n 1) 0)))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app print (app run 10000))
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
(doc "Tail-recursive: count Collatz steps from n to 1, accumulating in acc.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params n acc)
|
||||
(body
|
||||
(if (app eq n 1)
|
||||
@@ -41,8 +41,8 @@
|
||||
(doc "Tail-recursive: sum collatz_steps(i) for i in [n, n-1, ..., 1].")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params i total)
|
||||
(body
|
||||
(if (app eq i 0)
|
||||
@@ -52,12 +52,12 @@
|
||||
(app + total (app collatz_steps i 0))))))
|
||||
|
||||
(fn run_one
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body (app print (app sum_steps_loop n 0))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 10000)
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
(doc "Tail-recursive: acc += i*7 for i in [n, n-1, ..., 1]. Returns final acc.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params i acc)
|
||||
(body
|
||||
(if (app eq i 0)
|
||||
@@ -35,12 +35,12 @@
|
||||
(app + acc (app * i 7))))))
|
||||
|
||||
(fn run_one
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body (app print (app intsum_loop n 0))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 1000000)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
; layout is the same width as bench_list_sum's IntList ICons,
|
||||
; but the type-arg substitution is the additional code path.
|
||||
; 2. The traversal is via `fold_with_fn` — an HOF taking
|
||||
; `(fn-type (params a) (ret (con Int)))` as its first param.
|
||||
; `(fn-type (params (own a)) (ret (own (con Int))))` as its first param.
|
||||
; Each step calls `(app f h)` — an indirect call through the
|
||||
; fn-arg. This is the only fixture that exercises tight-loop
|
||||
; indirect dispatch.
|
||||
@@ -36,8 +36,8 @@
|
||||
(doc "Build [0, 1, ..., n-1] :: List Int. Tail-recursive accumulator form.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con List (con Int)))
|
||||
(ret (con List (con Int)))))
|
||||
(params (own (con Int)) (own (con List (con Int))))
|
||||
(ret (own (con List (con Int))))))
|
||||
(params n acc)
|
||||
(body
|
||||
(if (app eq n 0)
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
(fn inc
|
||||
(doc "Add 1 to an Int. Used as the HOF argument to fold_with_fn.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params x)
|
||||
(body (app + x 1)))
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
(type
|
||||
(forall (vars a)
|
||||
(fn-type
|
||||
(params (fn-type (params a) (ret (con Int)))
|
||||
(con List a)
|
||||
(con Int))
|
||||
(ret (con Int)))))
|
||||
(params (borrow (fn-type (params (own a)) (ret (own (con Int)))))
|
||||
(own (con List a))
|
||||
(own (con Int)))
|
||||
(ret (own (con Int))))))
|
||||
(params f xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
(fn run_one
|
||||
(doc "Build [0..n-1], fold with inc, print sum of (inc x).")
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
(app print
|
||||
@@ -79,7 +79,7 @@
|
||||
0))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 100000)
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
(doc "Build a balanced tree of given depth, every value = 1. Returns owned Tree; main holds it across the loop and the final drop fires at main's scope close.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Tree)))))
|
||||
(params depth)
|
||||
(body
|
||||
@@ -61,7 +61,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (borrow (con Tree)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params t)
|
||||
(body
|
||||
(match t
|
||||
@@ -74,7 +74,7 @@
|
||||
(doc "Tail-recursive list builder. Returns owned chain; caller is sum_list which owns and drops it.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (own (con IntList)))
|
||||
(params (own (con Int)) (own (con IntList)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n acc)
|
||||
(body
|
||||
@@ -88,7 +88,7 @@
|
||||
(doc "Build [0,1,...,n-1] :: IntList. Returns owned chain.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n)
|
||||
(body
|
||||
@@ -98,8 +98,8 @@
|
||||
(doc "Tail-recursive sum. Owns xs; consumes it via the LCons arm's t binder (move-into-tail-call).")
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con IntList)) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -112,7 +112,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con IntList)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(app sum_list_acc xs 0)))
|
||||
@@ -121,8 +121,8 @@
|
||||
(doc "One bench operation: build+sum a fresh CHUNK_LEN-cell list, pin the tree's root, return their sum so the value chain stays observable. Tree is borrowed; no inc/dec on the hot path against the persistent cache.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (borrow (con Tree)))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (borrow (con Tree)))
|
||||
(ret (own (con Int)))))
|
||||
(params chunk_len t)
|
||||
(body
|
||||
(app + (app sum_list (app cons_n chunk_len)) (app pin_root t))))
|
||||
@@ -133,8 +133,8 @@
|
||||
(doc "Tail-recursive bench loop. Tree is borrowed across all iterations.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int) (con Int) (con Int) (borrow (con Tree)))
|
||||
(ret (con Unit))
|
||||
(params (own (con Int)) (own (con Int)) (own (con Int)) (own (con Int)) (borrow (con Tree)))
|
||||
(ret (own (con Unit)))
|
||||
(effects IO)))
|
||||
(params remaining print_countdown chunk_len print_k t)
|
||||
(body
|
||||
@@ -159,7 +159,7 @@
|
||||
|
||||
(fn main
|
||||
(doc "Top-level: build tree, signal READY (8888), run loop, signal DONE (9999 emitted by loop).")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let t (app build_tree 19)
|
||||
|
||||
@@ -69,8 +69,8 @@
|
||||
(doc "Build a balanced tree of given depth, every value = 1. Constructor-blocked — recursion depth = `depth`, fits 8MB stack at depth 19.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Tree))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Tree)))))
|
||||
(params depth)
|
||||
(body
|
||||
(if (app eq depth 0)
|
||||
@@ -84,8 +84,8 @@
|
||||
(doc "Touch every node of the tree (ensures liveness across the loop).")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Tree))
|
||||
(ret (con Int))))
|
||||
(params (own (con Tree)))
|
||||
(ret (own (con Int)))))
|
||||
(params t)
|
||||
(body
|
||||
(match t
|
||||
@@ -99,8 +99,8 @@
|
||||
(doc "Tail-recursive list builder. Result = [n-1, n-2, ..., 0] :: IntList.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con IntList))
|
||||
(ret (con IntList))))
|
||||
(params (own (con Int)) (own (con IntList)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n acc)
|
||||
(body
|
||||
(if (app eq n 0)
|
||||
@@ -113,8 +113,8 @@
|
||||
(doc "Build [0,1,...,n-1] :: IntList.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con IntList))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n)
|
||||
(body
|
||||
(app cons_n_acc n (term-ctor IntList LNil))))
|
||||
@@ -123,8 +123,8 @@
|
||||
(doc "Tail-recursive sum.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -136,8 +136,8 @@
|
||||
(doc "Sum every element. Calls sum_list_acc with seed 0.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(app sum_list_acc xs 0)))
|
||||
@@ -158,8 +158,8 @@
|
||||
(doc "Constant-time tree liveness pin — read root tag, return 1 (TNode) or 0 (TLeaf).")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Tree))
|
||||
(ret (con Int))))
|
||||
(params (borrow (con Tree)))
|
||||
(ret (own (con Int)))))
|
||||
(params t)
|
||||
(body
|
||||
(match t
|
||||
@@ -170,8 +170,8 @@
|
||||
(doc "One bench operation: build+sum a fresh CHUNK_LEN-cell list, pin the tree's root, return their sum so the value chain stays observable.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Tree))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (borrow (con Tree)))
|
||||
(ret (own (con Int)))))
|
||||
(params chunk_len t)
|
||||
(body
|
||||
(app + (app sum_list (app cons_n chunk_len)) (app pin_root t))))
|
||||
@@ -192,8 +192,8 @@
|
||||
(doc "Tail-recursive bench loop. Ops countdown in `remaining`; print marker every time `print_countdown` hits 0.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int) (con Int) (con Int) (con Tree))
|
||||
(ret (con Unit))
|
||||
(params (own (con Int)) (own (con Int)) (own (con Int)) (own (con Int)) (borrow (con Tree)))
|
||||
(ret (own (con Unit)))
|
||||
(effects IO)))
|
||||
(params remaining print_countdown chunk_len print_k t)
|
||||
(body
|
||||
@@ -218,7 +218,7 @@
|
||||
|
||||
(fn main
|
||||
(doc "Top-level: build tree, signal READY (8888), run loop, signal DONE (9999 emitted by loop).")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let t (app build_tree 19)
|
||||
|
||||
+10
-10
@@ -40,8 +40,8 @@
|
||||
(doc "Tail-recursive list builder. Result = accumulator-prepended list.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con IntList))
|
||||
(ret (con IntList))))
|
||||
(params (own (con Int)) (own (con IntList)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n acc)
|
||||
(body
|
||||
(if (app eq n 0)
|
||||
@@ -54,8 +54,8 @@
|
||||
(doc "Build [0, 1, ..., n-1] :: IntList. Order doesn't matter for sum.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con IntList))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n)
|
||||
(body
|
||||
(app cons_n_acc n (term-ctor IntList INil))))
|
||||
@@ -64,8 +64,8 @@
|
||||
(doc "Tail-recursive sum.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -77,21 +77,21 @@
|
||||
(doc "Sum every element. Calls sum_acc with seed 0.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(app sum_acc xs 0)))
|
||||
|
||||
(fn run_one
|
||||
(doc "Build a list of length n, sum it, print the sum.")
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
(app print (app sum_list (app cons_n n)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 100000)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
data IntList = INil | ICons(Int, IntList)
|
||||
|
||||
/// Tail-recursive list builder. Result = accumulator-prepended list.
|
||||
fn cons_n_acc(n: Int, acc: IntList) -> IntList {
|
||||
fn cons_n_acc(n: own Int, acc: own IntList) -> own IntList {
|
||||
if eq(n, 0) {
|
||||
acc
|
||||
} else {
|
||||
@@ -12,12 +12,12 @@ fn cons_n_acc(n: Int, acc: IntList) -> IntList {
|
||||
}
|
||||
|
||||
/// Build [0, 1, ..., n-1] :: IntList. Order doesn't matter for sum.
|
||||
fn cons_n(n: Int) -> IntList {
|
||||
fn cons_n(n: own Int) -> own IntList {
|
||||
cons_n_acc(n, INil)
|
||||
}
|
||||
|
||||
/// Tail-recursive sum.
|
||||
fn sum_acc(xs: IntList, acc: Int) -> Int {
|
||||
fn sum_acc(xs: own IntList, acc: own Int) -> own Int {
|
||||
match xs {
|
||||
INil => acc,
|
||||
ICons(h, t) => tail sum_acc(t, acc + h)
|
||||
@@ -25,16 +25,16 @@ fn sum_acc(xs: IntList, acc: Int) -> Int {
|
||||
}
|
||||
|
||||
/// Sum every element. Calls sum_acc with seed 0.
|
||||
fn sum_list(xs: IntList) -> Int {
|
||||
fn sum_list(xs: own IntList) -> own Int {
|
||||
sum_acc(xs, 0)
|
||||
}
|
||||
|
||||
/// Build a list of length n, sum it, print the sum.
|
||||
fn run_one(n: Int) -> Unit with IO {
|
||||
fn run_one(n: own Int) -> own Unit with IO {
|
||||
print(sum_list(cons_n(n)))
|
||||
}
|
||||
|
||||
fn main() -> Unit with IO {
|
||||
fn main() -> own Unit with IO {
|
||||
run_one(100000);
|
||||
run_one(1000000);
|
||||
run_one(3000000)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
(doc "Tail-recursive: prepend (n-1, n-2, ..., 0) onto acc. Returns owned chain.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (own (con IntList)))
|
||||
(params (own (con Int)) (own (con IntList)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n acc)
|
||||
(body
|
||||
@@ -51,7 +51,7 @@
|
||||
(doc "Build [0..n-1] :: IntList. Returns owned chain; caller owns and consumes.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con IntList)))))
|
||||
(params n)
|
||||
(body (app cons_n_acc n (term-ctor IntList INil))))
|
||||
@@ -60,8 +60,8 @@
|
||||
(doc "Tail-recursive sum. Owns xs; consumes via LCons-arm move-into-tail-call.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con IntList)) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -74,19 +74,19 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con IntList)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body (app sum_acc xs 0)))
|
||||
|
||||
(fn run_one
|
||||
(doc "Build, sum, print. The owned list flows from cons_n into sum_list and is fully consumed.")
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
(app print (app sum_list (app cons_n n)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 100000)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(class Foo
|
||||
(param a)
|
||||
(method foo
|
||||
(type (fn-type (params a) (ret (con Int))))))
|
||||
(type (fn-type (params (own a)) (ret (own (con Int)))))))
|
||||
(instance
|
||||
(class Foo)
|
||||
(type (con Int))
|
||||
@@ -11,13 +11,13 @@
|
||||
(class Looper
|
||||
(param a)
|
||||
(method loop_call
|
||||
(type (fn-type (params a (con Int)) (ret (con Int))))))
|
||||
(type (fn-type (params (own a) (own (con Int))) (ret (own (con Int)))))))
|
||||
(instance
|
||||
(class Looper)
|
||||
(type (con Int))
|
||||
(method loop_call
|
||||
(body (lam (params (typed i a) (typed acc (con Int))) (ret (con Int)) (body (if (app eq i 0) acc (tail-app loop_call (app - i 1) (app + acc (app foo (app + acc i))))))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app loop_call 100000000 0)))))
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
(doc "Balanced binary tree of given depth, every value = 1.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Tree))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Tree)))))
|
||||
(params depth)
|
||||
(body
|
||||
(if (app eq depth 0)
|
||||
@@ -53,8 +53,8 @@
|
||||
(doc "Sum every Node value via match recursion. Constructor-blocked: not tail-recursive, but recursion depth = tree depth so fits.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Tree))
|
||||
(ret (con Int))))
|
||||
(params (own (con Tree)))
|
||||
(ret (own (con Int)))))
|
||||
(params t)
|
||||
(body
|
||||
(match t
|
||||
@@ -64,13 +64,13 @@
|
||||
|
||||
(fn run_one
|
||||
(doc "Build a tree of given depth, sum it, print the sum.")
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params depth)
|
||||
(body
|
||||
(app print (app sum_tree (app build_tree depth)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app run_one 16)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module bool_to_str_drop_rc
|
||||
(fn main
|
||||
(doc "Iter 24.1: pin that `bool_to_str` participates in RC discipline. Bind the heap-Str result to `s`, consume `s` once in `io/print_str`, let the binder drop at scope close. Under --alloc=rc with AILANG_RC_STATS=1 the atexit summary must report allocs == 1 && frees == 1 && live == 0 — the heap-Str slab allocated by str_alloc inside ailang_bool_to_str rides the same rc_header + ailang_rc_dec path as int_to_str.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (let s (app bool_to_str true) (seq (do io/print_str s) (do io/print_str "\n"))))))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module bool_to_str_smoke_false
|
||||
(fn main
|
||||
(doc "Iter 24.1: stdout-smoke for the false branch of bool_to_str. Stdout must be `false\\n` (puts adds the newline). Companion of bool_to_str_drop_rc.ail.json (which covers the true branch and the RC-stats invariant).")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (let s (app bool_to_str false) (seq (do io/print_str s) (do io/print_str "\n"))))))
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (borrow (con List)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(match xs
|
||||
@@ -41,7 +41,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con List)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(match xs
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
(fn main
|
||||
(doc "Build [1,2,3]; print list_length (3) then sum_list (6).")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let xs
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
(module borrow_value_reject
|
||||
|
||||
(fn ignore
|
||||
(doc "MUST FAIL post-cutover: borrow over a value type is meaningless.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (borrow (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params n)
|
||||
(body 0)))
|
||||
+3
-3
@@ -14,8 +14,8 @@
|
||||
(type
|
||||
(forall (vars a)
|
||||
(fn-type
|
||||
(params (con Box a))
|
||||
(ret a))))
|
||||
(params (own (con Box a)))
|
||||
(ret (own a)))))
|
||||
(params b)
|
||||
(body
|
||||
(match b
|
||||
@@ -27,7 +27,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params)
|
||||
(ret (con Unit))
|
||||
(ret (own (con Unit)))
|
||||
(effects IO)))
|
||||
(params)
|
||||
(body
|
||||
|
||||
@@ -9,12 +9,20 @@
|
||||
"type": {
|
||||
"k": "fn",
|
||||
"params": [],
|
||||
"ret": { "k": "con", "name": "Int" },
|
||||
"param_modes": [],
|
||||
"ret": {
|
||||
"k": "con",
|
||||
"name": "Int"
|
||||
},
|
||||
"ret_mode": "own",
|
||||
"effects": []
|
||||
},
|
||||
"params": [],
|
||||
"doc": "Referenziert eine nicht-existente Variable -> unbound-var.",
|
||||
"body": { "t": "var", "name": "does_not_exist" }
|
||||
"body": {
|
||||
"t": "var",
|
||||
"name": "does_not_exist"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
(class Describe
|
||||
(param a)
|
||||
(method describe
|
||||
(type (fn-type (params (borrow a)) (ret (con Str))))))
|
||||
(type (fn-type (params (borrow a)) (ret (own (con Str)))))))
|
||||
(instance
|
||||
(class Describe)
|
||||
(type (con Int))
|
||||
@@ -13,6 +13,6 @@
|
||||
(ret (con Str))
|
||||
(body (app format_label "n=" (app int_to_str n)))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (do io/print_str (app describe 5)))))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(module classify_pin
|
||||
(fn bump (type (fn-type (params (con Int)) (ret (con Int)))) (params n)
|
||||
(fn bump (type (fn-type (params (own (con Int))) (ret (own (con Int))))) (params n)
|
||||
(body (app + n 1)))
|
||||
(fn main (type (fn-type (params) (ret (con Int)))) (params)
|
||||
(fn main (type (fn-type (params) (ret (own (con Int))))) (params)
|
||||
(body (app bump 41))))
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
(fn main
|
||||
(doc "Use `(clone x)` on a let-bound Int; print it.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let x 42
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
(module closure
|
||||
(fn apply
|
||||
(doc "apply a fn-of-Int to an Int")
|
||||
(type (fn-type (params (fn-type (params (con Int)) (ret (con Int))) (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (fn-type (params (own (con Int))) (ret (own (con Int))))) (own (con Int))) (ret (own (con Int)))))
|
||||
(params f x)
|
||||
(body (app f x)))
|
||||
(fn main
|
||||
(doc "captures `n` from the enclosing let, returns 42")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (let n 3 (app print (app apply (lam (params (typed x (con Int))) (ret (con Int)) (body (app + x n))) 39))))))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
(module cmp_max_smoke
|
||||
(fn cmp_max
|
||||
(type (forall (vars a) (constraints (constraint prelude.Ord a)) (fn-type (params a a) (ret a))))
|
||||
(type (forall (vars a) (constraints (constraint prelude.Ord a)) (fn-type (params (own a) (own a)) (ret (own a)))))
|
||||
(params x y)
|
||||
(body (match (app compare x y)
|
||||
(case (pat-ctor LT) y)
|
||||
(case _ x))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app cmp_max 3 7)))))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(module compare_float_noinstance
|
||||
(fn cmp
|
||||
(type (fn-type (params) (ret (con Ordering))))
|
||||
(type (fn-type (params) (ret (own (con Ordering)))))
|
||||
(params)
|
||||
(body (app compare 1.0 2.0))))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module compare_primitives_smoke
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (seq (seq (app print (match (app compare 1 2)
|
||||
(case (pat-ctor LT) 1)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
(fn signum
|
||||
(doc "Map an Int to -1/0/+1 via prelude.compare. Returns the sign as an Int.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(match (app compare n 0)
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
(fn drain
|
||||
(doc "Print signum of every element of xs, in list order.")
|
||||
(type (fn-type (params (con IntList)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con IntList))) (ret (own (con Unit))) (effects IO)))
|
||||
(params xs)
|
||||
(body
|
||||
(match xs
|
||||
@@ -43,7 +43,7 @@
|
||||
(tail-app drain t))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app drain
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
(doc "Identity over Maybe<Int>; signature uses bare `Maybe` with no import.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Maybe (con Int)))
|
||||
(ret (con Maybe (con Int)))))
|
||||
(params (own (con Maybe (con Int))))
|
||||
(ret (own (con Maybe (con Int))))))
|
||||
(params m)
|
||||
(body m))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app classify (term-ctor Maybe Just 7)))))
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
(doc "Identity at mystery.Widget — but `mystery` is not a workspace module.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con mystery.Widget))
|
||||
(ret (con mystery.Widget))))
|
||||
(params (own (con mystery.Widget)))
|
||||
(ret (own (con mystery.Widget)))))
|
||||
(params w)
|
||||
(body w))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (do io/print_str "unreachable"))))
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
(doc "Identity at std_maybe.Widget — `std_maybe` is real, but `Widget` is not in it.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con std_maybe.Widget))
|
||||
(ret (con std_maybe.Widget))))
|
||||
(params (own (con std_maybe.Widget)))
|
||||
(ret (own (con std_maybe.Widget)))))
|
||||
(params w)
|
||||
(body w))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (do io/print_str "unreachable"))))
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
(class MyC
|
||||
(param a)
|
||||
(method op
|
||||
(type (fn-type (params a) (ret (con Int)))))))
|
||||
(type (fn-type (params (own a)) (ret (own (con Int))))))))
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
; RED-pin fixture for leg (C) of the drop-soundness bug family the
|
||||
; Implicit-cutover (#55) surfaced: a polymorphic ctor's drop fn
|
||||
; rc_dec's a type-parameter field even when that field is
|
||||
; monomorphised at a value type (Int).
|
||||
;
|
||||
; `Box a` is the minimal single-field box. `unbox` takes the box by
|
||||
; `own` and matches it, extracting the inner value `x` and returning
|
||||
; it. The match consumes the box husk, so codegen emits the
|
||||
; scope-close drop `drop_drop_value_field_no_segfault_pin_Box(box)`.
|
||||
; That drop fn is emitted ONCE from the polymorphic declaration; the
|
||||
; field type is the type-var `a`, which `llvm_type` cannot lower, so
|
||||
; drop.rs's `.unwrap_or_else(|_| "ptr")` treats it as a boxed pointer
|
||||
; and emits `ailang_rc_dec` on it.
|
||||
;
|
||||
; At the `Box Int` monomorph the field holds the raw i64 `7` stored
|
||||
; inline (offset 8), NOT a heap pointer. `ailang_rc_dec(7)`
|
||||
; dereferences address 7 -> SIGSEGV. Expected post-fix: prints `7`,
|
||||
; exits 0, AILANG_RC_STATS reports `allocs == frees && live == 0`
|
||||
; (the one Box slab is freed exactly once; no spurious dec of the
|
||||
; inline value field).
|
||||
|
||||
(module drop_value_field_no_segfault_pin
|
||||
|
||||
(data Box (vars a)
|
||||
(doc "Single-field polymorphic box.")
|
||||
(ctor MkBox a))
|
||||
|
||||
(fn unbox
|
||||
(doc "Consume the box by own, return its inner value. The match drops the box husk.")
|
||||
(type
|
||||
(forall (vars a)
|
||||
(fn-type
|
||||
(params (own (con Box a)))
|
||||
(ret (own a)))))
|
||||
(params b)
|
||||
(body
|
||||
(match b
|
||||
(case (pat-ctor MkBox x) x))))
|
||||
|
||||
(fn main
|
||||
(doc "Build MkBox 7 at Int, unbox it (drops the Box husk), print the result.")
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app unbox (term-ctor Box MkBox 7))))))
|
||||
@@ -4,8 +4,8 @@
|
||||
(export "backtest_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params state sample)
|
||||
(body
|
||||
(app + state (app * sample sample))))
|
||||
@@ -13,8 +13,8 @@
|
||||
(fn helper
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params x)
|
||||
(body
|
||||
(app * x x))))
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
(export "backtest_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con State)) (con Float))
|
||||
(ret (con State))))
|
||||
(params (own (con State)) (own (con Float)))
|
||||
(ret (own (con State)))))
|
||||
(params st sample)
|
||||
(body
|
||||
(match st
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
(export "backtest_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (borrow (con State)) (con Float))
|
||||
(ret (con State))))
|
||||
(params (borrow (con State)) (own (con Float)))
|
||||
(ret (own (con State)))))
|
||||
(params st sample)
|
||||
(body
|
||||
(match st
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con State)) (own (con Tick)))
|
||||
(ret (con State))))
|
||||
(ret (own (con State)))))
|
||||
(params st tick)
|
||||
(body
|
||||
(match st
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con State)) (borrow (con Tick)))
|
||||
(ret (con State))))
|
||||
(ret (own (con State)))))
|
||||
(params st tick)
|
||||
(body
|
||||
(match st
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
(export "f")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Reading))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Reading)))))
|
||||
(params n)
|
||||
(body (term-ctor Reading Sample n "tick"))))
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
(export "log_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Str))
|
||||
(ret (con Int))
|
||||
(params (own (con Int)) (own (con Str)))
|
||||
(ret (own (con Int)))
|
||||
(effects IO)))
|
||||
(params state label)
|
||||
(body
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
(export "embed_scale")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Float) (con Float))
|
||||
(ret (con Float))))
|
||||
(params (own (con Float)) (own (con Float)))
|
||||
(ret (own (con Float)))))
|
||||
(params a b)
|
||||
(body
|
||||
(app * a b))))
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
(export "f")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Int)))
|
||||
(effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
(ctor Boxed (con Int) (con List)))
|
||||
(fn f
|
||||
(export "f")
|
||||
(type (fn-type (params (con Int)) (ret (con Boxed))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Boxed)))))
|
||||
(params n)
|
||||
(body (term-ctor Boxed Boxed n (term-ctor List Nil)))))
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
(ctor R (con Float)))
|
||||
(fn f
|
||||
(export "f")
|
||||
(type (fn-type (params (con Int)) (ret (con Either2))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Either2)))))
|
||||
(params n)
|
||||
(body (term-ctor Either2 L n))))
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
(export "step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con State)) (con Float))
|
||||
(ret (con State))))
|
||||
(params (own (con State)) (own (con Float)))
|
||||
(ret (own (con State)))))
|
||||
(params st sample)
|
||||
(body
|
||||
(match st
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
(ctor Tagged (con Int) (con Str)))
|
||||
(fn f
|
||||
(export "f")
|
||||
(type (fn-type (params (con Int)) (ret (con Tagged))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Tagged)))))
|
||||
(params n)
|
||||
(body (term-ctor Tagged Tagged n "x"))))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(export "f")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Str))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Str)))
|
||||
(ret (own (con Int)))))
|
||||
(params n label)
|
||||
(body n)))
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
(fn helper
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params x)
|
||||
(body
|
||||
(app * x x))))
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
(fn mk
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Pt))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Pt)))))
|
||||
(params a b)
|
||||
(body (term-ctor Pt Pt a b)))
|
||||
|
||||
(fn sum_pt
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con Pt)))
|
||||
(ret (con Int))))
|
||||
(params (borrow (con Pt)))
|
||||
(ret (own (con Int)))))
|
||||
(params p)
|
||||
(body
|
||||
(match p
|
||||
@@ -23,7 +23,7 @@
|
||||
(app + x y)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let s (app int_to_str (app sum_pt (app mk 3 4)))
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
(fn classify_str
|
||||
(doc "Lit-pattern over Str; exercises build_eq's class-dispatch lowering for non-Int.")
|
||||
(type (fn-type (params (con Str)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Str))) (ret (own (con Int)))))
|
||||
(params s)
|
||||
(body
|
||||
(match s
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
(fn main
|
||||
(doc "Drive eq at Int/Bool/Str/Unit; then drive classify_str.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (seq (app print (app eq 5 5)) (do io/print_str "\n"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(module eq_float_must_fail
|
||||
(fn main
|
||||
(doc "Klausel-3 discriminator. After operator-routing-eq-ord, `(app eq 1.5 1.5)` must fire `NoInstance Eq Float` with a follow-up sentence naming `float_eq` as the explicit IEEE-aware alternative. Today the diagnostic already fires (no Eq Float instance) but does not name `float_eq` — the milestone adds that hint.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app eq 1.5 1.5)))))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(module eq_float_noinstance
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (if (app eq 1.0 2.0) 1 0)))))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(module eq_ord_polymorphic
|
||||
(fn at_most
|
||||
(doc "Composition of prelude `gt` with `not` — semantically equivalent to `le`. Used to exercise polymorphic-helper-over-prelude-fns composition through the unified mono pass.")
|
||||
(type (forall (vars a) (constraints (constraint prelude.Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
||||
(type (forall (vars a) (constraints (constraint prelude.Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (own (con Bool))))))
|
||||
(params x y)
|
||||
(body (app not (app gt x y))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (seq (seq (app print (if (app at_most 3 5) 1 0)) (do io/print_str "\n")) (seq (seq (app print (if (app at_most true false) 1 0)) (do io/print_str "\n")) (seq (app print (if (app at_most "abc" "abd") 1 0)) (do io/print_str "\n")))))))
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
(case (pat-ctor MkIntBox ai) (match b
|
||||
(case (pat-ctor MkIntBox bi) (app compare ai bi))))))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (seq (seq (app print (if (app eq (term-ctor IntBox MkIntBox 3) (term-ctor IntBox MkIntBox 3)) 1 0)) (do io/print_str "\n")) (seq (app print (if (app eq (term-ctor IntBox MkIntBox 3) (term-ctor IntBox MkIntBox 5)) 1 0)) (do io/print_str "\n"))))))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
(module eq_primitives_smoke
|
||||
(fn to_int
|
||||
(doc "1 if the bool is true, 0 otherwise. Used to render Eq results as printable Ints.")
|
||||
(type (fn-type (params (con Bool)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Bool))) (ret (own (con Int)))))
|
||||
(params b)
|
||||
(body (if b 1 0)))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (seq (seq (app print (app to_int (app eq 7 7))) (do io/print_str "\n")) (seq (seq (app print (app to_int (app eq 7 8))) (do io/print_str "\n")) (seq (seq (app print (app to_int (app eq true true))) (do io/print_str "\n")) (seq (seq (app print (app to_int (app eq true false))) (do io/print_str "\n")) (seq (seq (app print (app to_int (app eq "hello" "hello"))) (do io/print_str "\n")) (seq (app print (app to_int (app eq "hello" "world"))) (do io/print_str "\n"))))))))))
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
(case (pat-ctor Point a2 b2)
|
||||
(if (app eq a1 a2) (app eq b1 b2) false))))))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let p1 (term-ctor Point Point 1 2)
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
(fn peek
|
||||
(doc "Build a Box(n), discard the payload, return 42. The Box is non-escaping.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(let b (term-ctor Box MkBox n)
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
(fn count
|
||||
(doc "Recurse n times; each call builds a temporary Box, discards its payload via _, and returns 0 if n<=0, else 1 + count(n-1).")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(if (app le n 0)
|
||||
@@ -48,7 +48,7 @@
|
||||
(case (pat-ctor MkBox _) (app + 1 (app count (app - n 1)))))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (seq (app print (app peek 0)) (do io/print_str "\n"))
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
(export "ema_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params state sample)
|
||||
(body
|
||||
(app + state
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
(export "leaky_step")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Float) (con Float))
|
||||
(ret (con Float))))
|
||||
(params (own (con Float)) (own (con Float)))
|
||||
(ret (own (con Float)))))
|
||||
(params state sample)
|
||||
(body
|
||||
(app + (app * state 0.5) sample))))
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
(type
|
||||
(fn-type
|
||||
(params (own (con IntList)))
|
||||
(ret (con Int))))
|
||||
(ret (own (con Int)))))
|
||||
(params xs)
|
||||
(body
|
||||
(match xs
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
(export "tick")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Int)))
|
||||
(effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
(doc "Return the FizzBuzz label for n, or the empty string if n is a plain number.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Str))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Str)))))
|
||||
(params n)
|
||||
(body
|
||||
(if (app eq (app % n 15) 0)
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
(fn emit_one
|
||||
(doc "Print the FizzBuzz label or the number itself.")
|
||||
(type (fn-type (params (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params n)
|
||||
(body
|
||||
(let label (app classify n)
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
(fn loop
|
||||
(doc "Tail-recursive driver over [i..stop].")
|
||||
(type (fn-type (params (con Int) (con Int)) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params (own (con Int)) (own (con Int))) (ret (own (con Unit))) (effects IO)))
|
||||
(params i stop)
|
||||
(body
|
||||
(if (app gt i stop)
|
||||
@@ -68,6 +68,6 @@
|
||||
(tail-app loop (app + i 1) stop)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app loop 1 15))))
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
(app eq (app * a d) (app * b c)))))))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let r_1_2 (term-ctor Rational MkRational 1 2)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
(fn fabs
|
||||
(doc "Float absolute value via the named-fn comparison surface.")
|
||||
(type (fn-type (params (con Float)) (ret (con Float))))
|
||||
(type (fn-type (params (own (con Float))) (ret (own (con Float)))))
|
||||
(params x)
|
||||
(body
|
||||
(if (app float_lt x 0.0)
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
(fn iterate
|
||||
(doc "Tail-recursive Newton iteration. Stops when |xnew - x| < tol.")
|
||||
(type (fn-type (params (con Float) (con Float) (con Float)) (ret (con Float))))
|
||||
(type (fn-type (params (own (con Float)) (own (con Float)) (own (con Float))) (ret (own (con Float)))))
|
||||
(params n x tol)
|
||||
(body
|
||||
(let xnew (app / (app + x (app / n x)) 2.0)
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
(fn sqrt
|
||||
(doc "sqrt n via Newton with initial guess 1.0 and tolerance 1e-10. Returns 0.0 for n == 0.0; assumes n >= 0.")
|
||||
(type (fn-type (params (con Float)) (ret (con Float))))
|
||||
(type (fn-type (params (own (con Float))) (ret (own (con Float)))))
|
||||
(params n)
|
||||
(body
|
||||
(if (app float_eq n 0.0)
|
||||
@@ -52,7 +52,7 @@
|
||||
(app iterate n 1.0 0.0000000001))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app print (app sqrt 4.0))
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
|
||||
(module eqord_4_float_ord_must_fail
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (if (app lt 1.5 2.5) 1 0)))))
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
|
||||
(module eqord_5_float_eq_must_fail
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (if (app eq 1.5 1.5) 1 0)))))
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
(doc "Recurse k times applying x' = 0.5 * (x + n/x).")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Float) (con Float) (con Int))
|
||||
(ret (con Float))))
|
||||
(params (own (con Float)) (own (con Float)) (own (con Int)))
|
||||
(ret (own (con Float)))))
|
||||
(params n x k)
|
||||
(body
|
||||
(if (app eq k 0)
|
||||
@@ -27,12 +27,12 @@
|
||||
|
||||
(fn sqrt
|
||||
(doc "20-step Newton iteration starting from x0 = n.")
|
||||
(type (fn-type (params (con Float)) (ret (con Float))))
|
||||
(type (fn-type (params (own (con Float))) (ret (own (con Float)))))
|
||||
(params n)
|
||||
(body (app newton_iter n n 20)))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (app sqrt 2.0)))))
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
(doc "Tail-recursive sum with accumulator.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (borrow (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -35,8 +35,8 @@
|
||||
(doc "Tail-recursive length with accumulator.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con IntList) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (borrow (con IntList)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params xs acc)
|
||||
(body
|
||||
(match xs
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
(fn mean
|
||||
(doc "Mean as Float = sum / count, both promoted via int_to_float.")
|
||||
(type (fn-type (params (con IntList)) (ret (con Float))))
|
||||
(type (fn-type (params (borrow (con IntList))) (ret (own (con Float)))))
|
||||
(params xs)
|
||||
(body
|
||||
(app /
|
||||
@@ -54,7 +54,7 @@
|
||||
(app int_to_float (app count_acc xs 0)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
(fn classify
|
||||
(doc "-1=NaN, 0=infinite, 1=finite. Uses is_nan + abs > huge.")
|
||||
(type (fn-type (params (con Float)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Float))) (ret (own (con Int)))))
|
||||
(params x)
|
||||
(body
|
||||
(if (app is_nan x)
|
||||
@@ -44,7 +44,7 @@
|
||||
1)))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app print (app / 6.0 3.0))
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
(module floats_4_float_to_str_reach
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(do io/print_str (app float_to_str 3.14)))))
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
(doc "Tail-recursive factorial accumulator: fact_acc(n, acc) = n!*acc.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int) (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)) (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params n acc)
|
||||
(body
|
||||
(if (app eq n 0)
|
||||
@@ -16,13 +16,13 @@
|
||||
(doc "Factorial of a non-negative Int.")
|
||||
(type
|
||||
(fn-type
|
||||
(params (con Int))
|
||||
(ret (con Int))))
|
||||
(params (own (con Int)))
|
||||
(ret (own (con Int)))))
|
||||
(params n)
|
||||
(body (app fact_acc n 1)))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
(case (pat-ctor Blue) "Blue")))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
(doc "A user-defined typeclass: produce a short Str describing a value.")
|
||||
(param a)
|
||||
(method describe
|
||||
(type (fn-type (params (borrow a)) (ret (con Str))))))
|
||||
(type (fn-type (params (borrow a)) (ret (own (con Str)))))))
|
||||
|
||||
(data Shape
|
||||
(ctor Circle (con Int))
|
||||
@@ -42,13 +42,13 @@
|
||||
(constraints (constraint Describe a))
|
||||
(fn-type
|
||||
(params (borrow a))
|
||||
(ret (con Unit))
|
||||
(ret (own (con Unit)))
|
||||
(effects IO))))
|
||||
(params x)
|
||||
(body (do io/print_str (app describe x))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
(fn square
|
||||
(doc "Multiply an Int by itself.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params x)
|
||||
(body (app * x x)))
|
||||
|
||||
(fn cube
|
||||
(doc "Raise an Int to the third power.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params x)
|
||||
(body (app * x (app square x))))
|
||||
|
||||
(fn abs_int
|
||||
(doc "Absolute value of an Int.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params x)
|
||||
(body
|
||||
(if (app lt x 0)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(import forma_4_intmath_lib)
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
(fn add
|
||||
(doc "Plain Int addition. Used as the (b, a) -> b arg to List.fold_left.")
|
||||
(type (fn-type (params (con Int) (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int)) (own (con Int))) (ret (own (con Int)))))
|
||||
(params acc x)
|
||||
(body (app + acc x)))
|
||||
|
||||
(fn main
|
||||
(doc "Build a List<Int> of [1,2,3,4,5], print its length (5), then its sum (15).")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let xs
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
|
||||
(fn new
|
||||
(doc "Build a Counter initialised to the given value.")
|
||||
(type (fn-type (params (con Int)) (ret (con Counter))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Counter)))))
|
||||
(params n)
|
||||
(body (term-ctor Counter MkCounter n)))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let c (new Counter 42)
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
(ctor MkCounter (con Int)))
|
||||
|
||||
(fn value
|
||||
(type (fn-type (params (con Counter)) (ret (con Int))))
|
||||
(type (fn-type (params (borrow (con Counter))) (ret (own (con Int)))))
|
||||
(params c)
|
||||
(body (match c (case (pat-ctor MkCounter x) x))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let c (term-ctor Counter MkCounter 41)
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
(fn unwrap
|
||||
(doc "Project the contained Int out of a NumBox<Int>.")
|
||||
(type (fn-type (params (con NumBox (con Int))) (ret (con Int))))
|
||||
(type (fn-type (params (own (con NumBox (con Int)))) (ret (own (con Int)))))
|
||||
(params b)
|
||||
(body (match b (case (pat-ctor MkNumBox x) x))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let b (term-ctor NumBox MkNumBox 17)
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
|
||||
(fn unwrap_str
|
||||
(doc "BAD: NumBox is restricted to {Int, Float}, but we ask for Str. Expected: ParamNotInRestrictedSet on the type signature.")
|
||||
(type (fn-type (params (con NumBox (con Str))) (ret (con Str))))
|
||||
(type (fn-type (params (own (con NumBox (con Str)))) (ret (own (con Str)))))
|
||||
(params b)
|
||||
(body (match b (case (pat-ctor MkNumBox x) x))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (do io/print_str ""))))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(module loop_recur_1_isqrt_newton
|
||||
(fn main
|
||||
(doc "Integer square root of 152399025 (= 12345^2) via Newton's method, then a sanity-difference. Expected stdout: 12345 then 0.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let r (app isqrt 152399025)
|
||||
@@ -9,7 +9,7 @@
|
||||
(app print (app - r 12345))))))
|
||||
(fn isqrt
|
||||
(doc "Newton's method for floor(sqrt(n)). Two binders: x (current guess) and prev (previous guess, to detect the fixpoint/2-cycle). The recur is buried inside a nested if, not at body toplevel.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(if (app lt n 2)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(module loop_recur_2_collatz
|
||||
(fn main
|
||||
(doc "Collatz step counts. collatz_len(27)=111, collatz_len(97)=118, collatz_len(1)=0. Expected stdout (per line): 111, 118, 0.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(seq (app print (app collatz_len 27))
|
||||
@@ -9,7 +9,7 @@
|
||||
(app print (app collatz_len 1))))))
|
||||
(fn collatz_len
|
||||
(doc "Number of Collatz steps to reach 1. Two binders: n (current value) and steps (accumulator). Parity dispatch is a `match` on n%2; the recur lives in the tail of each match arm, not at body toplevel.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params start)
|
||||
(body
|
||||
(loop (n (con Int) start) (steps (con Int) 0)
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
; Expected: `ail check` exits 1 with code recur-outside-loop.
|
||||
(module loop_recur_3a_recur_outside_loop
|
||||
(fn countdown
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(if (app eq n 0)
|
||||
0
|
||||
(recur (app - n 1)))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app countdown 5)))))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
; Expected: `ail check` exits 1 with code recur-arity-mismatch.
|
||||
(module loop_recur_3b_recur_arity
|
||||
(fn sum_to
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(loop (acc (con Int) 0) (i (con Int) 1)
|
||||
@@ -12,6 +12,6 @@
|
||||
acc
|
||||
(recur (app + acc i))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app sum_to 10)))))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
; Expected: `ail check` exits 1 with code recur-type-mismatch.
|
||||
(module loop_recur_3c_recur_type
|
||||
(fn count_down
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params start)
|
||||
(body
|
||||
(loop (i (con Int) start)
|
||||
@@ -12,6 +12,6 @@
|
||||
i
|
||||
(recur (app gt i 0))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app count_down 5)))))
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
; Expected: `ail check` exits 1 with code recur-not-in-tail-position.
|
||||
(module loop_recur_3d_recur_not_tail
|
||||
(fn factorial
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(loop (i (con Int) n)
|
||||
@@ -13,6 +13,6 @@
|
||||
1
|
||||
(app * i (recur (app - i 1)))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app factorial 5)))))
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
; Expected: `ail check` exits 1 with code loop-binder-captured-by-lambda.
|
||||
(module loop_recur_3e_binder_captured
|
||||
(fn apply_int
|
||||
(type (fn-type (params (fn-type (params (con Int)) (ret (con Int))) (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (fn-type (params (own (con Int))) (ret (own (con Int))))) (own (con Int))) (ret (own (con Int)))))
|
||||
(params f x)
|
||||
(body (app f x)))
|
||||
(fn sum_to
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params n)
|
||||
(body
|
||||
(loop (acc (con Int) 0) (i (con Int) 1)
|
||||
@@ -18,6 +18,6 @@
|
||||
(recur (app apply_int (lam (params (typed d (con Int))) (ret (con Int)) (body (app + acc d))) i)
|
||||
(app + i 1))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app sum_to 10)))))
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
(module loop_recur_4_gcd_value_pos
|
||||
(fn gcd
|
||||
(doc "Euclidean gcd via loop/recur. Two binders a,b; recur in the tail of the else branch.")
|
||||
(type (fn-type (params (con Int) (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int)) (own (con Int))) (ret (own (con Int)))))
|
||||
(params x y)
|
||||
(body
|
||||
(loop (a (con Int) x) (b (con Int) y)
|
||||
@@ -18,7 +18,7 @@
|
||||
a
|
||||
(recur b (app % a b))))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (app + (app gcd 48 18) (app gcd 1071 462))))))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
(module loop_recur_5_event_loop_noterm
|
||||
(fn run_forever
|
||||
(doc "Infinite event loop. Two binders: tick counter and a running parity flag. No branch ever exits via a non-recur term.")
|
||||
(type (fn-type (params) (ret (con Int))))
|
||||
(type (fn-type (params) (ret (own (con Int)))))
|
||||
(params)
|
||||
(body
|
||||
(loop (tick (con Int) 0) (parity (con Int) 0)
|
||||
@@ -14,6 +14,6 @@
|
||||
(recur (app + tick 1) 1)
|
||||
(recur (app + tick 1) 0)))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app run_forever)))))
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
(module loop_recur_5b_event_loop_noterm
|
||||
(fn run_forever
|
||||
(doc "Infinite event loop. Two binders: tick counter and a running parity flag. No branch ever exits via a non-recur term.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params start)
|
||||
(body
|
||||
(loop (tick (con Int) start) (parity (con Int) 0)
|
||||
@@ -16,6 +16,6 @@
|
||||
(recur (app + tick 1) 1)
|
||||
(recur (app + tick 1) 0)))))
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body (app print (app run_forever 0)))))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
(module mut-local_1_factorial
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (let prod 1 (let prod (app * prod 1) (let prod (app * prod 2) (let prod (app * prod 3) (let prod (app * prod 4) (let prod (app * prod 5) prod))))))))))
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
(fn classify
|
||||
(doc "Return category code 0..3 for temperature t in degrees C.")
|
||||
(type (fn-type (params (con Int)) (ret (con Int))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Int)))))
|
||||
(params t)
|
||||
(body (let code 0 (let code (if (app lt t 0) 0 (if (app lt t 15) 1 (if (app lt t 28) 2 3))) code))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (app classify 22)))))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
(module mut-local_3_horner
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (let acc 2.0 (let acc (app - (app * acc 2.5) 3.0) (let acc (app + (app * acc 2.5) 5.0) (let acc (app - (app * acc 2.5) 7.0) acc))))))))
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
(module mut-local_4_has_small_factor
|
||||
|
||||
(fn has_small_factor
|
||||
(type (fn-type (params (con Int)) (ret (con Bool))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Bool)))))
|
||||
(params n)
|
||||
(body (let found false (let found (if (app eq (app % n 2) 0) true found) (let found (if (app eq (app % n 3) 0) true found) (let found (if (app eq (app % n 5) 0) true found) (let found (if (app eq (app % n 7) 0) true found) found)))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(app print (app has_small_factor 91)))))
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
(fn fill
|
||||
(doc "Fill slots 0..n of buf with (i*i + 1). Linear: own in, own out.")
|
||||
(type (fn-type (params (own (con RawBuf (con Int))) (con Int)) (ret (own (con RawBuf (con Int))))))
|
||||
(type (fn-type (params (own (con RawBuf (con Int))) (own (con Int))) (ret (own (con RawBuf (con Int))))))
|
||||
(params buf n)
|
||||
(body
|
||||
(loop (b (con RawBuf (con Int)) buf) (i (con Int) 0)
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
(fn total
|
||||
(doc "Sum every slot of buf, driving the bound off RawBuf.size.")
|
||||
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (con Int))))
|
||||
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (own (con Int)))))
|
||||
(params buf)
|
||||
(body
|
||||
(loop (acc (con Int) 0) (i (con Int) 0)
|
||||
@@ -49,7 +49,7 @@
|
||||
(app + i 1))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let buf (new RawBuf (con Int) 5)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
(module rawbuf_2_running_max
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let buf (new RawBuf (con Int) 4)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
(module rawbuf_3_sensor_pair
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let readings (new RawBuf (con Float) 3)
|
||||
|
||||
@@ -30,6 +30,6 @@
|
||||
|
||||
(fn first_price
|
||||
(doc "Read the first Tick out of a batch buffer. Should never check: RawBuf cannot hold a user ADT.")
|
||||
(type (fn-type (params (borrow (con RawBuf (con Tick)))) (ret (con Tick))))
|
||||
(type (fn-type (params (borrow (con RawBuf (con Tick)))) (ret (own (con Tick)))))
|
||||
(params batch)
|
||||
(body (app RawBuf.get batch 0))))
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
(fn build_window
|
||||
(doc "Allocate a 4-slot Float buffer, fill slot i with (2*(i+1)), wrap in a Window with count=4.")
|
||||
(type (fn-type (params (con Int)) (ret (own (con Window)))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con Window)))))
|
||||
(params n)
|
||||
(body
|
||||
(let buf (new RawBuf (con Float) 4)
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
(fn mean
|
||||
(doc "Average of the first count slots, read through a borrow of the Window.")
|
||||
(type (fn-type (params (borrow (con Window))) (ret (con Float))))
|
||||
(type (fn-type (params (borrow (con Window))) (ret (own (con Float)))))
|
||||
(params w)
|
||||
(body
|
||||
(match w
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
(fn wmax
|
||||
(doc "Maximum of the first count slots, read through a borrow of the Window.")
|
||||
(type (fn-type (params (borrow (con Window))) (ret (con Float))))
|
||||
(type (fn-type (params (borrow (con Window))) (ret (own (con Float)))))
|
||||
(params w)
|
||||
(body
|
||||
(match w
|
||||
@@ -84,7 +84,7 @@
|
||||
(app + i 1))))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let w (app build_window 4)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
(fn mark_even
|
||||
(doc "Set slot i to (i is even) for i in 0..n. Linear own->own.")
|
||||
(type (fn-type (params (own (con RawBuf (con Bool))) (con Int)) (ret (own (con RawBuf (con Bool))))))
|
||||
(type (fn-type (params (own (con RawBuf (con Bool))) (own (con Int))) (ret (own (con RawBuf (con Bool))))))
|
||||
(params buf n)
|
||||
(body
|
||||
(loop (b (con RawBuf (con Bool)) buf) (i (con Int) 0)
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
(fn count_set
|
||||
(doc "Count the set flags, reading the Bool buffer through a borrow.")
|
||||
(type (fn-type (params (borrow (con RawBuf (con Bool)))) (ret (con Int))))
|
||||
(type (fn-type (params (borrow (con RawBuf (con Bool)))) (ret (own (con Int)))))
|
||||
(params buf)
|
||||
(body
|
||||
(loop (acc (con Int) 0) (i (con Int) 0)
|
||||
@@ -49,7 +49,7 @@
|
||||
(app + i 1))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let buf (new RawBuf (con Bool) 6)
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
(fn make_presence
|
||||
(doc "Try to allocate a RawBuf of Unit — forbidden element type.")
|
||||
(type (fn-type (params (con Int)) (ret (own (con RawBuf (con Unit))))))
|
||||
(type (fn-type (params (own (con Int))) (ret (own (con RawBuf (con Unit))))))
|
||||
(params n)
|
||||
(body (new RawBuf (con Unit) n)))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let buf (app make_presence 3)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
(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))))))
|
||||
(type (fn-type (params (own (con RawBuf (con Int))) (own (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,
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
(fn total
|
||||
(doc "Sum every slot, borrow receiver.")
|
||||
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (con Int))))
|
||||
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (own (con Int)))))
|
||||
(params buf)
|
||||
(body
|
||||
(loop (acc (con Int) 0) (i (con Int) 0)
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
(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))))
|
||||
(type (fn-type (params (borrow (con RawBuf (con Int)))) (ret (own (con Int)))))
|
||||
(params buf)
|
||||
(body
|
||||
(loop (best_i (con Int) 0) (best_v (con Int) (app RawBuf.get buf 0)) (i (con Int) 0)
|
||||
@@ -67,7 +67,7 @@
|
||||
(recur best_i best_v (app + i 1)))))))
|
||||
|
||||
(fn main
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(type (fn-type (params) (ret (own (con Unit))) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let buf (new RawBuf (con Int) 6)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user