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.
102 lines
4.5 KiB
Rust
102 lines
4.5 KiB
Rust
//! Regression: the workspace-monomorphisation pass must not mis-resolve
|
|
//! a cross-module constructor pattern. The mono pass re-runs `synth` on
|
|
//! every fn body to recover residual class constraints; that env is built
|
|
//! by `mono::build_workspace_env`, which delegates to `crate::build_check_env`
|
|
//! and produces a workspace-flat `ctor_index` and `types` map.
|
|
//!
|
|
//! Post-ct.2, `Pattern::Ctor` lookup is type-driven — it consults the
|
|
//! scrutinee's canonical `Type::Con.name` to find the TypeDef directly
|
|
//! in `env.module_types`, then validates the ctor name within it. The
|
|
//! mono pass's flat `ctor_index` is no longer consulted by this path;
|
|
//! the per-module overlay (lib.rs:1247-1258) is now decorative for the
|
|
//! pattern path and remains only for duplicate-type / duplicate-ctor
|
|
//! detection at the workspace-build prologue.
|
|
//!
|
|
//! This test pins the cross-module pattern shape against a minimal
|
|
//! 2-module fixture (`test_mono_ctor_main` + `test_mono_ctor_listmod`).
|
|
//! Pre-ct.2 the bug surfaced as `PatternTypeMismatch { ctor: "Cons",
|
|
//! ty: "test_mono_ctor_listmod.List<Int>" }` because the mono env
|
|
//! resolved `Cons` to bare `List` via the flat index. Post-ct.2 the
|
|
//! lookup is type-driven and `expected.name == "test_mono_ctor_listmod.List"`
|
|
//! directly indexes the right TypeDef.
|
|
//!
|
|
//! Surfaced by iter 23.2 Task 3, which adds `class Eq a` + Eq Int/Bool/Str
|
|
//! instances to `examples/prelude.ail.json`, flipping the
|
|
//! `workspace_has_typeclasses` gate so every workspace exercises the
|
|
//! mono pass.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
fn examples_dir() -> PathBuf {
|
|
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
d.pop();
|
|
d.pop();
|
|
d.join("examples")
|
|
}
|
|
|
|
/// Property: `monomorphise_workspace` must succeed on a workspace that
|
|
/// (a) flips the typeclass gate (any `Def::Class` + `Def::Instance` is
|
|
/// enough), and (b) contains a fn whose body pattern-matches a
|
|
/// constructor whose `Def::Type` lives in an imported module.
|
|
///
|
|
/// The minimal fixture is two modules:
|
|
///
|
|
/// * `test_mono_ctor_listmod` — declares `data List a = Nil | Cons a (List a)`.
|
|
/// * `test_mono_ctor_main` — imports the listmod, declares
|
|
/// `class Trivial a` + `instance Trivial Int` (to flip the
|
|
/// `workspace_has_typeclasses` gate), and defines
|
|
/// `head_or_zero : test_mono_ctor_listmod.List<Int> -> Int` that
|
|
/// matches on `Cons h _ | Nil`.
|
|
///
|
|
/// Pre-ct.2 repro: `monomorphise_workspace` returned
|
|
/// `Err(CheckError::PatternTypeMismatch { ctor: "Cons", ty:
|
|
/// "test_mono_ctor_listmod.List<Int>" })`. The same workspace
|
|
/// typechecked cleanly because the typecheck pass overlaid a
|
|
/// per-module `ctor_index` whose imports-fallback produced the
|
|
/// qualified `resolved_type_name`, while the mono pass kept the
|
|
/// workspace-flat index whose local hit produced the bare one.
|
|
///
|
|
/// Post-ct.2 expectation: `monomorphise_workspace` returns `Ok`
|
|
/// because the Pattern::Ctor lookup no longer consults
|
|
/// `ctor_index` at all — it walks directly from the scrutinee's
|
|
/// canonical `Type::Con.name` to its TypeDef in
|
|
/// `env.module_types` and validates the ctor by name there.
|
|
#[test]
|
|
fn mono_pass_handles_xmod_ctor_pattern() {
|
|
let entry = examples_dir().join("test_mono_ctor_main.ail");
|
|
let ws = ailang_surface::load_workspace(&entry).expect("load");
|
|
|
|
// Pre-condition: the workspace typechecks cleanly. The bug is
|
|
// localised to the mono pass; the typecheck path does not have it.
|
|
let diags = ailang_check::check_workspace(&ws);
|
|
assert!(
|
|
diags.is_empty(),
|
|
"fixture must typecheck before mono runs: {:?}",
|
|
diags
|
|
);
|
|
|
|
// Pin the symptom to the inner cause. Pre-fix this returns Err
|
|
// with the qualified scrutinee type and the bare `Cons` ctor.
|
|
let result = ailang_check::monomorphise_workspace(&ws);
|
|
match result {
|
|
Ok(_) => { /* post-fix: pass */ }
|
|
Err(ailang_check::CheckError::PatternTypeMismatch { ctor, ty }) => {
|
|
panic!(
|
|
"mono pass mis-resolves cross-module ctor pattern: \
|
|
ctor=`{}` ty=`{}` (expected mono to succeed; the bare \
|
|
ctor_index in build_workspace_env resolves `Cons` to \
|
|
the local bare `List` instead of qualified \
|
|
`test_mono_ctor_listmod.List`)",
|
|
ctor, ty
|
|
);
|
|
}
|
|
Err(other) => {
|
|
panic!(
|
|
"mono pass failed with unexpected error variant: {:?} \
|
|
(expected PatternTypeMismatch on cross-module Cons)",
|
|
other
|
|
);
|
|
}
|
|
}
|
|
}
|