3286117605
Ships class Show a where show : (a borrow) -> Str in the prelude
plus primitive Show Int / Bool / Str / Float instances. Each
instance body is a single-application lambda invoking the
corresponding runtime primitive (int_to_str, bool_to_str,
str_clone, float_to_str) — first prelude instance bodies to call
runtime primitives directly. Float is included in Show (unlike
Eq/Ord) because textual representation is well-defined modulo the
NaN-spelling caveat at DESIGN.md §Float semantics.
The 22b typeclass test corpus is migrated preemptively: 21 fixture
files and 6 consumer files (typeclass_22b{2,3}.rs +
hash.rs ct4 pin + workspace.rs iter22b1 tests + the
instance_present.prose.txt snapshot) rename class Show / show
to class TShow / tshow, analogous to the existing TEq/TOrd
convention. Migration runs before the prelude additions so the
workspace stays green throughout.
Three new tests pin the post-mono shape: show_mono_synthesis.rs
(existence of show__Int/Bool/Str/Float as Def::Fn entries in the
prelude post-mono module), show_dispatch_pin.rs (bare show and
tshow both Step-2 singletons workspace-globally),
mono_hash_stability.rs::primitive_show_mono_symbol_hashes_stay_bit_identical
(body hashes pinned for the 4 new mono symbols).
DESIGN.md §Prelude (built-in) classes drops Show from the
deferred-features list and appends a milestone-24 paragraph
naming the class signature + the 4 instances + the body shape.
print rewire stays deferred to iter 24.3.
Tests: 552 passed (was 548 + 4 new). bench/compile_check +
bench/cross_lang exit 0. bench/check exits 1 on the recurring
noise envelope per the conservative-call lineage.
95 lines
3.4 KiB
Rust
95 lines
3.4 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_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("mono_hash_pin_smoke.ail.json")
|
|
}
|
|
|
|
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.json")
|
|
}
|
|
|
|
#[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");
|
|
|
|
let pins: &[(&str, &str)] = &[
|
|
("eq__Int", "81d59ac38ab3663d"),
|
|
("eq__Bool", "11da98a358b5979b"),
|
|
("eq__Str", "277516bb7f195b2a"),
|
|
("compare__Int", "d5d3f66b86c7e758"),
|
|
("compare__Bool", "676e3ea0298a8795"),
|
|
("compare__Str", "a532710899cf14fe"),
|
|
];
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
#[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");
|
|
|
|
let pins: &[(&str, &str)] = &[
|
|
("show__Int", "891eaebe64b3180d"),
|
|
("show__Bool", "1bdb621494e50607"),
|
|
("show__Str", "3f1d57c90ddce081"),
|
|
("show__Float", "5ab0bdd40b9f8b8f"),
|
|
];
|
|
|
|
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}");
|
|
}
|
|
}
|