Files
AILang/crates/ail/tests/mono_hash_stability.rs
T
Brummel caa3618c3e iter intrinsic-bodies.2-migration-lock (DONE 4/4): prelude → (intrinsic) + bijection pin (refs #9)
Second and final iteration of the intrinsic-bodies milestone. Migrates
the 13 authored prelude dummy bodies to (intrinsic), rebaselines the two
hash pins that move, and locks the registry to the source with a
bijection. Behaviour-preserving: the codegen intercepts emit identical
IR; the prelude placeholder bodies were already dead (intercepted by
name before lower_term, since raw-buf.1).

What landed (4 tasks):

  Task 1 — examples/prelude.ail: 13 authored dummy bodies → (intrinsic).
    7 Eq/Ord instance methods (eq Int/Bool/Str/Unit, compare
    Int/Bool/Str) keep their lambda shell (params/ret = the method's
    local signature, Design X); the inner (body false)/(body true)/
    (body (term-ctor Ordering EQ)) becomes (intrinsic). 6 float_* fns
    ((body false) → (intrinsic) in the fn body slot). The honesty-rule
    infraction the milestone exists to fix is now closed: no prelude
    body lies about what runs.

  Task 2 — hash rebaselines (the prelude bytes changed):
    prelude module hash  af372f28c726f29f → 2ea61ef21ebc1913
    eq__Int       86ed4988438924d3 → cc7b99b63d1e44ae
    eq__Bool      d62d4d8c51f433f8 → fd0412f127986512
    eq__Str       3d32f377c66b03e0 → fa269285754a52da
    compare__Int  6d6c20520766368b → 0a02bd9effc9746c
    compare__Bool 02b64e8fadc913eb → d0dc108dacf4e543
    compare__Str  9645929d53cd3cc9 → d1419595dc52a456
    The 4 show__* mono pins did NOT move (Show bodies are real).

  Task 3 — intercepts.rs: registry_contains_all_legacy_arms (one-
    directional, hardcoded 18-name list) replaced by
    intercepts_bijection_with_intrinsic_markers. The in-source test
    walks prelude + kernel_stub pre-mono for Term::Intrinsic markers,
    recovers each marker's codegen symbol (mono_symbol(method, type) for
    instance methods; the fn name for top-level float_*/answer), and
    asserts a bijection over the intrinsic-backed class: (A) every
    marker resolves to an INTERCEPTS entry, (B) every INTERCEPTS entry
    not on the optimisation-only allowlist has a marker, plus a guard
    that the allowlist names are themselves registered. The allowlist is
    the 5 *__Int icmp-family entries, which intercept the monomorphised
    specialisation of the real-bodied polymorphic lt/le/gt/ge/ne — an
    optimisation, not a compiler-supplied body, so no marker. The pin
    passing independently confirms Task 1 missed no prelude site.

  Task 4 — confirmed no codegen path lowers an intercepted body (already
    true since raw-buf.1: try_emit_primitive_instance_body matches by
    name before f.body is inspected). Refreshed the now-accurate comment
    at lib.rs:1310-1319. design/contracts/0007-honesty-rule.md needed NO
    edit — it is a general present-tense rule and does not name the
    prelude dummies (confirmed by grep), so editing it would have been
    invented work.

Verification:
  cargo test --workspace → 669 passed, 0 failed (post-.1 baseline held;
    one test replaced net-0).
  Behaviour-preservation ratifiers GREEN (the safety net):
    eq_primitives_smoke_compiles_and_runs,
    compare_primitives_smoke_prints_1_2_3_thrice (e2e.rs);
    float_compare_smoke_prints_true_true_false (float_compare_smoke_e2e.rs);
    eq_ord_polymorphic_runs_end_to_end (eq_ord_e2e.rs).
  Bijection pin GREEN. Both hash pins GREEN at the new baselines.
  bench/check.py + compile_check.py → 0 regressed.

Plan-text imprecision (no outcome impact, noted for the record): Task 1
Step 5 wrote `--test e2e` for all four ratifiers, but
float_compare_smoke_prints_true_true_false and
eq_ord_polymorphic_runs_end_to_end live in their own test targets
(float_compare_smoke_e2e.rs, eq_ord_e2e.rs). The verification-filter
self-review checked that the fn names exist, not that they sit in the
named target — a sharper form of the filter-zero discipline. The
implementer ran each in its real target; all four green.

Milestone intrinsic-bodies is now feature-complete (.1 mechanism +
.2 migration+lock). Audit + close follow.
2026-05-29 17:46:50 +02:00

123 lines
5.1 KiB
Rust

//! Regression pin for primitive Eq/Ord mono-symbol body hashes.
//!
//! Locks the six primitive mono symbols (`eq__Int`, `eq__Bool`, `eq__Str`,
//! `compare__Int`, `compare__Bool`, `compare__Str`) to their pre-iter-23.4
//! body hashes. The unified mono pass MUST produce bit-identical bodies.
use ailang_core::ast::Def;
use ailang_core::hash::def_hash;
use ailang_surface::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("mono_hash_pin_smoke.ail")
}
fn show_fixture_path() -> PathBuf {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.pop();
d.pop();
d.join("examples").join("show_mono_pin_smoke.ail")
}
#[test]
fn primitive_eq_ord_mono_symbol_hashes_stay_bit_identical() {
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");
// Mono symbols for class methods are appended to the instance's
// `defining_module` — i.e. the prelude module, since all six
// primitive Eq/Ord instances live there.
let prelude_mod = post_mono
.modules
.get("prelude")
.expect("prelude module present");
// 2026-05-14 bugfix-print-leak-show-ret-mode: hashes re-pinned
// after `substitute_rigids` started preserving `param_modes` and
// `ret_mode` through rigid substitution (was: hard-reset to
// Implicit / `[]`). Eq/Ord class methods declare
// `param_modes: ["borrow", "borrow"]` in `prelude.ail.json`, so
// the mono-synthesised `eq__T` / `compare__T` symbols now carry
// those modes in their `Type::Fn` — canonical-JSON bytes drift,
// bodies are semantically identical.
// 2026-05-21 operator-routing-eq-ord re-pinned the three `eq__*`
// hashes after the prelude reshape: the Eq Int/Bool/Str instance
// bodies became placeholder `false` lambdas (codegen intercept
// emits the actual `icmp` / `@ail_str_eq` call). The three
// `compare__*` hashes were unchanged — those bodies were already
// placeholder Ordering ctors.
// 2026-05-29 intrinsic-bodies.2 re-pinned all six: the prelude
// Eq/Ord instance-method bodies migrated from placeholder terms
// ((body false)/(body true)/(term-ctor Ordering EQ)) to
// Term::Intrinsic, so the mono-synthesised eq__T/compare__T body
// bytes flip. Behaviour is unchanged — codegen intercepts these
// by name; the body is signature-only. The four show__* pins
// below do NOT move (Show instance bodies are real, unchanged).
let pins: &[(&str, &str)] = &[
("eq__Int", "cc7b99b63d1e44ae"),
("eq__Bool", "fd0412f127986512"),
("eq__Str", "fa269285754a52da"),
("compare__Int", "0a02bd9effc9746c"),
("compare__Bool", "d0dc108dacf4e543"),
("compare__Str", "d1419595dc52a456"),
];
for (sym, pin) in pins {
let def = prelude_mod
.defs
.iter()
.find(|d| matches!(d, Def::Fn(f) if f.name == *sym))
.unwrap_or_else(|| panic!("mono symbol {sym} not found in prelude module"));
let h = def_hash(def);
assert_eq!(&h, pin, "{sym} body hash drifted; captured: {h}");
}
}
#[test]
fn primitive_show_mono_symbol_hashes_stay_bit_identical() {
// 24.2 hash-stability pin for the four primitive `show__T` mono
// symbols synthesised from `prelude.Show {Int|Bool|Str|Float}`
// instance bodies. Loaded from a separate fixture
// (`show_mono_pin_smoke.ail.json`) so the Eq/Ord pin above stays
// structurally isolated.
let ws = load_workspace(&show_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");
// 2026-05-14 bugfix-print-leak-show-ret-mode: hashes re-pinned
// after the Show class method declaration in `prelude.ail.json`
// added `ret_mode: "own"` AND `substitute_rigids` started
// preserving `param_modes`/`ret_mode`. The mono-synthesised
// `show__T` symbols now carry `param_modes: ["borrow"]` and
// `ret_mode: Own` in their `Type::Fn` — bodies are semantically
// identical.
let pins: &[(&str, &str)] = &[
("show__Int", "9229ce65fdf11f61"),
("show__Bool", "ade621119184351f"),
("show__Str", "93fb52834427598c"),
("show__Float", "49874c7ed31c9d15"),
];
for (sym, pin) in pins {
let def = prelude_mod
.defs
.iter()
.find(|d| matches!(d, Def::Fn(f) if f.name == *sym))
.unwrap_or_else(|| panic!("mono symbol {sym} not found in prelude module"));
let h = def_hash(def);
assert_eq!(&h, pin, "{sym} body hash drifted; captured: {h}");
}
}