77b28ad64d
First half of the form-a-default-authoring milestone-close iter (Boss-decided strategy C, big-bang). All five tasks DONE; cargo test --workspace green at every per-task boundary. T1 — Add three new tests: - parse_is_deterministic_over_every_ail_fixture (round_trip.rs) - cli_parse_then_render_then_parse_is_idempotent (roundtrip_cli.rs) - carve_out_inventory.rs (new file; #[ignore]'d until T8 deletion) T2 — Bulk-render the 99 missing examples/<stem>.ail files via `ail render`. Corpus 58 .ail (pre-iter) -> 157 .ail. Eight .ail.json carve-outs (7 §C4(a) subject-matter + 1 §C4(b) prelude) preserved. One re-loop triggered: load_workspace prefers .ail siblings since ext-cli.1, so the newly-rendered imports broke seven Group-A entries whose JSON entry-paths now resolved imports to fresh .ail. Repair: pre-emptive forward-pull of five T3 migrations + 4 transient #[ignore]s on workspace.rs mod tests (cleanly relocated in T5). T3 — 14 Group-A test files migrated from ailang_core::load_workspace to ailang_surface::load_workspace + .ail paths. Carve-out lines preserved verbatim (7 sites in typeclass_22b2.rs / typeclass_22b3.rs). T4 — 12 Group-B test files: bulk regex flip on build_and_run / build_and_run_with_alloc / build_and_run_with_rc_stats call sites (~70 e2e.rs invocations + 11 subprocess sites). Four files mis-classified Group-A as Group-B in plan recon (mono_hash_stability, prelude_free_fns, print_mono_body_shape, show_mono_synthesis); two files mis-classified Group-B as Group-A (mono_recursive_fn, mono_xmod_qualified_ref). Migrated per actual shape, not plan label. T5 — Relocated #[cfg(test)] mod tests from production source to integration test crates with ailang-surface dev-dependency: - crates/ailang-core/tests/hash_pin.rs (10 tests from hash.rs) - crates/ailang-core/tests/workspace_pin.rs (10 non-carve-out tests from workspace.rs) - crates/ailang-codegen/tests/eq_primitives_pin.rs (3 tests from codegen/src/lib.rs:3717-3799) - ailang-prose/tests/snapshot.rs migrated (helper + 8 fixtures) to .ail + ailang_surface::load_module Carve-out tests in workspace.rs mod tests preserved in-place (3× 22b2 + 3× ct1 = 6 tests). Tempdir-based loader-mechanism tests (3 sites) also preserved — they don't consume examples/. Tests: 560 passed, 0 failed, 4 ignored (was 558 + 3 T1 new - 1 transit carve_out_inventory #[ignore] = 560 active). Tasks 6-12 (bench-driver suffix flips, e2e diff-test rewrite + 4 additional raw-JSON-inspect handlers, .ail.json deletion, retiring obsolete roundtrip tests + schema_coverage corpus flip, §C3 DESIGN.md restatement, §A4 doctrine edits, WhatsNew + roadmap strike) ship in the next dispatch on this iter ID. Known debt inherited to T6-12: 4 raw-JSON-inspect tests in e2e.rs (borrow_own_demo / reuse_as_demo / render_parse_round_trip_canonical / ail_run_accepts_ail_source_with_same_stdout_as_ail_json dual-form smoke) need rewrite or #[ignore] before T8 deletion; recorded in journal Concerns + Known debt sections.
241 lines
9.1 KiB
Rust
241 lines
9.1 KiB
Rust
//! Drift-shape pin for env construction (env-construction unify
|
|
//! milestone). Asserts that `build_check_env(&ws)` agrees with an
|
|
//! in-test reproduction of the pre-refactor inline seeding on every
|
|
//! workspace-flat field. Future-you adds a new workspace-flat env
|
|
//! field without updating `build_check_env` -> this test fails before
|
|
//! the bug ships.
|
|
//!
|
|
//! Fixture: a two-module workspace covering one `Def::Class`, one
|
|
//! `Def::Instance`, one user ADT, and one cross-module import (the
|
|
//! same shape that `test_mono_imports_*` use).
|
|
|
|
use ailang_check::{build_check_env, build_module_globals, Env};
|
|
use ailang_core::ast::Def;
|
|
use ailang_surface::load_workspace;
|
|
use std::collections::BTreeMap;
|
|
use std::path::Path;
|
|
|
|
fn examples_dir() -> std::path::PathBuf {
|
|
let manifest = env!("CARGO_MANIFEST_DIR");
|
|
Path::new(manifest)
|
|
.parent().expect("CARGO_MANIFEST_DIR has a parent (crates/ailang-check)")
|
|
.parent().expect("CARGO_MANIFEST_DIR has a grandparent (crates/)")
|
|
.join("examples")
|
|
}
|
|
|
|
/// Independent reproduction of every workspace-flat env seeding
|
|
/// step. Pre-refactor, workspace-flat seeding was split between
|
|
/// `check_in_workspace` (per-module `types`/`ctor_index`) and
|
|
/// `mono::build_workspace_env` (workspace-flat `types`/`ctor_index`
|
|
/// plus everything else); this reproduction captures the *union*
|
|
/// — exactly the surface `build_check_env` is responsible for.
|
|
/// Kept as a frozen reference: any future divergence between this
|
|
/// body and `build_check_env` makes the assertion below fail.
|
|
fn build_env_inline_pre_refactor(ws: &ailang_core::workspace::Workspace) -> Env {
|
|
let mut env = Env::default();
|
|
ailang_check::builtins::install(&mut env);
|
|
|
|
// env.types + env.ctor_index — workspace-flat from every Def::Type.
|
|
for m in ws.modules.values() {
|
|
for d in &m.defs {
|
|
if let Def::Type(td) = d {
|
|
for c in &td.ctors {
|
|
env.ctor_index.insert(
|
|
c.name.clone(),
|
|
ailang_check::CtorRef { type_name: td.name.clone() },
|
|
);
|
|
}
|
|
env.types.insert(td.name.clone(), td.clone());
|
|
}
|
|
}
|
|
}
|
|
|
|
// env.module_globals — per-module .fns projection.
|
|
let mg = build_module_globals(ws).expect("build_module_globals");
|
|
env.module_globals = mg
|
|
.iter()
|
|
.map(|(k, v)| (k.clone(), v.fns.clone()))
|
|
.collect();
|
|
|
|
// env.module_types — workspace-wide ADT index, inlined here as
|
|
// a frozen reproduction (test does not share helper code with
|
|
// production).
|
|
let mut module_types: BTreeMap<String, indexmap::IndexMap<String, ailang_core::ast::TypeDef>> = BTreeMap::new();
|
|
for (mname, m) in &ws.modules {
|
|
let mut tys: indexmap::IndexMap<String, ailang_core::ast::TypeDef> = indexmap::IndexMap::new();
|
|
for d in &m.defs {
|
|
if let Def::Type(td) = d {
|
|
tys.insert(td.name.clone(), td.clone());
|
|
}
|
|
}
|
|
module_types.insert(mname.clone(), tys);
|
|
}
|
|
env.module_types = module_types;
|
|
|
|
// env.module_imports — per-module alias map. Iter 23.1: every
|
|
// non-prelude module implicitly imports the prelude module.
|
|
for m in ws.modules.values() {
|
|
let mut import_map: BTreeMap<String, String> = BTreeMap::new();
|
|
for imp in &m.imports {
|
|
let key = imp.alias.clone().unwrap_or_else(|| imp.module.clone());
|
|
import_map.insert(key, imp.module.clone());
|
|
}
|
|
if m.name != "prelude" {
|
|
import_map
|
|
.entry("prelude".to_string())
|
|
.or_insert_with(|| "prelude".to_string());
|
|
}
|
|
env.module_imports.insert(m.name.clone(), import_map);
|
|
}
|
|
|
|
// env.class_methods — workspace-merged from each module's
|
|
// ModuleGlobals.class_methods.
|
|
for g in mg.values() {
|
|
for (n, e) in &g.class_methods {
|
|
env.class_methods.insert(n.clone(), e.clone());
|
|
}
|
|
}
|
|
|
|
// env.class_superclasses — walk every module's Def::Class.
|
|
//
|
|
// mq.1: both key and value carry the qualified workspace-key shape;
|
|
// bare `SuperclassRef.class` is lifted using the parent class's
|
|
// defining module.
|
|
for (mod_name, m) in &ws.modules {
|
|
for d in &m.defs {
|
|
if let Def::Class(cd) = d {
|
|
if let Some(sc) = &cd.superclass {
|
|
let class_qualified = format!("{mod_name}.{}", cd.name);
|
|
let sc_qualified = if sc.class.contains('.') {
|
|
sc.class.clone()
|
|
} else {
|
|
format!("{mod_name}.{}", sc.class)
|
|
};
|
|
env.class_superclasses.insert(class_qualified, sc_qualified);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// env.workspace_registry — clone of ws.registry.
|
|
env.workspace_registry = ws.registry.clone();
|
|
|
|
env
|
|
}
|
|
|
|
#[test]
|
|
fn build_check_env_matches_inline_seeding() {
|
|
let entry = examples_dir().join("test_mono_imports_main.ail");
|
|
let ws = load_workspace(&entry).expect("load test_mono_imports_main");
|
|
|
|
let env_helper = build_check_env(&ws);
|
|
let env_inline = build_env_inline_pre_refactor(&ws);
|
|
|
|
// env.types — IndexMap<String, TypeDef>: compare key-set + name.
|
|
assert_eq!(
|
|
env_helper.types.keys().collect::<Vec<_>>(),
|
|
env_inline.types.keys().collect::<Vec<_>>(),
|
|
"env.types key-set differs"
|
|
);
|
|
for k in env_helper.types.keys() {
|
|
assert_eq!(
|
|
env_helper.types[k].name,
|
|
env_inline.types[k].name,
|
|
"env.types[{k}] type-def name differs"
|
|
);
|
|
}
|
|
|
|
// env.ctor_index — IndexMap<String, CtorRef>: compare key-set +
|
|
// type_name.
|
|
assert_eq!(
|
|
env_helper.ctor_index.keys().collect::<Vec<_>>(),
|
|
env_inline.ctor_index.keys().collect::<Vec<_>>(),
|
|
"env.ctor_index key-set differs"
|
|
);
|
|
for k in env_helper.ctor_index.keys() {
|
|
assert_eq!(
|
|
env_helper.ctor_index[k].type_name,
|
|
env_inline.ctor_index[k].type_name,
|
|
"env.ctor_index[{k}].type_name differs"
|
|
);
|
|
}
|
|
|
|
// env.module_globals — BTreeMap<String, IndexMap<String, Type>>.
|
|
assert_eq!(
|
|
env_helper.module_globals.keys().collect::<Vec<_>>(),
|
|
env_inline.module_globals.keys().collect::<Vec<_>>(),
|
|
"env.module_globals key-set differs"
|
|
);
|
|
for k in env_helper.module_globals.keys() {
|
|
assert_eq!(
|
|
env_helper.module_globals[k].keys().collect::<Vec<_>>(),
|
|
env_inline.module_globals[k].keys().collect::<Vec<_>>(),
|
|
"env.module_globals[{k}] inner key-set differs"
|
|
);
|
|
}
|
|
|
|
// env.module_types — same shape as module_globals.
|
|
assert_eq!(
|
|
env_helper.module_types.keys().collect::<Vec<_>>(),
|
|
env_inline.module_types.keys().collect::<Vec<_>>(),
|
|
"env.module_types key-set differs"
|
|
);
|
|
for k in env_helper.module_types.keys() {
|
|
assert_eq!(
|
|
env_helper.module_types[k].keys().collect::<Vec<_>>(),
|
|
env_inline.module_types[k].keys().collect::<Vec<_>>(),
|
|
"env.module_types[{k}] inner key-set differs"
|
|
);
|
|
}
|
|
|
|
// env.module_imports — BTreeMap<String, BTreeMap<String, String>>:
|
|
// direct equality.
|
|
assert_eq!(
|
|
env_helper.module_imports, env_inline.module_imports,
|
|
"env.module_imports differs"
|
|
);
|
|
|
|
// env.class_methods — BTreeMap<String, ClassMethodEntry>:
|
|
// compare key-set (entry shape has no PartialEq).
|
|
assert_eq!(
|
|
env_helper.class_methods.keys().collect::<Vec<_>>(),
|
|
env_inline.class_methods.keys().collect::<Vec<_>>(),
|
|
"env.class_methods key-set differs"
|
|
);
|
|
|
|
// env.class_superclasses — direct equality.
|
|
assert_eq!(
|
|
env_helper.class_superclasses, env_inline.class_superclasses,
|
|
"env.class_superclasses differs"
|
|
);
|
|
|
|
// env.effect_ops — IndexMap<String, EffectOpSig>: compare key-set.
|
|
assert_eq!(
|
|
env_helper.effect_ops.keys().collect::<Vec<_>>(),
|
|
env_inline.effect_ops.keys().collect::<Vec<_>>(),
|
|
"env.effect_ops key-set differs"
|
|
);
|
|
|
|
// env.workspace_registry — entries key-set must match.
|
|
assert_eq!(
|
|
env_helper.workspace_registry.entries.keys().collect::<Vec<_>>(),
|
|
env_inline.workspace_registry.entries.keys().collect::<Vec<_>>(),
|
|
"env.workspace_registry.entries key-set differs"
|
|
);
|
|
|
|
// Per-call overlay fields must NOT be seeded by the helper.
|
|
assert_eq!(env_helper.current_module, "", "current_module is overlay");
|
|
// env.globals — partially workspace-flat (builtins operators
|
|
// installed by `builtins::install`) and partially overlay
|
|
// (per-module fns seeded by callers). The helper carries only
|
|
// the workspace-flat half; key-set must match the inline
|
|
// reproduction at this point.
|
|
assert_eq!(
|
|
env_helper.globals.keys().collect::<Vec<_>>(),
|
|
env_inline.globals.keys().collect::<Vec<_>>(),
|
|
"env.globals key-set differs (workspace-flat half from builtins)"
|
|
);
|
|
assert!(env_helper.imports.is_empty(), "imports is overlay");
|
|
assert!(env_helper.rigid_vars.is_empty(), "rigid_vars is overlay");
|
|
}
|