iter 24.3: fn print + E2E + 3 compiler-path repairs; milestone 24 close

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.
This commit is contained in:
2026-05-13 04:07:36 +02:00
parent c04c07fe86
commit 246b5c7455
14 changed files with 858 additions and 43 deletions
+25 -23
View File
@@ -61,32 +61,34 @@ context. Pick the next milestone from P1.)_
runtime"); spec 2026-05-09-22-typeclasses §22b.4b ("Show#Int
needs an `int_to_str` primitive returning heap-allocated Str").
- [~] **\[milestone\]** Post-22 Prelude — Show + print rewire — ship
`Show` typeclass with `Show Int/Bool/Str/Float` instances; rewire
`print` through `Show.show`. Originally queued as 22b.4 in the
typeclass milestone, kept on hold pending demand and the
heap-`Str` prerequisite. Spec `docs/specs/2026-05-12-24-show-print.md`
approved; iter 24.1 (runtime + codegen for two new heap-Str
primitives `bool_to_str` + `str_clone`) shipped 2026-05-12 @ f38bad8.
Iters 24.2 (prelude `class Show` + four instances) and 24.3
(polymorphic `print` free fn + E2E) deferred — adding `class Show`
to the prelude collides with the user-class `Show` declared by
14 test fixtures under `examples/test_22b{1,2,3}_*.ail.json` (plus
hardcoded `"Show"` / `"show"` assertions in `crates/ail/tests/typeclass_22b{2,3}.rs`)
through the workspace-global method-name-collision pre-pass at
`crates/ailang-core/src/workspace.rs:547`. Resumes once the
dependency below ships and the spec re-brainstorms against the
post-retirement architecture.
- context: brainstorm 2026-05-12 (iter 23.5 wrap); deferral
2026-05-13 (user-direction Option C after plan-recon flagged the
collision; iter 24.1 retained as standalone runtime infrastructure).
- ready for re-brainstorm — the `MethodNameCollision` workaround
that blocked the original spec retired in mq.3 (2026-05-13).
Fresh brainstorm re-derives the spec against the post-retirement
architecture (type-driven dispatch, class-ref canonical form).
- [x] **\[milestone\]** Post-22 Prelude — Show + print rewire — shipped
2026-05-13 as iters 24.1 (heap-Str runtime + codegen for `bool_to_str`
+ `str_clone`, f38bad8), 24.2 (prelude `class Show` + four primitive
instances Int/Bool/Str/Float + 22b TShow/tshow migration), and 24.3
(polymorphic `fn print : forall a. Show a => (a borrow) -> () !IO`
+ positive 4-prim E2E + user-ADT E2E + Show-aware NoInstance
diagnostic + DESIGN.md amendments to §"Prelude (built-in) classes"
and §"Float semantics"). The `MethodNameCollision` workaround that
blocked the original spec retired in mq.3 (2026-05-13); spec
`docs/specs/2026-05-13-24-show-print.md` re-derived 24.2 + 24.3
against the post-mq architecture.
- context: spec `docs/specs/2026-05-13-24-show-print.md`; per-iter
journals 2026-05-12-iter-24.1, 2026-05-13-iter-24.2, 2026-05-13-iter-24.3.
## P2 — Medium-term
- [ ] **\[milestone\]** Retire `io/print_int` / `io/print_bool` /
`io/print_float` effect-ops + migrate example corpus to `print`.
Bulk text substitution `do io/print_<T> x``do print x` across
`examples/*.ail.json` (~86 fixtures affected). Per-type effect-ops
are deleted from `crates/ailang-check/src/builtins.rs`,
`crates/ailang-codegen/src/lib.rs::lower_app` arms, and the
corresponding runtime C glue.
- context: post-milestone-24 mechanical follow-up; the architecture-
shipping milestone (24) and corpus-migration milestone (this) are
separate so migration runs against a frozen architecture. Same
call milestone 23 made for `==` / `eq`.
- [ ] **\[feature\]** Operator routing through `Eq` / `Ord``==`,
`<` etc. resolved via the typeclass instead of the built-in
primitive comparators. No commitment; gated on bench re-baselining