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:
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"iter_id": "24.3",
|
||||||
|
"date": "2026-05-13",
|
||||||
|
"mode": "standard",
|
||||||
|
"outcome": "DONE",
|
||||||
|
"tasks_total": 8,
|
||||||
|
"tasks_completed": 8,
|
||||||
|
"reloops_per_task": {
|
||||||
|
"1": 0,
|
||||||
|
"2": 1,
|
||||||
|
"3": 0,
|
||||||
|
"4": 0,
|
||||||
|
"5": 0,
|
||||||
|
"6": 0,
|
||||||
|
"7": 0,
|
||||||
|
"8": 0
|
||||||
|
},
|
||||||
|
"review_loops_spec": 0,
|
||||||
|
"review_loops_quality": 0,
|
||||||
|
"blocked_reason": null,
|
||||||
|
"notes": {
|
||||||
|
"plan_defects_fixed_inline": 3,
|
||||||
|
"plan_defect_summary": [
|
||||||
|
"MonoTarget::FreeFn::type_args bare-type-cons normalisation (mono.rs, 2 sites)",
|
||||||
|
"Codegen cross-module reference fallback for post-mono bodies (codegen/lib.rs, 3 sites)",
|
||||||
|
"synth FreeFnCall arm constraint-residual push (lib.rs, 1 site)"
|
||||||
|
],
|
||||||
|
"task_2_reloop_cause": "AST-shape assumption: plan asserted Term::Lam wrapper for FnDef.body; actual top-level FnDef.body is the inner body. Test corrected on first reloop.",
|
||||||
|
"tests_added": 4,
|
||||||
|
"tests_passed_post_iter": 556,
|
||||||
|
"tests_passed_pre_iter": 552,
|
||||||
|
"bench_compile_check": "exit 1 (1 noise-class regression; 8th consecutive audit-grade observation)",
|
||||||
|
"bench_cross_lang": "exit 0 (25/25 stable)",
|
||||||
|
"bench_check": "exit 1 (0 regressions, 2 improvements beyond tolerance on latency.explicit_at_rc.* — documented noise envelope)",
|
||||||
|
"files_created": 6,
|
||||||
|
"files_modified": 6
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
//! IR-shape pin for milestone 24.3's `print` polymorphic free fn.
|
||||||
|
//!
|
||||||
|
//! Property protected: the post-mono `print__Int` `Def::Fn.body` is
|
||||||
|
//! structurally `Term::Let { name: "s", value: App(show__Int, [x]),
|
||||||
|
//! body: Term::Do { op: "io/print_str", args: [s] } }`. The explicit
|
||||||
|
//! let-binder around `show__Int x` is load-bearing for the heap-Str RC
|
||||||
|
//! discipline (eob.1 Str carve-out at `drop_symbol_for_binder` requires
|
||||||
|
//! a let-binder to attach the rc-dec to). If a future codegen / mono
|
||||||
|
//! refactor inlines the let-binder away, this pin fires and surfaces
|
||||||
|
//! the regression BEFORE the E2E runtime stats produce a confusing
|
||||||
|
//! "memory leak" diagnostic.
|
||||||
|
//!
|
||||||
|
//! Note: `FnDef.body: Term` is the *inner* function body — top-level
|
||||||
|
//! fns carry their parameter list separately on `FnDef.params`, so no
|
||||||
|
//! outer `Term::Lam` wraps the body. This contrasts with instance
|
||||||
|
//! method bodies (which carry a `Term::Lam` because they are anonymous
|
||||||
|
//! function values inside `InstanceMethod.body`).
|
||||||
|
|
||||||
|
use ailang_core::ast::{Def, Term};
|
||||||
|
use ailang_core::workspace::load_workspace;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
fn fixture_path() -> PathBuf {
|
||||||
|
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
d.pop();
|
||||||
|
d.pop();
|
||||||
|
d.join("examples").join("show_print_smoke.ail.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_int_body_preserves_explicit_let_binder() {
|
||||||
|
let ws = load_workspace(&fixture_path()).expect("workspace loads");
|
||||||
|
let diags = ailang_check::check_workspace(&ws);
|
||||||
|
assert!(diags.is_empty(), "typecheck diagnostics: {diags:?}");
|
||||||
|
let post_mono = ailang_check::monomorphise_workspace(&ws).expect("mono green");
|
||||||
|
|
||||||
|
let prelude_mod = post_mono
|
||||||
|
.modules
|
||||||
|
.get("prelude")
|
||||||
|
.expect("prelude module present");
|
||||||
|
|
||||||
|
let print_int = prelude_mod
|
||||||
|
.defs
|
||||||
|
.iter()
|
||||||
|
.find_map(|d| match d {
|
||||||
|
Def::Fn(f) if f.name == "print__Int" => Some(f),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.expect("print__Int mono symbol not found in prelude module");
|
||||||
|
|
||||||
|
// Body shape: Term::Let { name: "s",
|
||||||
|
// value: Term::App(show__Int, [x]),
|
||||||
|
// body: Term::Do { op: "io/print_str", args: [s] } }
|
||||||
|
let (let_value, let_body) = match &print_int.body {
|
||||||
|
Term::Let { name, value, body } => {
|
||||||
|
assert_eq!(name, "s", "let-binder name expected 's', got {name:?}");
|
||||||
|
(value.as_ref(), body.as_ref())
|
||||||
|
}
|
||||||
|
other => panic!(
|
||||||
|
"print__Int.body is not Term::Let — let-binder was optimised away or never inserted. Got: {other:?}"
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Inner App should reference show__Int (post-mono symbol).
|
||||||
|
let app_fn = match let_value {
|
||||||
|
Term::App { callee, .. } => callee.as_ref(),
|
||||||
|
other => panic!("print__Int let-value is not Term::App, got: {other:?}"),
|
||||||
|
};
|
||||||
|
let app_fn_name = match app_fn {
|
||||||
|
Term::Var { name } => name,
|
||||||
|
other => panic!("let-value's fn position is not Term::Var, got: {other:?}"),
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
app_fn_name, "show__Int",
|
||||||
|
"post-mono let-value should call show__Int, got: {app_fn_name}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Inner body should be a Do invoking io/print_str.
|
||||||
|
match let_body {
|
||||||
|
Term::Do { op, args, .. } => {
|
||||||
|
assert_eq!(op, "io/print_str", "let-body Do op expected 'io/print_str', got {op:?}");
|
||||||
|
assert_eq!(args.len(), 1, "io/print_str expects 1 arg, got {}", args.len());
|
||||||
|
}
|
||||||
|
other => panic!("print__Int let-body is not Term::Do, got: {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
//! Pins the Show-aware `no-instance` diagnostic shipped in milestone 24.3.
|
||||||
|
//!
|
||||||
|
//! Property protected: calling `print` on a function type fires the
|
||||||
|
//! `no-instance` diagnostic with a Show-aware message that
|
||||||
|
//! cross-references DESIGN.md §"Prelude (built-in) classes", so the
|
||||||
|
//! LLM author immediately learns which types ship with built-in Show
|
||||||
|
//! and how to declare their own instance for a user type.
|
||||||
|
|
||||||
|
use ailang_check::check_workspace;
|
||||||
|
use ailang_core::workspace::load_workspace;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
fn fixture(name: &str) -> PathBuf {
|
||||||
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("../../examples")
|
||||||
|
.join(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_on_fn_type_fires_show_aware_no_instance() {
|
||||||
|
let ws = load_workspace(&fixture("show_no_instance.ail.json")).expect("load");
|
||||||
|
let diags = check_workspace(&ws);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!diags.is_empty(),
|
||||||
|
"expected NoInstance Show diagnostic, got no diagnostics"
|
||||||
|
);
|
||||||
|
|
||||||
|
let no_inst = diags
|
||||||
|
.iter()
|
||||||
|
.find(|d| d.code == "no-instance")
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
panic!("expected diagnostic with code 'no-instance', got: {diags:#?}")
|
||||||
|
});
|
||||||
|
|
||||||
|
// Must mention Show.
|
||||||
|
assert!(
|
||||||
|
no_inst.message.contains("Show"),
|
||||||
|
"expected Show-aware NoInstance diagnostic, got message: {:?}",
|
||||||
|
no_inst.message
|
||||||
|
);
|
||||||
|
|
||||||
|
// Must cross-reference DESIGN.md §"Prelude (built-in) classes"
|
||||||
|
// verbatim — that's the canonical anchor naming which types
|
||||||
|
// ship with Show.
|
||||||
|
assert!(
|
||||||
|
no_inst.message.contains("Prelude (built-in) classes"),
|
||||||
|
"expected DESIGN.md §Prelude (built-in) classes cross-reference, got message: {:?}",
|
||||||
|
no_inst.message
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
//! End-to-end tests for the `print` polymorphic helper shipped in
|
||||||
|
//! milestone 24.3.
|
||||||
|
//!
|
||||||
|
//! Each test compiles a `.ail.json` workspace via the `ail build`
|
||||||
|
//! subcommand, runs the resulting native binary, and asserts on stdout.
|
||||||
|
//!
|
||||||
|
//! Properties protected:
|
||||||
|
//! - `print_primitives_smoke_runs_end_to_end`: `print` at four primitive
|
||||||
|
//! types (Int / Bool / Str / Float) emits the expected textual
|
||||||
|
//! representation of each value via the prelude Show instances +
|
||||||
|
//! `io/print_str`. The four `print__T` mono symbols synthesise from
|
||||||
|
//! the prelude `instance prelude.Show T` bodies and route through the
|
||||||
|
//! corresponding `<T>_to_str` runtime primitive.
|
||||||
|
//! - `print_user_adt_runs_end_to_end`: `print` composes with a
|
||||||
|
//! user-declared `instance prelude.Show IntBox` to emit a user-ADT's
|
||||||
|
//! structural representation. Confirms that the post-mono synthesised
|
||||||
|
//! `print__<UserType>` body's nested `show x` call rewrites to the
|
||||||
|
//! user instance's `show__<UserType>` mono symbol and that the
|
||||||
|
//! cross-module reference from `prelude.print__<UserType>` to
|
||||||
|
//! `<user_module>.show__<UserType>` lowers cleanly through codegen.
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn fixture_path(name: &str) -> PathBuf {
|
||||||
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("../../examples")
|
||||||
|
.join(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_and_run(fixture: &str) -> String {
|
||||||
|
let src = fixture_path(fixture);
|
||||||
|
let out = std::env::temp_dir().join(format!("ail_{}.bin", fixture.replace('.', "_")));
|
||||||
|
|
||||||
|
let build = Command::new(env!("CARGO_BIN_EXE_ail"))
|
||||||
|
.args(["build", src.to_str().unwrap(), "-o", out.to_str().unwrap()])
|
||||||
|
.output()
|
||||||
|
.expect("ail build");
|
||||||
|
assert!(
|
||||||
|
build.status.success(),
|
||||||
|
"ail build failed for {fixture}:\nstdout: {}\nstderr: {}",
|
||||||
|
String::from_utf8_lossy(&build.stdout),
|
||||||
|
String::from_utf8_lossy(&build.stderr),
|
||||||
|
);
|
||||||
|
|
||||||
|
let run = Command::new(&out).output().expect("run binary");
|
||||||
|
assert!(
|
||||||
|
run.status.success(),
|
||||||
|
"binary exited non-zero:\nstdout: {}\nstderr: {}",
|
||||||
|
String::from_utf8_lossy(&run.stdout),
|
||||||
|
String::from_utf8_lossy(&run.stderr),
|
||||||
|
);
|
||||||
|
String::from_utf8_lossy(&run.stdout).trim().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_primitives_smoke_runs_end_to_end() {
|
||||||
|
let stdout = build_and_run("show_print_smoke.ail.json");
|
||||||
|
// print 42 → "42\n" (int_to_str + puts)
|
||||||
|
// print true → "true\n" (bool_to_str + puts)
|
||||||
|
// print "hello" → "hello\n" (str_clone + puts)
|
||||||
|
// print 3.14 → "3.14\n" (float_to_str / libc %g + puts)
|
||||||
|
// puts emits each Str + a trailing newline; trimmed output is
|
||||||
|
// "42\ntrue\nhello\n3.14".
|
||||||
|
assert_eq!(stdout, "42\ntrue\nhello\n3.14", "got: {stdout:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn print_user_adt_runs_end_to_end() {
|
||||||
|
let stdout = build_and_run("show_user_adt.ail.json");
|
||||||
|
// print (MkIntBox 7) → "7\n" (via user instance prelude.Show
|
||||||
|
// IntBox that unwraps via match + int_to_str).
|
||||||
|
assert_eq!(stdout, "7", "got: {stdout:?}");
|
||||||
|
}
|
||||||
@@ -776,6 +776,23 @@ impl CheckError {
|
|||||||
orderability per IEEE-754); see DESIGN.md §\"Float semantics\".",
|
orderability per IEEE-754); see DESIGN.md §\"Float semantics\".",
|
||||||
d.message
|
d.message
|
||||||
);
|
);
|
||||||
|
} else if class == "prelude.Show" {
|
||||||
|
// Iter 24.3: Show-aware addendum on `NoInstance`. Fires
|
||||||
|
// for any type lacking a Show instance — most commonly
|
||||||
|
// a function type (`print f` where f is bare-fn-typed)
|
||||||
|
// or a user type the LLM-author forgot to give an
|
||||||
|
// instance for. Cross-references DESIGN.md §"Prelude
|
||||||
|
// (built-in) classes" so the author learns which types
|
||||||
|
// ship with built-in Show immediately.
|
||||||
|
d.message = format!(
|
||||||
|
"{} — `print` and `show` require a Show instance. \
|
||||||
|
Built-in Show ships for Int, Bool, Str, Float in \
|
||||||
|
the prelude; see DESIGN.md §\"Prelude (built-in) \
|
||||||
|
classes\". User types declare their own \
|
||||||
|
`instance prelude.Show <T>` in the type's defining \
|
||||||
|
module per Decision 11 coherence.",
|
||||||
|
d.message
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d
|
d
|
||||||
@@ -2800,10 +2817,52 @@ pub(crate) fn synth(
|
|||||||
// by bare name); the source-level `name` may be a
|
// by bare name); the source-level `name` may be a
|
||||||
// dot-qualified form (`prefix.suffix`) the synth started
|
// dot-qualified form (`prefix.suffix`) the synth started
|
||||||
// with.
|
// with.
|
||||||
if let (Type::Forall { vars, constraints: _, body }, Some((owner, unqualified_name))) =
|
if let (Type::Forall { vars, constraints, body }, Some((owner, unqualified_name))) =
|
||||||
(&raw, &free_fn_owner)
|
(&raw, &free_fn_owner)
|
||||||
{
|
{
|
||||||
let (metas, inst) = instantiate(vars, body, counter);
|
let (metas, inst) = instantiate(vars, body, counter);
|
||||||
|
// Iter 24.3: push a residual for each declared constraint
|
||||||
|
// of the poly free fn with the rigid var substituted by
|
||||||
|
// its fresh metavar. The discharge loop at the enclosing
|
||||||
|
// `check_fn`'s post-synth phase resolves the residual
|
||||||
|
// against the workspace registry (fully-concrete after
|
||||||
|
// App-arm unification) and fires `NoInstance` if no
|
||||||
|
// instance ships for the unified type. Without this push,
|
||||||
|
// `print f` at a function type `f : Int -> Int` would
|
||||||
|
// typecheck silently — the `Show f`-shaped obligation
|
||||||
|
// would only surface at codegen as an `unknown variable`
|
||||||
|
// error from the synthesised mono body.
|
||||||
|
//
|
||||||
|
// The substitution mirrors `instantiate`'s body-side
|
||||||
|
// mapping: position-by-position pairing of `vars` with
|
||||||
|
// the freshly-generated `metas`. The discharge path
|
||||||
|
// post-`subst.apply` produces the same concrete type
|
||||||
|
// that the App-arm unified into the metavars.
|
||||||
|
let cmapping: BTreeMap<String, Type> = vars
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.zip(metas.iter().cloned())
|
||||||
|
.collect();
|
||||||
|
for c in constraints {
|
||||||
|
let c_class = qualify_class_ref_in_check(&c.class, owner);
|
||||||
|
let c_ty = substitute_rigids(&c.type_, &cmapping);
|
||||||
|
// Look up the class's method name via the workspace
|
||||||
|
// class index; we need it for the `ResidualConstraint`'s
|
||||||
|
// `method` field (used by `NoInstance`'s rendering).
|
||||||
|
let method_name = env
|
||||||
|
.class_methods
|
||||||
|
.iter()
|
||||||
|
.find_map(|((cls, m), _)| {
|
||||||
|
if *cls == c_class { Some(m.clone()) } else { None }
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
residuals.push(ResidualConstraint {
|
||||||
|
class: c_class,
|
||||||
|
type_: c_ty,
|
||||||
|
method: method_name,
|
||||||
|
candidates: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
free_fn_calls.push(FreeFnCall {
|
free_fn_calls.push(FreeFnCall {
|
||||||
name: unqualified_name.clone(),
|
name: unqualified_name.clone(),
|
||||||
owner_module: owner.clone(),
|
owner_module: owner.clone(),
|
||||||
|
|||||||
@@ -687,7 +687,24 @@ pub fn collect_mono_targets(
|
|||||||
for m in &fc.metas {
|
for m in &fc.metas {
|
||||||
let resolved = subst.apply(m);
|
let resolved = subst.apply(m);
|
||||||
if crate::is_fully_concrete(&resolved) {
|
if crate::is_fully_concrete(&resolved) {
|
||||||
type_args.push(resolved);
|
// Iter 24.3: normalise bare type-cons references to the
|
||||||
|
// canonical `<owner>.<bare>` form before they enter the
|
||||||
|
// MonoTarget. The synthesised body for a poly free fn
|
||||||
|
// lives in the fn's `owner_module` (e.g. `prelude` for
|
||||||
|
// `print`), but its `type_args` typically come from
|
||||||
|
// user-defining modules. If left bare, the synthesised
|
||||||
|
// body's `param_tys` carry bare references that later
|
||||||
|
// mono-walks (in the synthesised body's caller-module
|
||||||
|
// context — i.e. the fn's owner module) cannot resolve
|
||||||
|
// back to the registry's qualified instance key — and
|
||||||
|
// any nested class-method call (e.g. `show x` inside
|
||||||
|
// `print`'s body) silently produces no mono target,
|
||||||
|
// leaving the synthesised body referencing a bare class
|
||||||
|
// method that codegen later rejects.
|
||||||
|
let normalised = env
|
||||||
|
.workspace_registry
|
||||||
|
.normalize_type_for_lookup(module_name, &resolved);
|
||||||
|
type_args.push(normalised);
|
||||||
} else if contains_rigid_var(&resolved) {
|
} else if contains_rigid_var(&resolved) {
|
||||||
has_rigid = true;
|
has_rigid = true;
|
||||||
break;
|
break;
|
||||||
@@ -1270,7 +1287,15 @@ pub(crate) fn collect_residuals_ordered(
|
|||||||
.map(|m| {
|
.map(|m| {
|
||||||
let resolved = subst.apply(m);
|
let resolved = subst.apply(m);
|
||||||
if crate::is_fully_concrete(&resolved) {
|
if crate::is_fully_concrete(&resolved) {
|
||||||
resolved
|
// Iter 24.3: canonical-form normalisation — see
|
||||||
|
// matching site in `collect_mono_targets` for
|
||||||
|
// rationale. Must agree byte-identically with
|
||||||
|
// that site or Phase 3 rewrite cursor produces
|
||||||
|
// a mono-symbol name that differs from the
|
||||||
|
// Phase 2 synthesis name.
|
||||||
|
env
|
||||||
|
.workspace_registry
|
||||||
|
.normalize_type_for_lookup(module_name, &resolved)
|
||||||
} else {
|
} else {
|
||||||
Type::unit()
|
Type::unit()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1980,11 +1980,24 @@ impl<'a> Emitter<'a> {
|
|||||||
// Logic identical to the typechecker (see `synth` for `Term::Var`).
|
// Logic identical to the typechecker (see `synth` for `Term::Var`).
|
||||||
if name.matches('.').count() == 1 {
|
if name.matches('.').count() == 1 {
|
||||||
let (prefix, suffix) = name.split_once('.').expect("checked");
|
let (prefix, suffix) = name.split_once('.').expect("checked");
|
||||||
let target_module = self.import_map.get(prefix).cloned().ok_or_else(|| {
|
// Iter 24.3: fall back to direct module-name lookup when
|
||||||
CodegenError::Internal(format!(
|
// the prefix isn't in the current module's import_map. A
|
||||||
"cross-module call `{name}`: prefix `{prefix}` not in import map"
|
// post-mono synthesised body may carry cross-module
|
||||||
))
|
// references to modules its source template didn't import
|
||||||
})?;
|
// (e.g. `prelude.print__<UserType>` synthesised in
|
||||||
|
// `prelude` calls `show_user_adt.show__<UserType>` even
|
||||||
|
// though prelude does not import user modules). See the
|
||||||
|
// matching fallback in `resolve_top_level_fn` for the
|
||||||
|
// companion change on the fn-pointer Var-resolution path.
|
||||||
|
let target_module = match self.import_map.get(prefix).cloned() {
|
||||||
|
Some(m) => m,
|
||||||
|
None if self.module_user_fns.contains_key(prefix) => prefix.to_string(),
|
||||||
|
None => {
|
||||||
|
return Err(CodegenError::Internal(format!(
|
||||||
|
"cross-module call `{name}`: prefix `{prefix}` not in import map"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
};
|
||||||
// iter 23.4: codegen-time poly-call dispatch removed. Post-mono
|
// iter 23.4: codegen-time poly-call dispatch removed. Post-mono
|
||||||
// every poly call site has been rewritten by `rewrite_mono_calls`
|
// every poly call site has been rewritten by `rewrite_mono_calls`
|
||||||
// to a monomorphic symbol, so the lookup-ladder below sees only
|
// to a monomorphic symbol, so the lookup-ladder below sees only
|
||||||
@@ -2200,7 +2213,22 @@ impl<'a> Emitter<'a> {
|
|||||||
fn resolve_top_level_fn(&self, name: &str) -> Option<(String, FnSig)> {
|
fn resolve_top_level_fn(&self, name: &str) -> Option<(String, FnSig)> {
|
||||||
if name.matches('.').count() == 1 {
|
if name.matches('.').count() == 1 {
|
||||||
let (prefix, suffix) = name.split_once('.')?;
|
let (prefix, suffix) = name.split_once('.')?;
|
||||||
let target = self.import_map.get(prefix)?;
|
// Iter 24.3: dotted form resolves through the current
|
||||||
|
// module's import_map first (the standard cross-module
|
||||||
|
// reference path). If the prefix isn't in import_map,
|
||||||
|
// fall back to a direct module-name lookup against
|
||||||
|
// `module_user_fns` — a post-mono synthesised body may
|
||||||
|
// carry cross-module references to modules its source
|
||||||
|
// template didn't import (e.g. `prelude.print__<UserType>`
|
||||||
|
// synthesised in `prelude` calls `show_user_adt.show__<UserType>`
|
||||||
|
// even though prelude does not import user modules; this is
|
||||||
|
// a valid post-mono construct because both ends were
|
||||||
|
// independently typechecked under their original module
|
||||||
|
// contexts before mono ran).
|
||||||
|
let target = match self.import_map.get(prefix) {
|
||||||
|
Some(m) => m,
|
||||||
|
None => prefix,
|
||||||
|
};
|
||||||
let sig = self.module_user_fns.get(target)?.get(suffix)?.clone();
|
let sig = self.module_user_fns.get(target)?.get(suffix)?.clone();
|
||||||
return Some((format!("@ail_{target}_{suffix}_clos"), sig));
|
return Some((format!("@ail_{target}_{suffix}_clos"), sig));
|
||||||
}
|
}
|
||||||
@@ -2748,7 +2776,24 @@ impl<'a> Emitter<'a> {
|
|||||||
}
|
}
|
||||||
if name.matches('.').count() == 1 {
|
if name.matches('.').count() == 1 {
|
||||||
let (prefix, suffix) = name.split_once('.').expect("checked");
|
let (prefix, suffix) = name.split_once('.').expect("checked");
|
||||||
if let Some(target) = self.import_map.get(prefix) {
|
// Iter 24.3: try the current module's import_map
|
||||||
|
// first (standard cross-module reference), then
|
||||||
|
// fall back to a direct module-name lookup for
|
||||||
|
// post-mono synthesised cross-module references
|
||||||
|
// (see `resolve_top_level_fn` and the cross-module
|
||||||
|
// call arm in `lower_app` for matching fallbacks).
|
||||||
|
let target_opt: Option<&str> = self
|
||||||
|
.import_map
|
||||||
|
.get(prefix)
|
||||||
|
.map(|s| s.as_str())
|
||||||
|
.or_else(|| {
|
||||||
|
if self.module_def_ail_types.contains_key(prefix) {
|
||||||
|
Some(prefix)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if let Some(target) = target_opt {
|
||||||
if let Some(ty) = self
|
if let Some(ty) = self
|
||||||
.module_def_ail_types
|
.module_def_ail_types
|
||||||
.get(target)
|
.get(target)
|
||||||
|
|||||||
+25
-10
@@ -1898,16 +1898,21 @@ diagnostic cross-referencing this section.
|
|||||||
|
|
||||||
Milestone 24 amends the above further: the prelude ships `class Show
|
Milestone 24 amends the above further: the prelude ships `class Show
|
||||||
a where show : (a borrow) -> Str` and primitive `Show Int`,
|
a where show : (a borrow) -> Str` and primitive `Show Int`,
|
||||||
`Show Bool`, `Show Str`, `Show Float` instances. Float **is** included
|
`Show Bool`, `Show Str`, `Show Float` instances (iter 24.2). Float
|
||||||
in Show (unlike Eq/Ord) — IEEE-754 makes structural equality and total
|
**is** included in Show (unlike Eq/Ord) — IEEE-754 makes structural
|
||||||
ordering semantically dubious, but textual representation of a Float
|
equality and total ordering semantically dubious, but textual
|
||||||
is well-defined modulo the NaN-spelling caveat in §"Float semantics".
|
representation of a Float is well-defined modulo the NaN-spelling
|
||||||
Each `Show <T>` instance body is a single-application lambda invoking
|
caveat in §"Float semantics". Each `Show <T>` instance body is a
|
||||||
the corresponding runtime primitive (`int_to_str`, `bool_to_str`,
|
single-application lambda invoking the corresponding runtime primitive
|
||||||
`str_clone`, `float_to_str`); no codegen intercept is required. The
|
(`int_to_str`, `bool_to_str`, `str_clone`, `float_to_str`); no codegen
|
||||||
polymorphic helper `print : forall a. Show a => a -> () !IO` ships in
|
intercept is required. The polymorphic helper `print : forall a. Show
|
||||||
the same milestone as the second iteration (24.3) and routes through
|
a => a -> () !IO` shipped in iter 24.3 with body
|
||||||
`show` and `io/print_str`.
|
`\x -> let s = show x in do io/print_str s` (explicit let-binder for
|
||||||
|
heap-Str RC discipline per eob.1 Str carve-out). The let-binder is
|
||||||
|
structurally pinned by `crates/ail/tests/print_mono_body_shape.rs`.
|
||||||
|
Routing through `print` replaces the ad-hoc `io/print_int|bool|float`
|
||||||
|
idiom for new code; retiring the per-type effect-ops is queued as a
|
||||||
|
P2 follow-up.
|
||||||
|
|
||||||
Primitive output goes through `io/print_int` / `io/print_bool` /
|
Primitive output goes through `io/print_int` / `io/print_bool` /
|
||||||
`io/print_str` directly.
|
`io/print_str` directly.
|
||||||
@@ -2446,6 +2451,16 @@ no `f32` variant. The runtime / codegen contract:
|
|||||||
spelling and `io/print_float` is for human-readable output, not
|
spelling and `io/print_float` is for human-readable output, not
|
||||||
round-trip.
|
round-trip.
|
||||||
|
|
||||||
|
The same libc-`%g` rendering applies to `show 1.5` / `show nan` /
|
||||||
|
`show inf` via `instance Show Float` (which calls `float_to_str`
|
||||||
|
internally — see §"Prelude (built-in) classes" for the Show ship).
|
||||||
|
The NaN-spelling caveat above is observable via both
|
||||||
|
`do io/print_float x` and `do print x` at the same `x`; the rendering
|
||||||
|
is libc-version-dependent and target-libc-specific. AILang does NOT
|
||||||
|
canonicalise Float textual representation; the LLM-author who needs
|
||||||
|
deterministic Float rendering for cross-platform test fixtures should
|
||||||
|
bypass `show` / `print` and emit a custom formatter.
|
||||||
|
|
||||||
These are the Rust / Swift / standard-LLVM defaults — not
|
These are the Rust / Swift / standard-LLVM defaults — not
|
||||||
research-grade reproducibility guarantees. The stronger guarantee
|
research-grade reproducibility guarantees. The stronger guarantee
|
||||||
(e.g. Pythonic `float.fromhex`-level bit reproducibility across
|
(e.g. Pythonic `float.fromhex`-level bit reproducibility across
|
||||||
|
|||||||
@@ -0,0 +1,238 @@
|
|||||||
|
# iter 24.3 — fn print polymorphic free fn + E2E + DESIGN.md sync; milestone 24 close
|
||||||
|
|
||||||
|
**Date:** 2026-05-13
|
||||||
|
**Started from:** c04c07f
|
||||||
|
**Status:** DONE
|
||||||
|
**Tasks completed:** 8 of 8
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Ships `fn print : forall a. Show a => (a borrow) -> () !IO` in
|
||||||
|
`examples/prelude.ail.json` with explicit-let body
|
||||||
|
`\x -> let s = show x in do io/print_str s`. The let-binder is
|
||||||
|
structurally pinned by `crates/ail/tests/print_mono_body_shape.rs`
|
||||||
|
(post-mono `print__Int.body` is `Term::Let → Term::App(show__Int) →
|
||||||
|
Term::Do(io/print_str)`). Three new E2E fixtures + tests verify the
|
||||||
|
full path: `show_print_smoke` (4 primitives) and `show_user_adt`
|
||||||
|
(`data IntBox` + `instance prelude.Show IntBox` + `print (MkIntBox 7)`)
|
||||||
|
both compile, run, and produce expected stdout; `show_no_instance`
|
||||||
|
fires a Show-aware `NoInstance` diagnostic with the canonical
|
||||||
|
DESIGN.md cross-reference. DESIGN.md §"Prelude (built-in) classes"
|
||||||
|
flips `print` from "ships in 24.3" to "shipped in iter 24.3" with the
|
||||||
|
explicit-let body + pin reference. DESIGN.md §"Float semantics" gains
|
||||||
|
a Show-Float NaN-spelling cross-reference paragraph. Roadmap P1
|
||||||
|
"Post-22 Prelude — Show + print rewire" entry checked off; new P2
|
||||||
|
entry "Retire `io/print_int|bool|float` effect-ops + migrate example
|
||||||
|
corpus to `print`" inserted at top of P2. **Three plan-defects-fixed-
|
||||||
|
inline** surfaced when running the user-ADT E2E: (a) `MonoTarget::
|
||||||
|
FreeFn::type_args` were carrying bare type-cons references that broke
|
||||||
|
the post-mono walk's registry lookup when the synthesised body lived
|
||||||
|
in a different module from the type — fixed by normalising via
|
||||||
|
`workspace_registry.normalize_type_for_lookup` at two
|
||||||
|
`mono.rs` collection sites; (b) codegen's cross-module fn resolution
|
||||||
|
went through `import_map`, but post-mono synthesised bodies may
|
||||||
|
reference modules their source template didn't import — fixed by
|
||||||
|
falling back to direct `module_user_fns` lookup at three codegen
|
||||||
|
sites (`resolve_top_level_fn`, `lower_app` cross-module arm,
|
||||||
|
`synth_with_extras` Var arm); (c) the synth FreeFnCall arm didn't push
|
||||||
|
residuals for declared constraints, so `Show (Int -> Int)` never
|
||||||
|
reached the typecheck-time discharge logic — fixed by walking
|
||||||
|
`Type::Forall.constraints` at the FreeFnCall site and pushing one
|
||||||
|
residual per constraint with the fresh-metavar substitution. Full
|
||||||
|
`cargo test --workspace` 556 passed / 0 failed (was 552 post-24.2,
|
||||||
|
+4 new = 1 print_mono_body_shape + 2 show_print_e2e + 1
|
||||||
|
show_no_instance_e2e). `bench/cross_lang.py` clean; `bench/compile_check.py`
|
||||||
|
+ `bench/check.py` exit 1 with documented noise-class metrics per the
|
||||||
|
audit-cma lineage envelope (baseline pristine, 8th consecutive
|
||||||
|
audit-grade observation). Milestone 24 closes structurally; only the
|
||||||
|
audit pipeline remains.
|
||||||
|
|
||||||
|
## Per-task notes
|
||||||
|
|
||||||
|
- iter 24.3.1: Appended `fn print` to `examples/prelude.ail.json`
|
||||||
|
after `fn ge` (last def pre-edit). 20 defs total (was 19). Body
|
||||||
|
is the literal `Term::Let { name: "s", value: App(show, [x]), body:
|
||||||
|
Do(io/print_str, [s]) }` with the constraint `Show a` bare per
|
||||||
|
mq.1 same-module canonical form. 552 tests stay green.
|
||||||
|
- iter 24.3.2: `crates/ail/tests/print_mono_body_shape.rs` asserts
|
||||||
|
post-mono `print__Int.body` shape. Initial test asserted outer
|
||||||
|
`Term::Lam` wrapper — corrected after the panic surfaced that
|
||||||
|
`FnDef.body: Term` is the *inner* function body for top-level fns
|
||||||
|
(params carried separately on `FnDef.params`). The test now asserts
|
||||||
|
directly `Term::Let → App(show__Int, [x]) → Do(io/print_str, [s])`,
|
||||||
|
faithful to the plan's intent (preserve the explicit-let-binder
|
||||||
|
discipline) while matching the actual AST shape.
|
||||||
|
- iter 24.3.3: `examples/show_print_smoke.ail.json` written with
|
||||||
|
nested `Term::Seq` of four `App(print, [lit])` calls (Int 42, Bool
|
||||||
|
true, Str "hello", Float bits=40091eb851eb851f for 3.14). `ail
|
||||||
|
build` clean; stdout: `42\ntrue\nhello\n3.14` — io/print_str
|
||||||
|
appends a newline via `@puts`.
|
||||||
|
- iter 24.3.4: `examples/show_user_adt.ail.json` written + 2-test
|
||||||
|
`crates/ail/tests/show_print_e2e.rs`. Surfaced three substantive
|
||||||
|
plan-defects-fixed-inline (Concerns below); after fix, both E2E
|
||||||
|
tests pass (`print (MkIntBox 7)` → stdout "7").
|
||||||
|
- iter 24.3.5: Extended NoInstance Float-aware arm in
|
||||||
|
`crates/ailang-check/src/lib.rs:770-779` with a parallel
|
||||||
|
`class == "prelude.Show"` branch. The arm fires for ANY type
|
||||||
|
lacking a Show instance (function types, user types without
|
||||||
|
instance) — cross-references DESIGN.md §"Prelude (built-in)
|
||||||
|
classes" verbatim. Negative fixture `examples/show_no_instance.ail.json`
|
||||||
|
(let-bound `f : Int -> Int` + `print f`) and pin test in
|
||||||
|
`crates/ail/tests/show_no_instance_e2e.rs` (asserts code,
|
||||||
|
Show-substring, Prelude-(built-in)-classes substring). After
|
||||||
|
the constraint-residual-push fix in synth (Concerns below), the
|
||||||
|
diagnostic fires at typecheck.
|
||||||
|
- iter 24.3.6: DESIGN.md §"Prelude (built-in) classes" milestone-24
|
||||||
|
paragraph amended: `print` flipped to past tense ("shipped in iter
|
||||||
|
24.3"), body shape + pin file reference added, retirement
|
||||||
|
follow-up named. DESIGN.md §"Float semantics" gained a new
|
||||||
|
paragraph in the "Unspecified" block cross-referencing `show 1.5`
|
||||||
|
/ `show nan` / `show inf` to `instance Show Float` via
|
||||||
|
`float_to_str`. ~10 lines added net (2697 → 2707).
|
||||||
|
- iter 24.3.7: Roadmap P1 "Post-22 Prelude — Show + print rewire"
|
||||||
|
entry flipped to `[x]` with a closing-summary block naming all
|
||||||
|
three shipped iters (24.1 f38bad8, 24.2 iter-24.2, 24.3 this
|
||||||
|
iter). New P2 entry "Retire `io/print_int|bool|float` effect-ops
|
||||||
|
+ migrate example corpus to `print`" inserted at top of P2,
|
||||||
|
before the existing operator-routing-through-Eq/Ord entry.
|
||||||
|
- iter 24.3.8: Full workspace 556 passed / 0 failed. `prelude_free_fns`
|
||||||
|
5/5 green; `mono_hash_stability` 2/2 green (Eq/Ord hashes
|
||||||
|
unchanged, Show hashes from 24.2 unchanged). `bench/cross_lang.py`
|
||||||
|
exit 0 (25/25 stable). `bench/compile_check.py` exit 1 with 1
|
||||||
|
noise-class regression on a `check_ms.*` metric (regressed metric
|
||||||
|
identity migrates between runs — pattern consistent with the
|
||||||
|
documented noise envelope per audit-cma lineage, 8th consecutive
|
||||||
|
observation). `bench/check.py` exit 1 with 2 improvements beyond
|
||||||
|
tolerance on `latency.explicit_at_rc.*` — same envelope, same
|
||||||
|
conservative call. Baseline pristine.
|
||||||
|
|
||||||
|
## Concerns
|
||||||
|
|
||||||
|
- **Three plan-defects-fixed-inline surfaced during Task 4 (user-ADT
|
||||||
|
E2E).** All three are necessary repairs to make the spec's stated
|
||||||
|
user-ADT trajectory (§"Data flow / print x at user type IntBox"
|
||||||
|
lines 297-310) work end-to-end. The plan did not anticipate them
|
||||||
|
because the test architecture envisioned (Tasks 3+4 sharing one
|
||||||
|
test file) didn't actually exercise the cross-module mono synthesis
|
||||||
|
before this iter; primitive-only smoke worked through the existing
|
||||||
|
pipeline.
|
||||||
|
- (a) **Bare type-cons in `MonoTarget::FreeFn::type_args`.** At
|
||||||
|
mono target-collection (`collect_mono_targets` + `collect_residuals_ordered`
|
||||||
|
free-fn arms), `subst.apply(meta)` returns the unification result
|
||||||
|
in whatever qualification the caller-module's view used. For a
|
||||||
|
user-defined type referenced from `main` (in `show_user_adt`),
|
||||||
|
`IntBox` came out bare. The downstream `synthesise_mono_fn_for_free_fn`
|
||||||
|
then substituted bare `IntBox` everywhere in the synthesised body,
|
||||||
|
and Phase 3 rewrite of the synthesised body (run in PRELUDE
|
||||||
|
caller-module context, where `IntBox` is not a known TypeDef) saw
|
||||||
|
`Type::Con{IntBox}` that didn't normalise to the registry-keyed
|
||||||
|
`show_user_adt.IntBox`. Lookup missed → no `show__IntBox` target
|
||||||
|
scheduled → bare `Var "show"` persisted post-mono. Fix:
|
||||||
|
`mono.rs` lines 685-696 + 1267-1278 normalise via
|
||||||
|
`env.workspace_registry.normalize_type_for_lookup(module_name, &resolved)`
|
||||||
|
before pushing the type into `MonoTarget::FreeFn::type_args`. Same
|
||||||
|
invariant applies symmetric to the existing
|
||||||
|
`r_ty_norm = normalize_type_for_lookup(...)` calls already in
|
||||||
|
`collect_mono_targets`'s class-method arm.
|
||||||
|
- (b) **Codegen cross-module references via import_map.** Post
|
||||||
|
fix-(a), the synthesised body now correctly references
|
||||||
|
`show_user_adt.show__cb5eb497` from inside `prelude.print__cb5eb497`.
|
||||||
|
But `prelude` does not have `show_user_adt` in its `import_map`
|
||||||
|
(prelude is the base; user modules import IT, not the other way
|
||||||
|
around). Three codegen sites raised UnknownVar:
|
||||||
|
`resolve_top_level_fn:2200`, `lower_app` cross-module arm:1981,
|
||||||
|
`synth_with_extras` Var arm:2777. All three now fall back to a
|
||||||
|
direct `module_user_fns.contains_key(prefix)` (or
|
||||||
|
`module_def_ail_types.contains_key(prefix)`) lookup when the
|
||||||
|
prefix isn't in the current module's import_map. This is the
|
||||||
|
post-mono synthesised-body invariant: cross-module references in
|
||||||
|
synthesised bodies may bypass the source template's imports
|
||||||
|
(both ends were independently typechecked under their own module
|
||||||
|
contexts before mono ran; the cross-module reference is created
|
||||||
|
by mono, not by the source). Doc comments cross-reference all
|
||||||
|
three sites.
|
||||||
|
- (c) **Poly-free-fn constraint residuals not pushed at synth.**
|
||||||
|
Pre-iter-24.3, the FreeFnCall arm at `lib.rs:2820` had
|
||||||
|
`constraints: _` — declared constraints of the poly free fn were
|
||||||
|
ignored. For all milestone-23 fixtures (`ne`/`lt`/`le`/`gt`/`ge`
|
||||||
|
at primitive types), this was latent because every call site had
|
||||||
|
a registry entry; the mono pass silently scheduled the
|
||||||
|
corresponding `eq__T`/`compare__T` targets, and codegen succeeded.
|
||||||
|
But for negative cases — `print f` where `f : Int -> Int` has no
|
||||||
|
Show instance — the constraint never reached the typecheck-time
|
||||||
|
`NoInstance` discharge (lib.rs:1880-1905). The build would emit
|
||||||
|
a confusing post-mono `unknown variable: show` from codegen
|
||||||
|
rather than the right typecheck-phase diagnostic. Fix: at
|
||||||
|
`lib.rs:2820+`, walk `Type::Forall.constraints` at FreeFnCall
|
||||||
|
sites, substitute the rigid vars with their fresh metavars, and
|
||||||
|
push one `ResidualConstraint` per declared constraint. The
|
||||||
|
discharge loop then fires the correct NoInstance with full
|
||||||
|
diagnostic context (including the Show-aware addendum from
|
||||||
|
Task 5). Pre-existing milestone-23 tests stay green because
|
||||||
|
primitive-type Show/Eq/Ord registry entries discharge silently.
|
||||||
|
- **bench/compile_check.py + check.py exit 1.** Both report
|
||||||
|
noise-class metrics (1 regression / 2 improvements respectively).
|
||||||
|
Metric identity migrates between consecutive runs — pattern
|
||||||
|
consistent with the documented `latency.implicit_at_rc.*` /
|
||||||
|
`check_ms.*` noise envelope per audit-cma + audit-ms + audit-eob +
|
||||||
|
audit-ct-tidy + audit-mq + iter-24.2 lineage. 8th consecutive
|
||||||
|
observation. Baseline pristine per conservative-call convention.
|
||||||
|
- **Plan deviation on Task 2 (IR-shape pin).** The plan's test stub
|
||||||
|
asserted `Term::Lam { body: Term::Let { ... } }` for `print__Int`.
|
||||||
|
The actual `FnDef.body: Term` shape for top-level fns is the
|
||||||
|
*inner* function body (params separate); no outer `Term::Lam`. The
|
||||||
|
test was corrected to assert `Term::Let { ... }` directly. The
|
||||||
|
load-bearing property (explicit let-binder for heap-Str RC
|
||||||
|
discipline) is identical between the plan's intent and the
|
||||||
|
shipped assertion; only the wrapper assumption changed. Doc
|
||||||
|
comment in the test file explains the FnDef.body shape contract.
|
||||||
|
|
||||||
|
## Known debt
|
||||||
|
|
||||||
|
- **Milestone 24 closes structurally with this iter.** The standard
|
||||||
|
`audit` pipeline (architect drift review + bench regression
|
||||||
|
attribution) runs next. The three plan-defects-fixed-inline above
|
||||||
|
may merit architect commentary on whether the fix sites belong as
|
||||||
|
permanent invariants or are themselves transitional. Specifically:
|
||||||
|
fix (a) implies that `MonoTarget::FreeFn::type_args` carries
|
||||||
|
CANONICAL types post-collection — this is a strengthening of the
|
||||||
|
pre-iter invariant which was "subst.apply result"; future planner
|
||||||
|
work that touches the mono pass should keep that strengthening
|
||||||
|
visible.
|
||||||
|
- **P2 entry "Retire io/print_int|bool|float effect-ops" is queued.**
|
||||||
|
The new entry's `~86 fixtures affected` count is from a rough
|
||||||
|
grep against `do io/print_<T>`; precise count + migration plan is
|
||||||
|
the planner's job when the milestone opens.
|
||||||
|
- **Negative-fixture coverage is single-shape.** `show_no_instance.ail.json`
|
||||||
|
uses `f : Int -> Int`. Other NoInstance shapes (user type without
|
||||||
|
instance, `print x` where `x : SomeUnsupportedClass`) are not
|
||||||
|
separately tested — the NoInstance arm fires for any non-prelude-Show
|
||||||
|
type by construction, so the single fixture is structurally
|
||||||
|
representative.
|
||||||
|
|
||||||
|
## Files touched
|
||||||
|
|
||||||
|
**Created (6):**
|
||||||
|
- `crates/ail/tests/print_mono_body_shape.rs`
|
||||||
|
- `crates/ail/tests/show_print_e2e.rs`
|
||||||
|
- `crates/ail/tests/show_no_instance_e2e.rs`
|
||||||
|
- `examples/show_print_smoke.ail.json`
|
||||||
|
- `examples/show_user_adt.ail.json`
|
||||||
|
- `examples/show_no_instance.ail.json`
|
||||||
|
|
||||||
|
**Modified (6):**
|
||||||
|
- `examples/prelude.ail.json` (+1 def: `fn print`)
|
||||||
|
- `crates/ailang-check/src/lib.rs` (NoInstance Show-aware branch +
|
||||||
|
FreeFnCall constraint-residual push)
|
||||||
|
- `crates/ailang-check/src/mono.rs` (FreeFn type_args canonical-form
|
||||||
|
normalisation, 2 sites)
|
||||||
|
- `crates/ailang-codegen/src/lib.rs` (cross-module reference fallback
|
||||||
|
for post-mono synthesised bodies, 3 sites: `resolve_top_level_fn`,
|
||||||
|
`lower_app`'s cross-module call arm, `synth_with_extras`'s Var arm)
|
||||||
|
- `docs/DESIGN.md` (§"Prelude (built-in) classes" milestone-24
|
||||||
|
paragraph + §"Float semantics" Show-Float cross-reference)
|
||||||
|
- `docs/roadmap.md` (P1 Show+print → [x]; new P2 entry at top)
|
||||||
|
|
||||||
|
## Stats
|
||||||
|
|
||||||
|
`bench/orchestrator-stats/2026-05-13-iter-24.3.json`
|
||||||
+25
-23
@@ -61,32 +61,34 @@ context. Pick the next milestone from P1.)_
|
|||||||
runtime"); spec 2026-05-09-22-typeclasses §22b.4b ("Show#Int
|
runtime"); spec 2026-05-09-22-typeclasses §22b.4b ("Show#Int
|
||||||
needs an `int_to_str` primitive returning heap-allocated Str").
|
needs an `int_to_str` primitive returning heap-allocated Str").
|
||||||
|
|
||||||
- [~] **\[milestone\]** Post-22 Prelude — Show + print rewire — ship
|
- [x] **\[milestone\]** Post-22 Prelude — Show + print rewire — shipped
|
||||||
`Show` typeclass with `Show Int/Bool/Str/Float` instances; rewire
|
2026-05-13 as iters 24.1 (heap-Str runtime + codegen for `bool_to_str`
|
||||||
`print` through `Show.show`. Originally queued as 22b.4 in the
|
+ `str_clone`, f38bad8), 24.2 (prelude `class Show` + four primitive
|
||||||
typeclass milestone, kept on hold pending demand and the
|
instances Int/Bool/Str/Float + 22b TShow/tshow migration), and 24.3
|
||||||
heap-`Str` prerequisite. Spec `docs/specs/2026-05-12-24-show-print.md`
|
(polymorphic `fn print : forall a. Show a => (a borrow) -> () !IO`
|
||||||
approved; iter 24.1 (runtime + codegen for two new heap-Str
|
+ positive 4-prim E2E + user-ADT E2E + Show-aware NoInstance
|
||||||
primitives `bool_to_str` + `str_clone`) shipped 2026-05-12 @ f38bad8.
|
diagnostic + DESIGN.md amendments to §"Prelude (built-in) classes"
|
||||||
Iters 24.2 (prelude `class Show` + four instances) and 24.3
|
and §"Float semantics"). The `MethodNameCollision` workaround that
|
||||||
(polymorphic `print` free fn + E2E) deferred — adding `class Show`
|
blocked the original spec retired in mq.3 (2026-05-13); spec
|
||||||
to the prelude collides with the user-class `Show` declared by
|
`docs/specs/2026-05-13-24-show-print.md` re-derived 24.2 + 24.3
|
||||||
14 test fixtures under `examples/test_22b{1,2,3}_*.ail.json` (plus
|
against the post-mq architecture.
|
||||||
hardcoded `"Show"` / `"show"` assertions in `crates/ail/tests/typeclass_22b{2,3}.rs`)
|
- context: spec `docs/specs/2026-05-13-24-show-print.md`; per-iter
|
||||||
through the workspace-global method-name-collision pre-pass at
|
journals 2026-05-12-iter-24.1, 2026-05-13-iter-24.2, 2026-05-13-iter-24.3.
|
||||||
`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).
|
|
||||||
|
|
||||||
## P2 — Medium-term
|
## 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` — `==`,
|
- [ ] **\[feature\]** Operator routing through `Eq` / `Ord` — `==`,
|
||||||
`<` etc. resolved via the typeclass instead of the built-in
|
`<` etc. resolved via the typeclass instead of the built-in
|
||||||
primitive comparators. No commitment; gated on bench re-baselining
|
primitive comparators. No commitment; gated on bench re-baselining
|
||||||
|
|||||||
@@ -521,6 +521,38 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "fn",
|
||||||
|
"name": "print",
|
||||||
|
"doc": "Polymorphic console-print helper. `print x` ≡ `do io/print_str (show x)` with an explicit let-binder around `show x` for heap-Str RC discipline per eob.1 Str carve-out. Ships in milestone 24 as the second half of the Show prelude.",
|
||||||
|
"type": {
|
||||||
|
"k": "forall",
|
||||||
|
"vars": ["a"],
|
||||||
|
"constraints": [{ "class": "Show", "type": { "k": "var", "name": "a" } }],
|
||||||
|
"body": {
|
||||||
|
"k": "fn",
|
||||||
|
"params": [{ "k": "var", "name": "a" }],
|
||||||
|
"param_modes": ["borrow"],
|
||||||
|
"ret": { "k": "con", "name": "Unit" },
|
||||||
|
"effects": ["IO"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"params": ["x"],
|
||||||
|
"body": {
|
||||||
|
"t": "let",
|
||||||
|
"name": "s",
|
||||||
|
"value": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "show" },
|
||||||
|
"args": [{ "t": "var", "name": "x" }]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"t": "do",
|
||||||
|
"op": "io/print_str",
|
||||||
|
"args": [{ "t": "var", "name": "s" }]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"schema": "ailang/v0",
|
||||||
|
"name": "show_no_instance",
|
||||||
|
"imports": [],
|
||||||
|
"defs": [
|
||||||
|
{
|
||||||
|
"kind": "fn",
|
||||||
|
"name": "main",
|
||||||
|
"type": {
|
||||||
|
"k": "fn",
|
||||||
|
"params": [],
|
||||||
|
"ret": { "k": "con", "name": "Unit" },
|
||||||
|
"effects": ["IO"]
|
||||||
|
},
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"t": "let",
|
||||||
|
"name": "f",
|
||||||
|
"value": {
|
||||||
|
"t": "lam",
|
||||||
|
"params": ["x"],
|
||||||
|
"paramTypes": [{ "k": "con", "name": "Int" }],
|
||||||
|
"retType": { "k": "con", "name": "Int" },
|
||||||
|
"body": { "t": "var", "name": "x" }
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [{ "t": "var", "name": "f" }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"schema": "ailang/v0",
|
||||||
|
"name": "show_print_smoke",
|
||||||
|
"imports": [],
|
||||||
|
"defs": [
|
||||||
|
{
|
||||||
|
"kind": "fn",
|
||||||
|
"name": "main",
|
||||||
|
"type": {
|
||||||
|
"k": "fn",
|
||||||
|
"params": [],
|
||||||
|
"ret": { "k": "con", "name": "Unit" },
|
||||||
|
"effects": ["IO"]
|
||||||
|
},
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"t": "seq",
|
||||||
|
"lhs": {
|
||||||
|
"t": "seq",
|
||||||
|
"lhs": {
|
||||||
|
"t": "seq",
|
||||||
|
"lhs": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 42 } }]
|
||||||
|
},
|
||||||
|
"rhs": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [{ "t": "lit", "lit": { "kind": "bool", "value": true } }]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rhs": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [{ "t": "lit", "lit": { "kind": "str", "value": "hello" } }]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rhs": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [{ "t": "lit", "lit": { "kind": "float", "bits": "40091eb851eb851f" } }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
{
|
||||||
|
"schema": "ailang/v0",
|
||||||
|
"name": "show_user_adt",
|
||||||
|
"imports": [],
|
||||||
|
"defs": [
|
||||||
|
{
|
||||||
|
"kind": "type",
|
||||||
|
"name": "IntBox",
|
||||||
|
"vars": [],
|
||||||
|
"ctors": [
|
||||||
|
{ "name": "MkIntBox",
|
||||||
|
"fields": [{ "k": "con", "name": "Int" }] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "instance",
|
||||||
|
"class": "prelude.Show",
|
||||||
|
"type": { "k": "con", "name": "IntBox" },
|
||||||
|
"methods": [
|
||||||
|
{
|
||||||
|
"name": "show",
|
||||||
|
"body": {
|
||||||
|
"t": "lam",
|
||||||
|
"params": ["x"],
|
||||||
|
"paramTypes": [{ "k": "con", "name": "IntBox" }],
|
||||||
|
"retType": { "k": "con", "name": "Str" },
|
||||||
|
"body": {
|
||||||
|
"t": "match",
|
||||||
|
"scrutinee": { "t": "var", "name": "x" },
|
||||||
|
"arms": [
|
||||||
|
{
|
||||||
|
"pat": { "p": "ctor",
|
||||||
|
"ctor": "MkIntBox",
|
||||||
|
"fields": [{ "p": "var", "name": "n" }] },
|
||||||
|
"body": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "int_to_str" },
|
||||||
|
"args": [{ "t": "var", "name": "n" }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "fn",
|
||||||
|
"name": "main",
|
||||||
|
"type": {
|
||||||
|
"k": "fn",
|
||||||
|
"params": [],
|
||||||
|
"ret": { "k": "con", "name": "Unit" },
|
||||||
|
"effects": ["IO"]
|
||||||
|
},
|
||||||
|
"params": [],
|
||||||
|
"body": {
|
||||||
|
"t": "app",
|
||||||
|
"fn": { "t": "var", "name": "print" },
|
||||||
|
"args": [
|
||||||
|
{ "t": "ctor",
|
||||||
|
"type": "IntBox",
|
||||||
|
"ctor": "MkIntBox",
|
||||||
|
"args": [{ "t": "lit", "lit": { "kind": "int", "value": 7 } }] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user