iter 22b.3.1: mono pass skeleton — identity for class-free workspaces
This commit is contained in:
@@ -2032,6 +2032,13 @@ fn build_to(
|
||||
// load-time remains valid.
|
||||
registry: ws.registry.clone(),
|
||||
};
|
||||
// Iter 22b.3: monomorphisation pass. After `lift_letrecs` and
|
||||
// before codegen, every (class-method, concrete-type) call-site
|
||||
// pair becomes a synthesised top-level fn; user call sites are
|
||||
// rewritten to target those names. Class-free workspaces flow
|
||||
// through bit-identically; see `ailang_check::monomorphise_workspace`.
|
||||
let ws = ailang_check::monomorphise_workspace(&ws)
|
||||
.map_err(|e| anyhow::anyhow!("monomorphise_workspace: {e}"))?;
|
||||
let ir = ailang_codegen::lower_workspace_with_alloc(&ws, alloc)?;
|
||||
let tmpdir = std::env::temp_dir().join(format!("ailang-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&tmpdir)?;
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user