222 Commits

Author SHA1 Message Date
Brummel 72e54f4fd3 iter ext-rename: .ailx → .ail across the live toolchain
The surface-form file extension changes from .ailx to .ail. AILang's
authoring surface now uses the same .ail stem as its canonical JSON
form (.ail.json), giving the language a single coherent extension
family: .ail is the LLM-authored Form A, .ail.json is the canonical
JSON-AST Form B.

Scope (touched):
- 61 example renames examples/**/*.ailx → .ail (git mv)
- 1 rename experiments/.../rendered/ailx.md → ail.md
- 35 content-edited live-toolchain files (crates/, docs/DESIGN.md,
  docs/roadmap.md, docs/PROSE_ROUNDTRIP.md, skills/, bench/reference/*.c,
  experiment crates under experiments/.../{render,harness,master})
- Experiment-crate cohort rename Cohort::Ailx → Cohort::Ail,
  Form::Ailx → Form::Ail, per_cohort/ailx → per_cohort/ail,
  {form-only: ailx} → {form-only: ail}, ```ailx → ```ail

Out of scope (deliberately untouched, to preserve honest history):
- docs/journal-archive.md (content-frozen per CLAUDE.md)
- docs/journals/, docs/specs/, docs/plans/, bench/orchestrator-stats/
- experiments/.../runs/ (frozen LLM-output artefacts; models actually
  saw .ailx — renaming would falsify the experimental record)

Verification: cargo build/test --workspace green; experiment crate
cargo test green; bench/check.py + compile_check.py + cross_lang.py
all 0-regressed; negative grep for ailx|Ailx|AILX outside the
out-of-scope paths returns zero matches.

Opens immediate follow-up: roadmap.md P2 todo `ail check`/build/run
accept .ail extension — after this rename, .ail is canonical
authoring surface but the CLI still produces a misleading JSON-parse
error on `ail check foo.ail`. That's the next iter.
2026-05-12 14:20:27 +02:00
Brummel 098fa7e9be iter rt.1: roundtrip-invariant audit tests — 3 new tests, all PASS first-shot
Three new reader-only tests pin the .ail.json / .ailx bijection
plus AST-variant coverage. All three passed first observation
across the current corpus — no roundtrip, schema-coverage, or
CLI-drift gaps surfaced.

- every_ailx_fixture_matches_its_json_counterpart (replaces the
  3-pair handwritten exhibits): 57 paired .ailx fixtures pass.
- every_ast_variant_is_observed_in_the_fixture_corpus (new): 34/34
  AST variants exercised across 136 fixtures; exhaustive matches
  without _ wildcard so AST drift fails the build.
- cli_render_then_parse_preserves_canonical_bytes_on_every_fixture
  (new): 136 fixtures round-trip through ail render → tempfile →
  ail parse with BLAKE3 identity on canonical bytes.

No production code, no DESIGN.md changes (those follow in later
iterations). Tests are pure readers of the repo per spec
acceptance #7 — tempfile crate added as workspace dep for the CLI
roundtrip's intermediate file outside the repo.
2026-05-12 09:31:38 +02:00
Brummel 92e830e6c2 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.
2026-05-12 00:38:52 +02:00
Brummel a1692a4859 iter 23.4: mono-pass unification — class methods + polymorphic free fns in one fixpoint
Restructure ailang-check/src/mono.rs::monomorphise_workspace into a
single specialiser over every Type::Forall-quantified Def::Fn, covering
both class-method residuals AND polymorphic free-fn call sites in one
fixpoint pass. Remove the codegen-time specialiser (lower_polymorphic_call,
module_polymorphic_fns, mono_queue, mono_emitted, emit_specialised_fn,
plus the now-dead helpers apply_subst_to_term, descriptor_for_subst,
type_descriptor) entirely. Codegen sees only monomorphic Def::Fns after
this iter — no polymorphic call sites, no codegen-time queue.

Architecture changes:
- MonoTarget: struct → enum with ClassMethod / FreeFn variants; dedup
  keys are guaranteed-disjoint via 'class'/'free' first component.
- collect_mono_targets: new FreeFnCall channel through synth (cleaner
  than the plan's separate-walker proposal — one less data flow,
  substitution tracking comes 'for free' via fresh metavars +
  post-synth subst.apply). Plan Step 4.4 (polymorphic_free_fns env
  field) consequently obsolete.
- synthesise_mono_fn_for_free_fn: new free-fn entry point; substitutes
  rigid vars in BOTH the type AND the body (body substitution required
  because free-fn bodies carry inner Lams whose param_tys reference
  outer Forall vars — adapted from plan's 'body unchanged' sketch).
- mono_symbol_n: N-ary extension of mono_symbol; bit-stable for the
  single-type-var case (hash-stability pin Task 1 fires zero times
  through all eight refactor tasks).
- rewrite_class_method_calls → rewrite_mono_calls; interleaved-slot
  collector preserves the positional-cursor invariant across both
  channels.
- workspace_has_typeclasses → workspace_has_specialisable_targets
  (principled correctness; old predicate happened to already be true
  for every user workspace because the prelude is auto-injected).

Codegen cleanup:
- Two call sites of lower_polymorphic_call deleted (codegen/src/lib.rs
  lines ~1939-1945, ~1965-1973).
- lower_polymorphic_call body, module_polymorphic_fns field +
  population + Emitter wiring, mono_queue / mono_emitted, drain loop,
  emit_specialised_fn — all removed.
- is_static_callee collapsed to module_user_fns-only.
- subst.rs apply_subst_to_term + descriptor_for_subst removed; synth.rs
  type_descriptor removed (all dead post-removal).
- ail emit-ir command pipeline gains lift_letrecs + monomorphise_workspace
  pre-passes (pre-iter-23.4 the codegen-time poly path was masking
  this dependency — emit-ir is now consistent with build).
- Net codegen reduction: -285 lines lib.rs, -93 lines subst.rs.

Tests:
- mono_hash_stability.rs (new): regression pin for six primitive Eq/Ord
  mono-symbol body hashes; stayed bit-stable through all eight refactor
  tasks.
- mono_unification.rs (new): six tests covering variant-key disjointness,
  free-fn target emission, free-fn synthesis with rigid substitution,
  rewrite walker on free fns, identity for poly-free-fn-only workspaces,
  end-to-end cmp_max_smoke runtime correctness.
- typeclass_22b3.rs: three test sites updated to MonoTarget::ClassMethod
  enum form.
- 73 e2e + 18 typeclass + 81 codegen tests all green workspace-wide.

DESIGN.md §'Monomorphisation (post-typecheck, pre-codegen)' amended:
two-arm fixpoint described, disjoint-keyed dedup, cursor-aligned
walker, removed codegen-time path.

Bench check (all exit 0, 112 metrics stable): bench/check.py +
compile_check.py + cross_lang.py.

Plan parent: docs/plans/2026-05-11-iter-23.4.md (fab1685).
Spec parent: docs/specs/2026-05-11-23-eq-ord-prelude.md (841d65d).
Per-iter journal documents two adapted deviations from the plan
(synth-channel vs separate walker; body substitution; emit-ir fix);
no spec defects.
2026-05-11 23:59:45 +02:00
Brummel ba48349052 iter ct.4.4: compare_primitives_smoke E2E fixture (closes iter 23.3 Task 4) 2026-05-11 10:09:48 +02:00
Brummel 666c78468f iter ct.3.3: retire obsolete ambiguous-type paragraph in migrate-canonical-types docstring 2026-05-11 09:39:47 +02:00
Brummel edb694fdce iter ct.2.2-doctidy: refresh stale doc-comments on UnknownCtorInPattern and mono_xmod_ctor_pattern 2026-05-11 09:16:20 +02:00
Brummel b3c3b6088e iter ct.2.2: Pattern::Ctor type-driven lookup; delete imports-fallback 2026-05-11 09:07:59 +02:00
Brummel c1783e01bc iter ct.1.8: E2E coverage for canonical-form diagnostic surface + happy path
Five tests in crates/ail/tests/ct1_check_cli.rs, each pinning one named property:

- check_json_emits_bare_cross_module_type_ref: --json mode surfaces
  `bare-cross-module-type-ref` with non-zero exit on the
  test_ct1_bare_xmod_rejected fixture.
- check_json_emits_bad_cross_module_type_ref: same for
  `bad-cross-module-type-ref`.
- check_json_emits_qualified_class_name: same for `qualified-class-name`.
- check_human_mode_emits_actionable_message_to_stderr: human (non-JSON)
  mode prints both the offending type name and the migration-command
  hint to stderr — this path goes through the anyhow/thiserror Display
  impl, not workspace_error_to_diagnostic, so it needs its own pin.
- check_ordering_match_post_migration_is_clean: post-migration
  ordering_match.ail.json typechecks via the CLI with zero diagnostics,
  guarding against revert of the ct.1.5 migration or a regression in
  Registry::normalize_type_for_lookup that would reject the canonical form.
2026-05-11 01:50:29 +02:00
Brummel a73f7d3213 iter ct.1.4-followup: type-con rewrite test + doc clarity 2026-05-11 01:21:18 +02:00
Brummel d45977f9bb iter ct.1.4: dev-only ail migrate-canonical-types subcommand 2026-05-11 01:16:55 +02:00
Brummel 000b84dda7 iter ct.1.1: validator scaffolding + Type::Con canonical-form rules
Adds BareCrossModuleTypeRef / BadCrossModuleTypeRef / QualifiedClassName
to WorkspaceLoadError plus the validate_canonical_type_names function
that enforces the canonical-form rule on every Type::Con name reachable
from any def (including Term::Lam.param_tys / .ret_ty and Term::LetRec.ty).
Term::Ctor.type_name and class-name fields land in Tasks 2 + 3; the
validator is not yet wired into load_workspace (Task 6). Seven RED-first
unit tests cover the cases enumerated in spec section Testing strategy
plus a Lam-embedded-type smuggle-prevention test.

main.rs gains diagnostic arms for the three new variants to keep the
exhaustive match compiling.
2026-05-11 00:58:37 +02:00
Brummel 94893bfb9d iter 23.3.1: runtime ail_str_compare + IR header declaration 2026-05-10 23:00:22 +02:00
Brummel 559e591ab2 iter 23.2.4: e2e smoke fixture + ir-shape integration tests for eq__T mono symbols 2026-05-10 22:46:51 +02:00
Brummel e580f75adf test: red for mono pass mis-resolving cross-module ctor patterns
`monomorphise_workspace` re-runs `synth` on every fn body to recover
residual class constraints; the env it uses is built by
`mono::build_workspace_env`, which delegates to `build_check_env` and
produces a workspace-flat `ctor_index` (every Def::Type ctor across
every module, keyed by bare ctor name → bare type name).

`check_in_workspace` (lib.rs:1247-1258) explicitly clears that flat
index after `build_check_env` and rebuilds it per-module so that
`Pattern::Ctor`'s local-first / imports-fallback resolution at
lib.rs:2486-2521 keeps the qualified-type-name comparison at
lib.rs:2526 intact: imports-fallback yields a qualified
`resolved_type_name` (`Mod.Type`), local-hit yields a bare one.

The mono pass never does the per-module overlay, so when a body in
module B pattern-matches a ctor `C` whose Def::Type lives in imported
module A, the workspace-flat index resolves `C` locally and yields the
bare type name. The scrutinee, however, was typed against the
qualified name, and the comparison fails with
`PatternTypeMismatch { ctor: "Cons", ty: "A.Type<...>" }`.

Surfaced by iter 23.2 Task 3, which adds `class Eq a` + Eq Int/Bool/Str
instances to the prelude. Pre-Task-3 the prelude is class-free, so
`workspace_has_typeclasses(ws) == false` and the mono pass early-outs
at `mono.rs:73`. Task 3 flips the gate; every workspace now traverses
bodies, which brings the latent bug to the surface for the
pre-existing `nested_ctor_pattern_first_two_sum` and
`std_either_list_demo` E2E tests.

Sibling regressions in the same family: `mono_xmod_qualified_ref.rs`
(env.imports not seeded), commit 13b36cc (env.globals not seeded for
self-recursive fns), commit 5c5180f (env.types / env.ctor_index not
seeded for user ADTs — the original "flat ctor_index" decision that
this bug now exposes as wrong-by-construction for cross-module ctor
pattern resolution).

The minimal fixture is two modules with five defs total:
test_mono_ctor_listmod (data List a = Nil | Cons a (List a)) and
test_mono_ctor_main (class Trivial a + instance Trivial Int + a fn
that pattern-matches Cons against the imported List<Int> + a main).
The test pins the inner cause: matches against the specific
`CheckError::PatternTypeMismatch` variant with the qualified
scrutinee type and bare ctor name, so it stays RED regardless of the
prelude's typeclass content.
2026-05-10 22:16:51 +02:00
Brummel 736064adf4 iter 23.2.2: codegen — declare @ail_str_eq + eq__Str body intercept 2026-05-10 21:55:19 +02:00
Brummel cc2d6944c1 iter 23.2.1: runtime/str.c with ail_str_eq + unconditional link 2026-05-10 21:49:45 +02:00
Brummel aace5e3ce2 iter 23.1.4: E2E fixture — bare LT match via implicit prelude import 2026-05-10 21:32:05 +02:00
Brummel 3742583924 iter 23.1.2: load_workspace auto-injects prelude module 2026-05-10 21:13:40 +02:00
Brummel 9764b616ce floats iter 4.6: codegen io/print_float + examples/floats.ail.json E2E fixture 2026-05-10 16:25:25 +02:00
Brummel 581144a4f9 floats iter 4.4: codegen neg/int_to_float/float_to_int_truncate/is_nan + float_to_str-deferred 2026-05-10 16:15:39 +02:00
Brummel 2bf827f600 test: red for mono-pass unknown module prefix on qualified xmod reference in class workspace 2026-05-10 01:19:45 +02:00
Brummel 3b0bcf3f65 test: red for mono-pass unknown identifier on recursive fn in class workspace 2026-05-10 01:06:18 +02:00
Brummel 59e86b3805 test: red for monomorphise_workspace unknown type on user ADT 2026-05-09 22:41:18 +02:00
Brummel 090f082215 iter 22b.3.tester: e2e for coherence, default-keyword, cross-module mono
Adds three end-to-end tests for the 22b.3 mono pass, each with a
matching one-property fixture under examples/. Defends mono-pass
invariants 3, 4, and 6 from docs/specs/2026-05-09-22-typeclasses.md
at the binary level (stdout-asserting, not AST-asserting):

- coherence_two_instances_pick_correct_body_at_runtime — class R
  with instances at Int and Bool, both reachable from one main.
  Stdout `11\n22` proves both mono fns are synthesised AND each
  call site picks the matching body (no collapse).

- class_default_method_runs_and_prints_default_value — empty
  instance body + class-level `default` clause must lower, link,
  and print the default value (`99`). Promotes the existing
  synthesise_mono_fn unit test to a binary-level guarantee.

- cross_module_class_method_runs_and_prints_correct_value —
  class+instance in module A, called from module B's main. The
  qualified-name rewrite + cross-module synth-def placement was
  AST-tested in 22b.3.6; this pins down the emit-and-link path.

All 18 typeclass_22b3 tests pass; full workspace green; 3 bench
gates 0/0/0.
2026-05-09 21:36:15 +02:00
Brummel b59820b737 iter 22b.3.7: synthetic fixture — class+instance compiles, runs, prints 5 2026-05-09 21:28:41 +02:00
Brummel 7f260b82ad iter 22b.3.6: fix — quality-review (shadow-aware walker, cross-mod test, Option-typed targets, const helper) 2026-05-09 21:21:33 +02:00
Brummel d1b590ceab iter 22b.3.6: call-site rewrite — same/cross module qualified names 2026-05-09 21:07:58 +02:00
Brummel e8018d48b6 iter 22b.3.5: fix — quality-review (chained-call test, hoist class_index, drop noise comments) 2026-05-09 20:59:43 +02:00
Brummel dd87b36e00 iter 22b.3.5: workspace fixpoint loop — dedup + synth-append 2026-05-09 20:52:07 +02:00
Brummel d2954010ea iter 22b.3.4: fix — quality-review (zero-arg test, drop what-comments + param-name pin) 2026-05-09 20:45:56 +02:00
Brummel d6084a71fb iter 22b.3.4: synthesise_mono_fn — instance body + class default fallback 2026-05-09 20:41:45 +02:00
Brummel 89311ee20b iter 22b.3.3: collect_mono_targets — synth-replay residual gathering 2026-05-09 20:31:12 +02:00
Brummel 028227587b iter 22b.3.2: mono_symbol — primitive surface forms + hash for compound 2026-05-09 20:21:24 +02:00
Brummel 108115f7dd iter 22b.3.1: fix — quality-review (doc reframe + class-present test) 2026-05-09 20:18:20 +02:00
Brummel 209074ee5d iter 22b.3.1: mono pass skeleton — identity for class-free workspaces 2026-05-09 20:12:36 +02:00
Brummel 73965a6cbd iter 22b.2.e2e: cross-module class resolution + multi-fn aggregation
Four new E2E tests in typeclass_22b2.rs covering invariants the
per-task fixtures (all single-module, single-fn) did not exercise:

- cross_module_class_method_resolves_and_fires_no_instance:
  module B's call to `show` (declared in module A) reaches the
  no-instance arm, proving Env.class_methods is merged workspace-
  wide and not restricted to the local module.
- cross_module_polymorphic_fn_without_constraint_fires_missing_constraint:
  same merge guarantees the missing-constraint arm sees the residual
  produced by a call to A's class method from inside B.
- cross_module_instance_satisfies_concrete_call: the workspace
  registry built at load time over all modules must populate keys
  visible from B; a concrete call resolves clean cross-module.
- two_fns_each_missing_constraint_produce_two_diagnostics: pins
  check_in_workspace's per-def aggregation — two ill-formed fns
  produce two diagnostics (one per fn), not one.

Six new fixtures (xmod_* trio + two_fns_*).
2026-05-09 19:19:44 +02:00
Brummel 47bec74b26 iter 22b.2.10: fix — positive green-path test, drop dead let _ = ws
Adds the missing positive counterpart to the no-instance test:
`show 42` with `instance Show Int` PRESENT must typecheck green.
This guards against registry-keying or threading bugs that would
otherwise sneak past the negative-only test (an empty registry at
typecheck time, or a key shape mismatch, would silently fire
no-instance even when the instance exists).

Also drops the dead `let _ = ws;` and its stale comment in
`check_in_workspace` — the line above already consumes
`ws.registry`, so the explicit drop is redundant. The remaining
comment is folded into the registry-threading comment so the
"registry is the only thing threaded" rationale is preserved.
2026-05-09 19:13:32 +02:00
Brummel 3600e82ec2 iter 22b.2.10: no-instance per-fn diagnostic 2026-05-09 19:07:46 +02:00
Brummel b741a8ba05 iter 22b.2.9: fix — superclass-walk tests, simplify class_superclasses map shape 2026-05-09 18:59:15 +02:00
Brummel 7cff741632 iter 22b.2.9: missing-constraint per-fn diagnostic 2026-05-09 18:51:39 +02:00
Brummel afa06a3f3d iter 22b.2.8: fix — fold double-match, IndexMap parity, broader contract test 2026-05-09 18:37:49 +02:00
Brummel 17605a3327 iter 22b.2.8: register class methods in module globals 2026-05-09 18:33:01 +02:00
Brummel a546c5851c iter 22b.2.7: missing-superclass-instance diagnostic 2026-05-09 18:18:12 +02:00
Brummel a9aa248910 iter 22b.2.6: method-name-collision diagnostic 2026-05-09 18:07:52 +02:00
Brummel 634bd5eca3 iter 22b.2.5: overriding-non-existent-method diagnostic 2026-05-09 17:59:10 +02:00
Brummel 257b47625d iter 22b.2.4: constraint-references-unbound-type-var diagnostic 2026-05-09 17:54:20 +02:00
Brummel 4b84e781d4 iter 22b.2.3: invalid-superclass-param class-schema diagnostic 2026-05-09 17:50:29 +02:00
Brummel 928deb9d74 iter 22b.2.2: kind-mismatch class-schema diagnostic 2026-05-09 17:45:27 +02:00
Brummel eb4db9dafc iter 22b.1.2: workspace registry skeleton + coherence checks
Adds the workspace-global typeclass instance registry per Decision 11
"Resolution and monomorphisation". Built at the end of load_workspace
after the DFS over imports completes; keyed by (class-name, type-hash)
where type-hash uses the new canonical::type_hash (16-hex prefix,
parallel to def_hash and module_hash).

Three coherence checks fire from build_registry, each surfacing as a
distinct WorkspaceLoadError variant:

- OrphanInstance: `instance C T` not in C's or T's defining module.
- DuplicateInstance: two entries share the same (class, type-hash) key.
- MissingMethod: instance omits a required (non-default) method.

The CLI's workspace_error_to_diagnostic is extended with the three new
codes (orphan-instance / duplicate-instance / missing-method).

All existing Workspace { ... } construction sites get the new
`registry` field, defaulting to Registry::default() at synthetic /
test-only paths and threading through ws.registry.clone() at codepath
sites that already hold a real workspace.

Includes hash-stability regression tests (iter22b1_schema_extension_*
and iter22b1_classdef_empty_optionals_hash_stable) and the empty-
registry positive test against examples/sum.ail.json. Test count:
288 → 291 (3 new tests, all pass).
2026-05-09 12:37:00 +02:00