iter 23.5: prelude free fns + E2E — Eq/Ord milestone close

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.
This commit is contained in:
2026-05-12 00:38:52 +02:00
parent 35c6eb5736
commit 92e830e6c2
21 changed files with 1321 additions and 41 deletions
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "eq_float_noinstance",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "eq" },
"args": [
{ "t": "lit", "lit": { "kind": "float", "bits": "3ff0000000000000" } },
{ "t": "lit", "lit": { "kind": "float", "bits": "4000000000000000" } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+103
View File
@@ -0,0 +1,103 @@
{
"schema": "ailang/v0",
"name": "eq_ord_polymorphic",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "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": {
"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": "app",
"fn": { "t": "var", "name": "not" },
"args": [{
"t": "app",
"fn": { "t": "var", "name": "gt" },
"args": [
{ "t": "var", "name": "x" },
{ "t": "var", "name": "y" }
]
}]
}
},
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "seq",
"lhs": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "at_most" },
"args": [
{ "t": "lit", "lit": { "kind": "int", "value": 3 } },
{ "t": "lit", "lit": { "kind": "int", "value": 5 } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
},
"rhs": {
"t": "seq",
"lhs": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "at_most" },
"args": [
{ "t": "lit", "lit": { "kind": "bool", "value": true } },
{ "t": "lit", "lit": { "kind": "bool", "value": false } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
},
"rhs": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "at_most" },
"args": [
{ "t": "lit", "lit": { "kind": "str", "value": "abc" } },
{ "t": "lit", "lit": { "kind": "str", "value": "abd" } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
}
}
]
}
+156
View File
@@ -0,0 +1,156 @@
{
"schema": "ailang/v0",
"name": "eq_ord_user_adt",
"imports": [],
"defs": [
{
"kind": "type",
"name": "IntBox",
"vars": [],
"doc": "A one-field box around an Int, used to demonstrate that the unified mono pass synthesises eq__IntBox from a user-written instance, not from the primitive == operator.",
"ctors": [
{ "name": "MkIntBox", "fields": [{ "k": "con", "name": "Int" }] }
]
},
{
"kind": "instance",
"class": "Eq",
"type": { "k": "con", "name": "IntBox" },
"doc": "Eq IntBox by structural unwrap of the inner Int.",
"methods": [
{
"name": "eq",
"body": {
"t": "lam",
"params": ["a", "b"],
"paramTypes": [
{ "k": "con", "name": "IntBox" },
{ "k": "con", "name": "IntBox" }
],
"retType": { "k": "con", "name": "Bool" },
"body": {
"t": "match",
"scrutinee": { "t": "var", "name": "a" },
"arms": [{
"pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "ai" }] },
"body": {
"t": "match",
"scrutinee": { "t": "var", "name": "b" },
"arms": [{
"pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "bi" }] },
"body": {
"t": "app",
"fn": { "t": "var", "name": "==" },
"args": [
{ "t": "var", "name": "ai" },
{ "t": "var", "name": "bi" }
]
}
}]
}
}]
}
}
}
]
},
{
"kind": "instance",
"class": "Ord",
"type": { "k": "con", "name": "IntBox" },
"doc": "Ord IntBox by delegating to Int's compare on the inner field.",
"methods": [
{
"name": "compare",
"body": {
"t": "lam",
"params": ["a", "b"],
"paramTypes": [
{ "k": "con", "name": "IntBox" },
{ "k": "con", "name": "IntBox" }
],
"retType": { "k": "con", "name": "prelude.Ordering" },
"body": {
"t": "match",
"scrutinee": { "t": "var", "name": "a" },
"arms": [{
"pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "ai" }] },
"body": {
"t": "match",
"scrutinee": { "t": "var", "name": "b" },
"arms": [{
"pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "bi" }] },
"body": {
"t": "app",
"fn": { "t": "var", "name": "compare" },
"args": [
{ "t": "var", "name": "ai" },
{ "t": "var", "name": "bi" }
]
}
}]
}
}]
}
}
}
]
},
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "seq",
"lhs": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "eq" },
"args": [
{
"t": "ctor", "type": "IntBox", "ctor": "MkIntBox",
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }]
},
{
"t": "ctor", "type": "IntBox", "ctor": "MkIntBox",
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }]
}
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
},
"rhs": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "eq" },
"args": [
{
"t": "ctor", "type": "IntBox", "ctor": "MkIntBox",
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }]
},
{
"t": "ctor", "type": "IntBox", "ctor": "MkIntBox",
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 5 } }]
}
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "ge_at_int_smoke",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "ge" },
"args": [
{ "t": "lit", "lit": { "kind": "int", "value": 3 } },
{ "t": "lit", "lit": { "kind": "int", "value": 5 } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "gt_at_bool_smoke",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "gt" },
"args": [
{ "t": "lit", "lit": { "kind": "bool", "value": true } },
{ "t": "lit", "lit": { "kind": "bool", "value": false } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "le_at_str_smoke",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "le" },
"args": [
{ "t": "lit", "lit": { "kind": "str", "value": "abc" } },
{ "t": "lit", "lit": { "kind": "str", "value": "abd" } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "lt_at_int_smoke",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "lt" },
"args": [
{ "t": "lit", "lit": { "kind": "int", "value": 3 } },
{ "t": "lit", "lit": { "kind": "int", "value": 5 } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"schema": "ailang/v0",
"name": "ne_at_int_smoke",
"imports": [],
"defs": [
{
"kind": "fn",
"name": "main",
"type": {
"k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" },
"effects": ["IO"]
},
"params": [],
"body": {
"t": "do", "op": "io/print_int",
"args": [{
"t": "if",
"cond": {
"t": "app",
"fn": { "t": "var", "name": "ne" },
"args": [
{ "t": "lit", "lit": { "kind": "int", "value": 3 } },
{ "t": "lit", "lit": { "kind": "int", "value": 5 } }
]
},
"then": { "t": "lit", "lit": { "kind": "int", "value": 1 } },
"else": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
}]
}
}
]
}
+201
View File
@@ -218,6 +218,207 @@
}
}
]
},
{
"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 } }
}
]
}
}
]
}
+2 -2
View File
@@ -21,7 +21,7 @@
}
},
{
"name": "ne",
"name": "tne",
"type": {
"k": "fn",
"params": [
@@ -40,7 +40,7 @@
"type": { "k": "con", "name": "Int" },
"methods": [
{
"name": "ne",
"name": "tne",
"body": { "t": "lit", "lit": { "kind": "bool", "value": false } }
}
]