Closes Gitea #1. Realises the "P2 follow-up" called out in examples/prelude.ail:9 — removes the surface comparator names `==` / `!=` / `<` / `<=` / `>` / `>=` from the language entirely, routes the LLM-author's `(app eq …)` / `(app compare …)` / `(app ne|lt|le|gt|ge …)` through prelude.Eq / prelude.Ord class- dispatch, ships six named Float-comparison fns (`float_eq`/`float_ne`/`float_lt`/`float_le`/`float_gt`/`float_ge`) so Float keeps comparability without an Eq/Ord instance, and emits primitive instance bodies with `alwaysinline` so the -O0 IR shape stays at one instruction per comparison. Plan-task journal (13 tasks, single atomic iter per Approach A): Task 1 — Bootstrap: 4 new fixtures (eq_user_adt_smoke.ail, eq_float_must_fail.ail, float_compare_smoke.ail, operator_unbound_check.ail) + 5 new E2E/pin tests as RED starting state. All 5 confirmed RED at start: north-star fixed `NoInstance Eq Unit` (preserved by Unit-eq opening line intentionally added in plan-self-review); float_compare unknown `float_eq`; operator-name typechecked (== still polymorphic); must-fail diagnostic lacked `float_eq`; alwaysinline absent from IR. Task 2 — Codegen alwaysinline + intercept arms: introduced `intercept_emit_wants_alwaysinline` allowlist + appended ` alwaysinline` between `)` and `{` of the `define` line in `emit_fn`; added 9 new intercept arms to `try_emit_primitive_instance_body` — `eq__Int`/`eq__Bool`/ `eq__Unit` + the six `float_*` arms. Task 3 — Prelude reshape: `instance Eq Unit` added; Eq Int/Bool bodies become placeholder-`false` (intercept overrides); six `float_*` free fns added; line-9 P2-follow-up comment removed. Lockstep hash re-pins: prelude_module_hash_pin (3abe0d3fa3c11c99 → new), mono_hash_stability six body-hash literals (eq__Int/Bool/Str + compare__Int/Bool/Str all shifted because placeholder body changes the canonical hash). IR-snapshot regen (hello/list/max3/sum/ws_main) rolled forward into this task at orchestrator's pragmatic call — prelude shift forces the snapshots immediately. Task 4 — Fixture migration: 58 .ail fixtures rewritten (`(app == …)` → `(app eq …)`, etc.; Float-typed operand sites to `(app float_eq …)` / `(app float_lt …)`). eq_ord_user_adt.ail:21 inner `==` → `eq` migration with lockstep eq_ord_e2e.rs:134 body-hash re-pin (3c4cf040cb4e8bb2 → new). Two prose snapshots accepted; deps test + 5 hash_pin literals updated as cascading consequences. Task 5 — Test-scaffold migration: all 8 in-source `#[cfg(test)] mod tests` AST-literal sites threaded (desugar.rs:2414, check/lib.rs:5656/6092/6220, codegen/lib.rs sites). 7 obsolete in-source tests deleted (5 eq_typechecks + 2 lower_eq ADT/Fn rejection — coverage moves to E2E eq_user_adt_smoke + eq_float_must_fail). 2 additional letrec tests deleted (single-module check env can't resolve eq/ge without prelude auto-import; covered by workspace E2E). Task 6 — Lit-pattern desugar: build_eq emits `Term::Var { name: "eq" }` instead of `"=="` at desugar.rs:1109; doc-comment rewritten to describe class-dispatch. Task 7 — Dead-machinery deletion sweep (compile-gated): typchecker builtins (install + list comparator entries deleted); codegen builtin_binop_typed (10 comparator arms deleted from synth.rs, table reduced to arithmetic core); lower_eq fn entirely deleted; `==` short-circuit in lower_app deleted; `is_static_callee` `==` clause deleted; `is_arithmetic_or_comparison_op` renamed to `is_arithmetic_op` + caller-update at codegen/lib.rs:2152 + :2529. Dead `poly_a_a_to_bool` helpers also removed. Workspace build green after compile gate — every caller of the deleted surface was migrated by Tasks 4-6. Task 8 — Float-aware NoInstance diagnostic: check/lib.rs:856-880 addendum extended to name `float_eq` / `float_lt` as the explicit alternative for Eq/Ord at Float; eq_float_noinstance.rs:32-44 assertion extended. Task 9 — IR snapshot regen: subsumed by Task 3 (prelude shift forced immediate snapshot regen; deferring to Task 9 would have left the workspace red between tasks). Task 10 — Prose-projection cleanup: 6 comparator arms deleted from binop_info; 3 in-source mod-tests updated/deleted (comparator-infix rendering would be dishonest now that the operators are no longer language identifiers). Task 11 — Contract updates: 5 design files rewritten to the class-dispatch present — float-semantics.md (arithmetic guarantees retained on +/-/*/; comparison guarantees transferred from ==/!=/< to float_eq/float_ne/float_lt/etc.); prelude-classes.md (Eq Unit added to instance list; new paragraph on six float_* fns; Float-no-Eq/Ord clause gains `→ use float_eq` cross-reference); str-abi.md (clause "REMAIN primitive operators" rewritten to describe class-method dispatch); scope-boundaries.md (multiple operator-name and Pattern::Lit-desugar clauses rewritten); authoring-surface.md (==, <= dropped from operator-example list). Task 12 — Initial acceptance gate: workspace 638/0 GREEN; bench/compile_check + cross_lang 0 regressed; bench/check.py flagged 4 regressions on bench_closure_chain (+29% bump_s, +47% rc_s, +29% bump_rss_kb, +48% rc_rss_kb). Orchestrator initially classified as DONE-with-concerns; Boss reclassified as PARTIAL-via-acceptance-#8-fail after independent re-run, extended iter scope to Task 13. Task 13 — Direct icmp intercept arms (Boss-extension): try_emit_primitive_instance_body gains direct-icmp arms for lt__Int / le__Int / gt__Int / ge__Int / ne__Int, bypassing the compare__Int → Ordering → match indirection that allocated one Ordering ctor per call in tight loops. Each new arm inherits `alwaysinline` via the existing allowlist (extended accordingly). New IR pin test `ord_int_intercept_ir_pin.rs` + smoke fixture `ord_int_intercept_smoke.ail` ratify the optimization — opt -O2 -S confirms zero `call @ail_prelude_lt__Int` in optimized IR; the icmp folds directly at every use site. Bool variants (lt__Bool/etc.) deliberately NOT added — no bench/example calls Ord at Bool; spec-extension permits skipping if unreachable at bench level. Family can be extended symmetrically when first Bool-ordered perf workload appears. Bench-gate post-Task-13: bench_closure_chain bump_s -6.05%, rc_s -2.67%, bump_rss_kb -0.77%, rc_rss_kb +0.46% — all four previously-regressed metrics back inside tolerance. Full bench corpus: 36 metrics, 0 regressed, 0 improved beyond tolerance, 36 stable. bench/check.py exit 0 ✓; bench/compile_check.py exit 0 ✓; bench/cross_lang.py exit 0 ✓. Workspace: 640 passed, 0 failed across all binaries (delta vs. milestone start: +5 new E2E/pin tests added in Task 1 + 1 IR pin added in Task 13 − 9 in-source mod tests deleted as obsolete net ≈ −3). The eq_user_adt_smoke fixture's Unit-opening line was the deliberate RED-first device added in planner self-review so the north-star wouldn't accidentally GREEN at start (user-ADT-Eq on Point with hand-written instance was already operable today; the milestone's actual delivery is operator-name death + Eq Unit + Float-named-fns + cleanup of the two-pathy primitive comparator machinery). Net delta: 96 files changed, 1760 insertions, 1101 deletions; 12 net-new files (6 new fixtures, 5 new E2E/pin tests, 1 stats file). main passes-test-count: 640 (was 633 pre-iter, accounting for the deletions). Spec-vs-acceptance addendum: spec §Testing strategy anticipated the bench-gate-regression case with two recovery paths (`alwaysinline` investigation or "spec needs revisiting toward α"). Task 13 is the third path — direct intercept arms for `lt`/etc. that bypass the compare→match path entirely. The spec's contingency clause was thus generous enough to absorb Task 13 without spec revision, but a future iter that hits a class-method primitive where the body shape introduces a similar codegen cost (Ordering allocation, RC tax, deferred-init) should expect a parallel extension. The pattern is "primitive instance whose canonical body indirects through other class methods that allocate" → add a direct-emit intercept arm + alwaysinline + IR-shape pin. Concerns absorbed: - Codegen lower_app / resolve_top_level_fn gained a prelude-fallback lookup so bare monomorphic prelude fns (`float_eq` etc.) resolve from non-prelude modules without explicit `prelude.float_eq` qualifier. Mirrors the typechecker's implicit prelude import — not in plan but necessary infra for the named-fn surface to be callable. - Recon's "≈10 fixtures" estimate was 6× too low — 58 actual. Mechanical migration; no design impact. - Recon caught 4 in-source AST-literal sites the spec missed (lib.rs:5656 `>=` site + three codegen/lib.rs sites); Task 5 covered all. - Recon caught 2 contract files outside the spec's update set that directly contradicted the milestone (str-abi.md + scope-boundaries.md "REMAIN primitive operators" / "Pattern::Lit desugar to ==" clauses); Task 11 covered all 5. Stats file: `bench/orchestrator-stats/2026-05-21-iter-operator-routing-eq-ord.1.json`. closes #1
11 KiB
What is not (yet) supported
What is not (yet) supported
Snapshot of the current boundary.
- No effect handlers — only the built-in
IOop (io/print_str); the effect system is described in effects.Divergeis a reserved effect name with no op and no codegen. - No refinements / SMT escalation.
- No HM inference inside bodies. Top-level def types are explicit;
polymorphism is opt-in via
Type::Forall { vars, body }(see Data model). Inside a body, lambdas check monomorphically against their declared type. - Polymorphic fns must be directly called at the use site.
Passing a polymorphic fn as a value (
let f = id in f(42)) is not yet supported. - No higher-rank polymorphism. Passing a polymorphic fn to another
polymorphic fn (
apply(id, 42)) is not supported. - No recursive
letfor non-fn values. Plainlet x = … in …only seesxinside the body, not inside its own RHS — recursive value bindings would break the acyclicity invariant. Recursive fn bindings are supported viaTerm::LetRec({ "t": "letrec", ... }); the desugar pass lifts most occurrences to a synthetic top-level fn, withlift_letrecsfinishing the residue after typecheck (see pipeline). - No visibility rules in imports. Every top-level def of an imported module
is reachable; there is no
pub/priv.
What is supported (and used as the smoke test for the pipeline):
-
Int, Bool, Unit, Str, Float as primitive types.
-
if,let, function calls, recursion. -
Effects on function signatures, with
do op(args)for direct effect ops (io/print_str). The polymorphicprint(see prelude classes) is the canonical output path for non-Str values. -
Builtins. Arithmetic operators (
+,-,*,/) of typeforall a. (a, a) -> a(codegen-restricted to{Int, Float});%of type(Int, Int) -> Int(Int-only —fmodsemantics for Float deferred); polymorphicneg : forall a. (a) -> a(codegen-restricted to{Int, Float}; Float arm uses LLVMfneg doublefor correct-0.0handling); logicalnot : (Bool) -> Bool; conversionsint_to_float : (Int) -> Float,float_to_int_truncate : (Float) -> Int(saturating, NaN → 0),float_to_str : (Float) -> Str,int_to_str : (Int) -> Str(both allocate a heap-Str slab at call time and return it withret_mode: Own; see Str ABI for the dual heap-/static-Str realisation); inspectionis_nan : (Float) -> Bool(LLVMfcmp uno); Float bit-pattern constantsnan : Float,inf : Float,neg_inf : Float(resolved as bare values, lower to direct hex-floatdoubleSSA constants at use site); the IO effect opio/print_str; and__unreachable__ : forall a. a.- Equality + ordering are not builtins. The class method
eq(prelude.Eq) dispatches via the per-type Eq instance; the class methodcompare(prelude.Ord) dispatches via the per-type Ord instance, returning a three-ctorOrderingADT (LT/EQ/GT). The five free helpersne/lt/le/gt/geare defined in the prelude in terms ofeq/compare. The primitive Eq/Ord instance bodies are emitted by the codegen intercepttry_emit_primitive_instance_body: Eq Int →icmp eq i64, Eq Bool →icmp eq i1, Eq Str →call @ail_str_eq(...), Eq Unit →ret i1 1, Ord Int / Bool / Str → three-wayicmp slt/icmp eqladder constructing theOrderingctor; every primitive instance body carries thealwaysinlineattribute so the call folds at every use site. Float has no Eq / Ord instance (see Float semantics); explicit comparison is via the named fnsfloat_eq/float_ne/float_lt/float_le/float_gt/float_ge, each lowering to a singlefcmpwith the matching predicate.float_neusesfcmp une double(NOTone) sonan != nanreturnstrueper IEEE. __unreachable__is a polymorphic bottom value: a use of__unreachable__typechecks against any expected type at the use site and codegens to the LLVMunreachableinstruction (UB if ever executed). It is the chain machinery's deepest fall-through for matches that the typechecker proved exhaustive, and it is available to user code as an explicit panic primitive ((if cond __unreachable__ ...)for assertions or impossible branches). Reference site isTerm::Var { name = "__unreachable__" }/ form-A bare__unreachable__.
- Equality + ordering are not builtins. The class method
-
ADTs + pattern matching. Sub-patterns of a Ctor pattern may be
Var,Wild, anotherCtor, or a literal. The desugar pass flattens nested Ctor patterns into a chain of let + match and rewrites everyPattern::Lit(top-level or sub-) to aTerm::Ifoneq(the class methodprelude.Eq.eq) before typecheck/codegen — see desugar and Pipeline. -
Literal patterns at top level and inside Ctor sub-patterns (via desugar).
(pat-lit 0)and(pat-ctor Cons (pat-lit 0) _)both parse and lower; the rewrite is toTerm::If { cond = (eq sv lit) }, so any literal kind whoseeqdispatch resolves to a known primitive Eq instance is authorable. The primitive instances coverInt/Bool/Str/Unit;Floatlit-patterns are hard-rejected at typecheck (CheckError::FloatPatternNotAllowed, see float-semantics).(pat-lit "hi")over aStrscrutinee is exercised byexamples/eq_demo.ail.json. -
Imports + qualified cross-module references via dotted names. Extends to types and constructors: a foreign module's ADT is referenced as
(con std_pair.Pair a b), its ctors as(term-ctor std_pair.Pair MkPair x y)and(pat-ctor MkPair x y)inside that scrutinee. Std-library demos (examples/std_*_demo.ail.json) exercise this end-to-end. -
AI-authoring text surface, form (A) (see authoring surface). The
ailang-surfacecrate parses.ailform-A text into a canonicalailang-core::ast::Moduleand prints any module back as form-A text.ail renderandail describeuse it as the sole text projection;ail parseis the inverse direction. Round-trip identity (text → AST → JSON → AST → text) is gated byailang-surface/tests/round_trip.rsover every shipped fixture. -
Memory management via reference counting + uniqueness inference (see RC + uniqueness), with per-fn arena via stack
allocafor non-escaping allocations layered on top. Every ADT box, lambda env, and closure pair allocates either via@ailang_rc_alloc(escaping; RC-managed with inc/dec instrumentation per the memory model) or via LLVMalloca(non-escaping; freed at fn return). The decision is made by an escape-analysis pre-pass over the fn body — see the "Per-fn arena via stackalloca" subsection of RC + uniqueness. The per-fn-arena path is exercised end-to-end byexamples/escape_local_demo.ail.json. -
First-class function references. A top-level fn name (or qualified
prefix.def) used as aTerm::Varis a fn-value. -
Anonymous lambdas with capture.
Term::Lamconstructs a closure that captures any free variables of its body from the enclosing scope. All fn-values share a single ABI: aptrto a closure pair{ thunk_ptr, env_ptr }. Top-level fns get an auto- generated adapter and a static closure pair (env = null) so they remain passable as values without heap overhead. -
Polymorphism via
Type::Forallat top-level def types. Use sites instantiate fresh metavars; unification pins them against the concrete types of the call args. Codegen monomorphises on demand: each unique instantiation emits a specialised LLVM fn mangled@ail_<m>_<def>__<descriptor>(e.g.id__IforidatInt,apply__I_Iforapplyat(Int, Int)). -
Parameterised ADTs.
TypeDef.vars: Vec<String>declares type parameters;Type::Con.args: Vec<Type>carries the type arguments at use sites. Both fields default to empty and are skipped during serialization, so canonical-JSON hashes of every existing definition stay bit-identical (regression test incrates/ailang-core/src/hash.rs). Ctor and match codegen stay inline at every use site — there is no specialised ADT symbol — but LLVM field types are derived per use site by substituting throughcdef.ail_fields. The substitution is read off the call's arg types (ctor) or the scrutinee'sType::Con.args(match). An unresolvedType::Varreachingllvm_typeis a hard error rather than a silent fallback toptr. Pipeline regression smoke tests: -
examples/sum.ail.json→ prints 55 (recursion, arithmetic). -
examples/list.ail.json→ prints 42 (ADTs + match). -
examples/hof.ail.json→ prints 42 (first-class fn-refs, indirect call). -
examples/closure.ail.json→ prints 42 (lambda capturing a let-bound var). -
examples/list_map.ail.json→ prints 2/4/6 (ADTs + closure + recursive HOF + IO; the dogfood smoke test). -
examples/sort.ail.json→ prints sorted [3,1,4,1,5,9,2,6,5,3,5] one-per-line (insertion sort over an 11-element list). -
examples/poly_id.ail.json→ prints 42 then "true" (polymorphic identity atIntandBool; two specialised fns emitted). -
examples/poly_apply.ail.json→ prints 42 (polymorphicapplywith a fn-typed parameter;apply(succ, 41)). -
examples/box.ail.json→ prints 42 (parameterised ADT round- trip:MkBox(42)constructed, then projected by a polymorphicunbox : forall a. (Box<a>) -> aand printed). -
examples/maybe_int.ail.json→ prints 7 then 99 (pattern match overMaybe<Int>:or_else(Some(7), 99)thenor_else(None, 99)). -
examples/std_list_demo.ail.json→ exercisesstd_list's combinators (length, sum, reverse, take/drop-style uses) end-to-end againststd_list'sList<a>. -
examples/std_maybe_demo.ail.json→ exercisesstd_maybecombinators overMaybe<Int>, includingfrom_maybeandmap. -
examples/std_either_demo.ail.json→ first program with three distinct type variables in a single fn (theeithereliminator), monomorphised six different ways in the IR. -
examples/std_pair_demo.ail.json→ drives everystd_paircombinator (fst, snd, swap, map_first, map_second); expected output 7, 9, 9, 7, 8, 18. -
examples/nested_pat.ail.json→ first program to use a nested(pat-ctor Cons a (pat-ctor Cons b _)); the desugar pass flattens it into a chain that the existing flat-match codegen consumes. Prints 30 for a 3-element input list.
Ratified by: crates/ailang-core/tests/effect_doc_honesty_pin.rs.