iter rpe.1: retire per-type print effect-ops
Single iter shipping the post-milestone-24 follow-up named in
docs/specs/2026-05-14-retire-per-type-print-effects.md. After this
iter the only surviving direct-output effect-op is `io/print_str`;
all per-type print primitives are replaced by the polymorphic
`print` helper (prelude, iter 24.3).
Components:
- 92 examples/*.ail fixtures migrated (do io/print_<T> x) →
(app print x); 6 .prose.txt snapshots regenerated via `ail prose`.
- Four-site lockstep compiler deletion: crates/ailang-check/src/builtins.rs
(3 effect_ops.insert blocks + 3 list() rows + the
install_io_print_float_signature test + module + EffectOpSig
doc-comments); crates/ailang-codegen/src/lib.rs lower_app
(3 arms + lowers_io_print_float test); crates/ailang-codegen/src/synth.rs
builtin_effect_op_ret match-arm pattern. Dead `intern_string`
helper removed as a follow-up.
- Five incidental test-body migrations (ailang-check x2, ailang-core
spec_drift + design_schema_drift, ailang-surface/src/lex.rs,
ailang-prose/src/lib.rs round-trip test).
- Cat B test-harness patch: six IR-shape tests in
crates/ail/tests/e2e.rs gained a monomorphise_workspace call
before lower_workspace_with_alloc so they follow the same
pipeline as `ail build` (the home-rolled desugar+lift loop
stayed because mono's precondition is "already lifted"; mono
inserts after lift).
- Six doc-comment touch-ups (lex.rs module doc, parse.rs
diagnostic example, ail/src/main.rs x2, runtime/str.c %g anchor,
crates/ailang-core/specs/form_a.md surface-spec example).
- DESIGN.md seven-site sweep (Decision 11 example, Polymorphic
print past-tense, Heap-Str output sentence, effect-op
invocation comment, Float NaN paragraph re-anchored on
float_to_str, two "What is supported" lists).
- Three E2E test-comment polish + four IR-snapshot refresh + one
canonical-hash pin update (plan-unanticipated downstream
consequences of the corpus migration).
- bench/{check,compile_check,cross_lang}.py: all exit 0; no
ratification needed.
- Roadmap entry struck through; per-iter journal at
docs/journals/2026-05-14-iter-rpe.1.md.
Tests 564/0/3. cargo clippy and cargo doc: zero warnings.
Two upstream codegen bugs surfaced during the first BLOCKED
attempt and were fixed in separate iters before this retry:
- 1fb225e bugfix: mono cursor misalignment at poly-free-fn Var
with class-constrained Forall.
- feb9413 bugfix: print leak — propagate ret_mode through rigid
substitution + prelude Show.show ret_mode.
Known debt (carried forward for next /audit):
- Emitter.strings field is functionally dead post-iter (orphan
after intern_string removal); cycles over empty map harmlessly.
This commit is contained in:
@@ -2299,50 +2299,6 @@ impl<'a> Emitter<'a> {
|
||||
let _ = tail;
|
||||
let call_kw = if tail { "tail call" } else { "call" };
|
||||
match op {
|
||||
"io/print_int" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_int arity".into(),
|
||||
));
|
||||
}
|
||||
let (v, vty) = self.lower_term(&args[0])?;
|
||||
if vty != "i64" {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_int needs i64".into(),
|
||||
));
|
||||
}
|
||||
let fmt = self.intern_string("fmt_int", "%lld\n");
|
||||
self.body.push_str(&format!(
|
||||
" {call_kw} i32 (ptr, ...) @printf(ptr @{fmt}, i64 {v})\n"
|
||||
));
|
||||
if tail {
|
||||
self.body.push_str(" ret i8 0\n");
|
||||
self.block_terminated = true;
|
||||
}
|
||||
Ok(("0".into(), "i8".into()))
|
||||
}
|
||||
"io/print_float" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_float arity".into(),
|
||||
));
|
||||
}
|
||||
let (v, vty) = self.lower_term(&args[0])?;
|
||||
if vty != "double" {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_float needs double".into(),
|
||||
));
|
||||
}
|
||||
let fmt = self.intern_string("fmt_float", "%g\n");
|
||||
self.body.push_str(&format!(
|
||||
" {call_kw} i32 (ptr, ...) @printf(ptr @{fmt}, double {v})\n"
|
||||
));
|
||||
if tail {
|
||||
self.body.push_str(" ret i8 0\n");
|
||||
self.block_terminated = true;
|
||||
}
|
||||
Ok(("0".into(), "i8".into()))
|
||||
}
|
||||
"io/print_str" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CodegenError::Internal(
|
||||
@@ -2370,45 +2326,6 @@ impl<'a> Emitter<'a> {
|
||||
}
|
||||
Ok(("0".into(), "i8".into()))
|
||||
}
|
||||
"io/print_bool" => {
|
||||
if args.len() != 1 {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_bool arity".into(),
|
||||
));
|
||||
}
|
||||
let (v, vty) = self.lower_term(&args[0])?;
|
||||
if vty != "i1" {
|
||||
return Err(CodegenError::Internal(
|
||||
"io/print_bool needs i1".into(),
|
||||
));
|
||||
}
|
||||
// Print "true\n" or "false\n".
|
||||
let fmt_t = self.intern_string("fmt_true", "true\n");
|
||||
let fmt_f = self.intern_string("fmt_false", "false\n");
|
||||
let id = self.fresh_id();
|
||||
let then_lbl = format!("ptbl_t.{id}");
|
||||
let else_lbl = format!("ptbl_f.{id}");
|
||||
let join_lbl = format!("ptbl_j.{id}");
|
||||
self.body.push_str(&format!(
|
||||
" br i1 {v}, label %{then_lbl}, label %{else_lbl}\n"
|
||||
));
|
||||
self.start_block(&then_lbl);
|
||||
self.body.push_str(&format!(
|
||||
" call i32 (ptr, ...) @printf(ptr @{fmt_t})\n"
|
||||
));
|
||||
self.body.push_str(&format!(" br label %{join_lbl}\n"));
|
||||
self.start_block(&else_lbl);
|
||||
self.body.push_str(&format!(
|
||||
" call i32 (ptr, ...) @printf(ptr @{fmt_f})\n"
|
||||
));
|
||||
self.body.push_str(&format!(" br label %{join_lbl}\n"));
|
||||
self.start_block(&join_lbl);
|
||||
if tail {
|
||||
self.body.push_str(" ret i8 0\n");
|
||||
self.block_terminated = true;
|
||||
}
|
||||
Ok(("0".into(), "i8".into()))
|
||||
}
|
||||
other => Err(CodegenError::Internal(format!(
|
||||
"unknown effect op: {other}"
|
||||
))),
|
||||
@@ -2722,20 +2639,9 @@ impl<'a> Emitter<'a> {
|
||||
self.counter
|
||||
}
|
||||
|
||||
fn intern_string(&mut self, hint: &str, content: &str) -> String {
|
||||
if let Some((name, _)) = self.strings.get(content) {
|
||||
return name.clone();
|
||||
}
|
||||
// Mangling per module: `.str_<module>_<hint>_<idx>`.
|
||||
let name = format!(".str_{}_{}_{}", self.module_name, hint, self.str_counter);
|
||||
self.str_counter += 1;
|
||||
let len = c_byte_len(content);
|
||||
self.strings
|
||||
.insert(content.to_string(), (name.clone(), len));
|
||||
name
|
||||
}
|
||||
|
||||
/// Iter hs.1 (amended hs.2): parallel to `intern_string`, but for
|
||||
/// Iter hs.1 (amended hs.2): parallel to the legacy
|
||||
/// `intern_string` (retired in iter rpe.1 alongside the per-type
|
||||
/// print effect-ops it served), but for
|
||||
/// language `Str` literals emitted as packed-struct globals
|
||||
/// (len + bytes + NUL). Shares the same monotonic `str_counter`
|
||||
/// so the produced global names remain alphabetically orderable
|
||||
@@ -3577,45 +3483,6 @@ mod tests {
|
||||
assert!(ir.contains("0xFFF0000000000000"), "-inf bit pattern missing: {ir}");
|
||||
}
|
||||
|
||||
/// Floats iter 4.6 RED: `(do io/print_float 1.5)` lowers via
|
||||
/// `printf("%g\n", v)`, parallel to `io/print_int` at line 2152.
|
||||
#[test]
|
||||
fn lowers_io_print_float() {
|
||||
use ailang_core::ast::*;
|
||||
let body = Term::Do {
|
||||
op: "io/print_float".into(),
|
||||
args: vec![Term::Lit { lit: Literal::Float { bits: 0x3ff8_0000_0000_0000u64 } }],
|
||||
tail: false,
|
||||
};
|
||||
let m = Module {
|
||||
schema: ailang_core::SCHEMA.to_string(),
|
||||
name: "t".into(),
|
||||
imports: vec![],
|
||||
defs: vec![Def::Fn(FnDef {
|
||||
name: "main".into(),
|
||||
ty: Type::Fn {
|
||||
params: vec![], ret: Box::new(Type::unit()), effects: vec!["IO".into()],
|
||||
param_modes: vec![], ret_mode: ParamMode::Implicit,
|
||||
},
|
||||
params: vec![], body, suppress: vec![], doc: None,
|
||||
})],
|
||||
};
|
||||
let ir = emit_ir(&m).unwrap();
|
||||
assert!(
|
||||
ir.contains("call i32 (ptr, ...) @printf"),
|
||||
"io/print_float not emitting printf: {ir}"
|
||||
);
|
||||
assert!(
|
||||
ir.contains("double 0x3FF8000000000000"),
|
||||
"Float arg not threaded through io/print_float: {ir}"
|
||||
);
|
||||
// Verify the format string `%g\n` is interned.
|
||||
assert!(
|
||||
ir.contains("%g") || ir.contains("\\67"), // `g` ASCII = 67 = 0x47
|
||||
"format string `%g\\n` not interned: {ir}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Iter 23.2: codegen intercepts a fn named `eq__Str` (the
|
||||
/// monomorphiser's synthesised symbol for `Eq Str.eq`) and emits
|
||||
/// a two-instruction body that calls @ail_str_eq, regardless of
|
||||
|
||||
Reference in New Issue
Block a user