246b5c7455
Ships fn print : forall a. Show a => (a borrow) -> () !IO in the
prelude with explicit-let body \\x -> let s = show x in do
io/print_str s. Three new E2E fixtures + tests verify the full
path:
- show_print_smoke: 4 primitives smoke (print 42 / true / 'hello' /
3.14) — compile, run, expected stdout
- show_user_adt: data IntBox + instance prelude.Show IntBox +
print (MkIntBox 7) — stdout '7'
- show_no_instance: let f : Int -> Int = \\x -> x in do print f —
fires Show-aware NoInstance with DESIGN.md §Prelude(built-in)
classes cross-reference
IR-shape pin in print_mono_body_shape.rs asserts post-mono
print__Int.body is structurally Term::Let → App(show__Int) →
Do(io/print_str). Protects the explicit let-binder for the heap-Str
RC discipline per eob.1 Str carve-out.
Three plan-defects-fixed-inline surfaced during user-ADT E2E,
necessary repairs to make the spec's stated user-ADT trajectory
work end-to-end:
(a) mono.rs (2 sites): MonoTarget::FreeFn::type_args were carrying
bare type-cons references; normalised to canonical
<owner>.<bare> form via workspace_registry.normalize_type_for_lookup
so synthesised cross-module bodies' post-mono walks reach the
registry-keyed instance entries. Symmetric to the existing
class-method-arm normalisation.
(b) codegen/lib.rs (3 sites: resolve_top_level_fn, lower_app
cross-module arm, synth_with_extras Var arm): post-mono
synthesised bodies may carry cross-module references to modules
their source template didn't import (prelude.print__<UserType>
references show_user_adt.show__<UserType> even though prelude
does not import user modules). Fall back to direct
module_user_fns lookup when prefix not in import_map. Both
ends were independently typechecked before mono ran; the
cross-module ref is created by mono not by source.
(c) lib.rs synth FreeFnCall arm: walked Type::Forall.constraints,
substituted rigid vars with fresh metavars, pushed one
ResidualConstraint per declared constraint. Without this,
print f at Int -> Int would silently typecheck and fail with
a confusing 'unknown variable: show' at codegen rather than
fire the right typecheck-time NoInstance diagnostic.
NoInstance Float-aware arm in check/lib.rs:770-779 extended with
a parallel class == 'prelude.Show' branch that cross-references
DESIGN.md §Prelude(built-in) classes verbatim. Negative-fixture
test asserts code 'no-instance' + Show substring + Prelude-(built-in)-
classes substring.
DESIGN.md §Prelude(built-in) classes milestone-24 paragraph flips
fn print from 'ships in 24.3' to 'shipped in iter 24.3' with body
shape + pin file reference. §Float semantics gains a Show-Float
NaN-spelling cross-reference paragraph linking show 1.5 / show nan /
show inf to instance Show Float via float_to_str.
Roadmap P1 'Post-22 Prelude — Show + print rewire' flipped to [x]
with closing summary naming all three shipped iters (24.1 / 24.2 /
24.3). New P2 entry 'Retire io/print_int|bool|float effect-ops +
migrate example corpus to print' inserted at top of P2.
Tests: 556 passed (was 552 + 4 new). bench/cross_lang exit 0;
bench/compile_check + bench/check exit 1 on documented noise-class
metrics per the audit-cma lineage envelope (8th consecutive
audit-grade observation, baseline pristine per conservative-call).
Milestone 24 closes structurally with this iter. Standard audit
pipeline next.
559 lines
16 KiB
JSON
559 lines
16 KiB
JSON
{
|
|
"schema": "ailang/v0",
|
|
"name": "prelude",
|
|
"imports": [],
|
|
"defs": [
|
|
{
|
|
"kind": "type",
|
|
"name": "Ordering",
|
|
"vars": [],
|
|
"doc": "Result of a three-way comparison: LT (less than), EQ (equal), GT (greater than). Ships in milestone 23 as the codomain of Ord.compare.",
|
|
"ctors": [
|
|
{ "name": "LT", "fields": [] },
|
|
{ "name": "EQ", "fields": [] },
|
|
{ "name": "GT", "fields": [] }
|
|
]
|
|
},
|
|
{
|
|
"kind": "class",
|
|
"name": "Eq",
|
|
"param": "a",
|
|
"doc": "Structural equality. Ships in milestone 23 alongside Ord. The primitive `==` operator stays as the surface-level comparator this iter; routing `==` through `Eq.eq` is the declared P2 follow-up (see docs/specs/2026-05-10-23-eq-ord-prelude.md, `Out of scope`).",
|
|
"methods": [
|
|
{
|
|
"name": "eq",
|
|
"type": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Eq",
|
|
"type": { "k": "con", "name": "Int" },
|
|
"doc": "Eq Int. Body lowers to `icmp eq i64` via the existing primitive `==` dispatch in `lower_eq`.",
|
|
"methods": [
|
|
{
|
|
"name": "eq",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Bool" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "==" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Eq",
|
|
"type": { "k": "con", "name": "Bool" },
|
|
"doc": "Eq Bool. Body lowers to `icmp eq i1` via the existing primitive `==` dispatch in `lower_eq`.",
|
|
"methods": [
|
|
{
|
|
"name": "eq",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Bool" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "==" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Eq",
|
|
"type": { "k": "con", "name": "Str" },
|
|
"doc": "Eq Str. The lambda body shape mirrors Int/Bool for round-trip stability, but the codegen intercept in `emit_fn` overrides the body to call `@ail_str_eq` directly — see `try_emit_primitive_instance_body` in `crates/ailang-codegen/src/lib.rs`.",
|
|
"methods": [
|
|
{
|
|
"name": "eq",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Bool" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "==" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "class",
|
|
"name": "Ord",
|
|
"param": "a",
|
|
"superclass": { "class": "Eq", "type": "a" },
|
|
"doc": "Total ordering. Ships in milestone 23 alongside Eq. `compare x y` returns LT, EQ, or GT (the three-ctor Ordering ADT also in the prelude). Decision 11's single-superclass closure requires `instance Eq T` for every `instance Ord T` — the three Ord instances below pair with the three Eq instances shipped in iter 23.2.3.",
|
|
"methods": [
|
|
{
|
|
"name": "compare",
|
|
"type": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Ordering" },
|
|
"effects": []
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Ord",
|
|
"type": { "k": "con", "name": "Int" },
|
|
"doc": "Ord Int. The lambda body shape is a placeholder for round-trip stability; the codegen intercept `try_emit_primitive_instance_body::\"compare__Int\"` emits a three-way `icmp slt` / `icmp eq` branch ladder constructing LT / EQ / GT.",
|
|
"methods": [
|
|
{
|
|
"name": "compare",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Ordering" },
|
|
"body": {
|
|
"t": "ctor",
|
|
"type": "Ordering",
|
|
"ctor": "EQ",
|
|
"args": []
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Ord",
|
|
"type": { "k": "con", "name": "Bool" },
|
|
"doc": "Ord Bool. Body lowered via `try_emit_primitive_instance_body::\"compare__Bool\"` — `icmp ult i1` LT-test, `icmp eq i1` EQ-test, GT default.",
|
|
"methods": [
|
|
{
|
|
"name": "compare",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Ordering" },
|
|
"body": {
|
|
"t": "ctor",
|
|
"type": "Ordering",
|
|
"ctor": "EQ",
|
|
"args": []
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Ord",
|
|
"type": { "k": "con", "name": "Str" },
|
|
"doc": "Ord Str. Body lowered via `try_emit_primitive_instance_body::\"compare__Str\"` — `call i32 @ail_str_compare(ptr, ptr)` then branch on slt-0 / eq-0 against the normalised {-1, 0, +1} return.",
|
|
"methods": [
|
|
{
|
|
"name": "compare",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x", "y"],
|
|
"paramTypes": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"retType": { "k": "con", "name": "Ordering" },
|
|
"body": {
|
|
"t": "ctor",
|
|
"type": "Ordering",
|
|
"ctor": "EQ",
|
|
"args": []
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "class",
|
|
"name": "Show",
|
|
"param": "a",
|
|
"doc": "Producer of a human-readable Str representation. Ships in milestone 24 with primitive instances for Int/Bool/Str/Float; user types declare their own instance.",
|
|
"methods": [
|
|
{
|
|
"name": "show",
|
|
"type": {
|
|
"k": "fn",
|
|
"params": [{ "k": "var", "name": "a" }],
|
|
"param_modes": ["borrow"],
|
|
"ret": { "k": "con", "name": "Str" },
|
|
"effects": []
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Show",
|
|
"type": { "k": "con", "name": "Int" },
|
|
"methods": [
|
|
{
|
|
"name": "show",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x"],
|
|
"paramTypes": [{ "k": "con", "name": "Int" }],
|
|
"retType": { "k": "con", "name": "Str" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "int_to_str" },
|
|
"args": [{ "t": "var", "name": "x" }]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Show",
|
|
"type": { "k": "con", "name": "Bool" },
|
|
"methods": [
|
|
{
|
|
"name": "show",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x"],
|
|
"paramTypes": [{ "k": "con", "name": "Bool" }],
|
|
"retType": { "k": "con", "name": "Str" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "bool_to_str" },
|
|
"args": [{ "t": "var", "name": "x" }]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Show",
|
|
"type": { "k": "con", "name": "Str" },
|
|
"methods": [
|
|
{
|
|
"name": "show",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x"],
|
|
"paramTypes": [{ "k": "con", "name": "Str" }],
|
|
"retType": { "k": "con", "name": "Str" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "str_clone" },
|
|
"args": [{ "t": "var", "name": "x" }]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "instance",
|
|
"class": "Show",
|
|
"type": { "k": "con", "name": "Float" },
|
|
"methods": [
|
|
{
|
|
"name": "show",
|
|
"body": {
|
|
"t": "lam",
|
|
"params": ["x"],
|
|
"paramTypes": [{ "k": "con", "name": "Float" }],
|
|
"retType": { "k": "con", "name": "Str" },
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "float_to_str" },
|
|
"args": [{ "t": "var", "name": "x" }]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "ne",
|
|
"doc": "Polymorphic disequality. `ne x y` ≡ not (eq x y). Ships in milestone 23 as the Eq-class free helper.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Eq", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
},
|
|
"params": ["x", "y"],
|
|
"body": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "not" },
|
|
"args": [{
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "eq" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
}]
|
|
}
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "lt",
|
|
"doc": "Polymorphic strict-less-than. `lt x y` ≡ case compare x y of LT -> True; _ -> False. Ships in milestone 23 as the Ord-class free helper.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Ord", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
},
|
|
"params": ["x", "y"],
|
|
"body": {
|
|
"t": "match",
|
|
"scrutinee": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "compare" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
},
|
|
"arms": [
|
|
{
|
|
"pat": { "p": "ctor", "ctor": "LT", "fields": [] },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": true } }
|
|
},
|
|
{
|
|
"pat": { "p": "wild" },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": false } }
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "le",
|
|
"doc": "Polymorphic less-than-or-equal. `le x y` ≡ case compare x y of GT -> False; _ -> True. Ships in milestone 23 as the Ord-class free helper.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Ord", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
},
|
|
"params": ["x", "y"],
|
|
"body": {
|
|
"t": "match",
|
|
"scrutinee": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "compare" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
},
|
|
"arms": [
|
|
{
|
|
"pat": { "p": "ctor", "ctor": "GT", "fields": [] },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": false } }
|
|
},
|
|
{
|
|
"pat": { "p": "wild" },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": true } }
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "gt",
|
|
"doc": "Polymorphic strict-greater-than. `gt x y` ≡ case compare x y of GT -> True; _ -> False. Ships in milestone 23 as the Ord-class free helper.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Ord", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
},
|
|
"params": ["x", "y"],
|
|
"body": {
|
|
"t": "match",
|
|
"scrutinee": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "compare" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
},
|
|
"arms": [
|
|
{
|
|
"pat": { "p": "ctor", "ctor": "GT", "fields": [] },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": true } }
|
|
},
|
|
{
|
|
"pat": { "p": "wild" },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": false } }
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "ge",
|
|
"doc": "Polymorphic greater-than-or-equal. `ge x y` ≡ case compare x y of LT -> False; _ -> True. Ships in milestone 23 as the Ord-class free helper.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Ord", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [
|
|
{ "k": "var", "name": "a" },
|
|
{ "k": "var", "name": "a" }
|
|
],
|
|
"param_modes": ["borrow", "borrow"],
|
|
"ret": { "k": "con", "name": "Bool" },
|
|
"effects": []
|
|
}
|
|
},
|
|
"params": ["x", "y"],
|
|
"body": {
|
|
"t": "match",
|
|
"scrutinee": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "compare" },
|
|
"args": [
|
|
{ "t": "var", "name": "x" },
|
|
{ "t": "var", "name": "y" }
|
|
]
|
|
},
|
|
"arms": [
|
|
{
|
|
"pat": { "p": "ctor", "ctor": "LT", "fields": [] },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": false } }
|
|
},
|
|
{
|
|
"pat": { "p": "wild" },
|
|
"body": { "t": "lit", "lit": { "kind": "bool", "value": true } }
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"kind": "fn",
|
|
"name": "print",
|
|
"doc": "Polymorphic console-print helper. `print x` ≡ `do io/print_str (show x)` with an explicit let-binder around `show x` for heap-Str RC discipline per eob.1 Str carve-out. Ships in milestone 24 as the second half of the Show prelude.",
|
|
"type": {
|
|
"k": "forall",
|
|
"vars": ["a"],
|
|
"constraints": [{ "class": "Show", "type": { "k": "var", "name": "a" } }],
|
|
"body": {
|
|
"k": "fn",
|
|
"params": [{ "k": "var", "name": "a" }],
|
|
"param_modes": ["borrow"],
|
|
"ret": { "k": "con", "name": "Unit" },
|
|
"effects": ["IO"]
|
|
}
|
|
},
|
|
"params": ["x"],
|
|
"body": {
|
|
"t": "let",
|
|
"name": "s",
|
|
"value": {
|
|
"t": "app",
|
|
"fn": { "t": "var", "name": "show" },
|
|
"args": [{ "t": "var", "name": "x" }]
|
|
},
|
|
"body": {
|
|
"t": "do",
|
|
"op": "io/print_str",
|
|
"args": [{ "t": "var", "name": "s" }]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|