92e830e6c2
Five polymorphic prelude free fns (ne/lt/le/gt/ge) plus three E2E fixtures: positive composition over Int/Bool/Str, user-ADT with user-written Eq/Ord on IntBox, and Float-NoInstance with a Float-aware diagnostic addendum cross-referencing DESIGN.md §"Float semantics". Two checker-side fixes were needed alongside the prelude additions, both symmetric to the iter 23.4-prep visibility fix: - linearity::check_module_with_visible — workspace-aware callee-mode resolution so a Borrow-mode user fn forwarding into a prelude poly fn (e.g. `at_most x y = not (gt x y)`) doesn't false-fire consume-while-borrowed. - mono::collect_mono_targets — distinguish rigid forall vars from unbound metavars; rigid-bearing free-fn targets skip (they get re-collected with concrete subst when the enclosing fn itself monomorphises). Without this, a polymorphic body calling another polymorphic free fn produced a spurious __Unit specialisation whose body referenced compare at Unit. Roadmap split: shipped Eq/Ord half checked, Show + print-rewire half remains pending behind the heap-Str ABI prerequisite. DESIGN.md §"Prelude classes" amended. One pre-existing fixture (test_22b1_missing_method) renamed its class method ne → tne to avoid collision with the new prelude `ne`. Bench: check.py + cross_lang.py exit 0; compile_check.py exits 1 with one sub-ms check_ms.local_rec_capture at +26% (tolerance 25%) — prelude-growth-related noise-band fluctuation, ratifiable per spec §248-249 and journal Concerns.
425 lines
13 KiB
JSON
425 lines
13 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": "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 } }
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|