Iter 18c.1: Term::Clone schema (no inc emission yet)
Adds (clone X) as a new Term variant. Form-A:
(let p (expensive_fn x)
(do consume_a (clone p)) ; explicit RC inc — needs 18c.3
(do consume_b p))
Schema floor for the LLM-aware RC design (Decision 10): explicit
clone is the author-visible alternative to implicit sharing. In
18c.1 the variant is purely additive — typechecker treats it as
identity (same type as inner), codegen lowers it to the inner
term's IR with no extra calls. Iter 18c.3 will replace the
codegen identity-arm with a single call:
Term::Clone { value } =>
let v = self.lower_term(value, ...)?;
self.emit("call void @ailang_rc_inc(ptr {v})");
Ok(v)
Match-arm count: ~10 sites across 6 files, all mechanical
structural recursion through `value`. The codegen `lower_term`
arm carries an explicit comment marking the 18c.3 emission seam.
Hash invariant: `(clone X)` uses a new serde tag "clone" that no
pre-18c.1 fixture contains. Every existing fixture's canonical
JSON is bit-identical (git diff examples/ empty).
New fixture examples/clone_demo.{ailx,ail.json}:
(let x 42 (do io/print_int (clone x)))
Stdout 42 under both --alloc=gc and --alloc=rc.
Tail-position propagates through clone (verify_tail_positions
treats `(clone tail-call)` as itself a tail call), per the
identity-of-clone semantics in 18c.1.
Verified:
- cargo build --workspace clean
- cargo test --workspace green: 52 e2e (+1), 14 surface parse
(+2 for clone tests), all other buckets unchanged
- ail render round-trip exact
- clone_demo --alloc=gc → 42; --alloc=rc → 42
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"defs":[{"body":{"body":{"args":[{"t":"clone","value":{"name":"x","t":"var"}}],"op":"io/print_int","t":"do"},"name":"x","t":"let","value":{"lit":{"kind":"int","value":42},"t":"lit"}},"doc":"Use `(clone x)` on a let-bound Int; print it.","kind":"fn","name":"main","params":[],"type":{"effects":["IO"],"k":"fn","params":[],"ret":{"k":"con","name":"Unit"}}}],"imports":[],"name":"clone_demo","schema":"ailang/v0"}
|
||||
@@ -0,0 +1,26 @@
|
||||
; Iter 18c.1 — `(clone X)` schema floor.
|
||||
;
|
||||
; The `clone` form is an additive `Term` variant. In 18c.1 it is
|
||||
; identity for both the typechecker and the codegen — `(clone X)`
|
||||
; has the same type as `X` and lowers to the same SSA reg with no
|
||||
; extra IR. Iter 18c.3 will replace the codegen passthrough with
|
||||
; `call void @ailang_rc_inc(ptr %v)` under `--alloc=rc`; for now
|
||||
; the wrapper's only role is to record author intent.
|
||||
;
|
||||
; This fixture wraps a let-bound `Int` in `(clone x)` at its single
|
||||
; use site. The inner term is a primitive value (Int) so RC inc is
|
||||
; meaningless even in 18c.3 — the point is purely that the schema
|
||||
; round-trips and the binary still produces the expected `42`.
|
||||
;
|
||||
; Expected stdout:
|
||||
; 42
|
||||
|
||||
(module clone_demo
|
||||
|
||||
(fn main
|
||||
(doc "Use `(clone x)` on a let-bound Int; print it.")
|
||||
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
||||
(params)
|
||||
(body
|
||||
(let x 42
|
||||
(do io/print_int (clone x))))))
|
||||
Reference in New Issue
Block a user