bcd41810f4
Reader-facing prose and rustdoc carried opaque shorthand like
"Decision 10", "clause-5", "mq.1", "ct.1", "eob.1", "rpe.1",
"post-mq.3", and "Iter 22b.1:" with no in-repo definition the reader
could follow. This commit replaces every such occurrence in the
durable tier the reader is most likely to land on (design/ ledger +
source //! module headers + the central /// public-item rustdoc) with
an inline content phrase plus, where applicable, a Markdown link to
the file that defines the referenced concept.
design/ ledger — 16 files:
Definition-site headings demoted from "Decision N: <title>" to
"<title>": authoring-surface, tail-calls, memory-model section in
rc-uniqueness.md, dual-allocator section, typeclass design,
effects "pure core + algebraic effects".
Cross-reference sites: "Decision 1" -> canonical-schema principle
(data-model); "Decision 3/4" -> effects + scope-boundaries; "Decision
6" -> authoring-surface; "Decision 8" -> tail-calls; "Decision 9" ->
rc-uniqueness (dual-allocator); "Decision 10" -> memory-model;
"Decision 11" -> typeclasses (model). "clause-5" -> body-link
durability gate. "clause-3" (in language-constraints) ->
bug-class-reintroduction discriminator. "mq.1/2/3", "ct.1/4",
"eob.1", "rpe.1" -> the canonical-form rule / the type-driven
dispatch / the Str carve-out / etc. "post-mq.3" -> "type-driven".
design/contracts/feature-acceptance.md: file-local "clauses 1/2/3"
-> "criteria 1/2/3" (sprachliche Kohärenz mit der File-Überschrift
"Feature-acceptance criterion"); "the clause-3 mechanism" -> "the
bug-class-reintroduction discriminator".
Source //! module headers — 24 files:
Stripped "Iter X.Y:" prefixes and "(Decision N)" / "(mq.X)" tags
from spec_drift, uniqueness, reuse_shape, migrate_canonical_types,
typeclass_22b{2,3,c}, suppress_filter, lift, mono, linearity,
diagnostic, method_dispatch_pin, method_collision_pin,
no_per_type_print_ops, mq3_multi_class_e2e, print_mono_body_shape,
print_no_leak_pin, cli_diag_human_workspace_load_error,
ct1_check_cli, prose snapshot, unbound_in_instance_method_pin,
mono_xmod_ctor_pattern, desugar.
Central /// public-item rustdoc:
ast.rs (full sweep — every "Iter X" + "Decision N" prefix
reformulated; mode/Type::Fn rustdoc now points at memory-model.md;
Constraint / SuperclassRef / InstanceDef / ClassDef rustdoc points
at typeclasses contract).
diagnostic.rs (all "(Iter X)" / "(mq.X)" tags on diagnostic codes
removed).
lib.rs (FORM_A_SPEC rustdoc points at authoring-surface.md
instead of "Decision 6").
canonical.rs (type_hash + Float-literal rustdoc).
Still outstanding (for a follow-up commit): ~500 inline `//`
code-body comments with `Iter X.Y` markers across the workspace, and
a handful of `///` rustdoc items in hash_pin / workspace_pin / lift /
mono / suppress_filter test-pin and internal-function bodies. Code
identifiers (test filenames like `mq3_multi_class_e2e.rs`, function
names like `iter18e_drop_iterative_default_preserves_hashes`) stay
verbatim per the user's "code identifiers stay verbatim" rule.
Tests: design_index_pin 5/5 + docs_honesty_pin 5/5; workspace builds
clean; full `cargo test --workspace` previously green (every
`test result: ok` line, no FAILED line).
105 lines
4.6 KiB
Rust
105 lines
4.6 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.
|
|
//!
|
|
//! After the canonical-form / type-driven-ctor-lookup refactor,
|
|
//! `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`).
|
|
//! Before the refactor 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. After the
|
|
//! refactor the lookup is type-driven and
|
|
//! `expected.name == "test_mono_ctor_listmod.List"` directly indexes
|
|
//! the right TypeDef.
|
|
//!
|
|
//! Surfaced when `class Eq a` + Eq Int/Bool/Str instances were added
|
|
//! 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
|
|
);
|
|
}
|
|
}
|
|
}
|