iter 22b.3.1: mono pass skeleton — identity for class-free workspaces

This commit is contained in:
2026-05-09 20:12:36 +02:00
parent f7791e6cbd
commit 209074ee5d
4 changed files with 127 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
//! Iter 22b.3: monomorphisation pass tests.
//!
//! Co-located with `typeclass_22b2.rs` so the typeclass-feature
//! coverage is browsable in one directory. Tests use the same
//! `examples_dir()` pattern — `cargo test`-cwd is the crate dir,
//! the fixtures live in `<repo>/examples/`.
use std::path::PathBuf;
fn examples_dir() -> PathBuf {
// crates/ail/ → repo root → examples/
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.pop();
d.pop();
d.join("examples")
}
#[test]
fn monomorphise_workspace_is_identity_on_class_free_workspace() {
// Pick any class-free fixture; `examples/hello.ail.json` is
// the canonical class-free smoke test.
let entry = examples_dir().join("hello.ail.json");
let ws = ailang_core::load_workspace(&entry).expect("load");
let diags = ailang_check::check_workspace(&ws);
assert!(diags.is_empty(), "fixture must typecheck: {:?}", diags);
let ws = ailang_check::monomorphise_workspace(&ws)
.expect("mono on class-free workspace");
// Module set unchanged.
let before = ailang_core::load_workspace(&examples_dir().join("hello.ail.json"))
.expect("re-load");
assert_eq!(
ws.modules.keys().collect::<Vec<_>>(),
before.modules.keys().collect::<Vec<_>>(),
"module set must be identical"
);
// Per-module def list unchanged (compare by canonical-JSON hash).
for (mname, m) in &ws.modules {
let before_m = &before.modules[mname];
let h_after = ailang_core::module_hash(m);
let h_before = ailang_core::module_hash(before_m);
assert_eq!(
h_after, h_before,
"class-free module `{}` must hash-identical through mono",
mname
);
}
}