iter 24.tidy: close 5 actionable drift items from audit-24

Documents the three iter-24.3 strengthenings as load-bearing
invariants and tightens two error-handling sites:

T1: DESIGN.md gains new subsection §Cross-module references in
synthesised bodies (between Resolution-and-monomorphisation and
Defaults-and-superclasses) documenting three invariants installed
in iter 24.3 — (1) MonoTarget::FreeFn::type_args carries canonical
types post-collection via normalize_type_for_lookup; (2) post-mono
synthesised body cross-module refs may bypass the source template's
import_map (codegen falls back to module_user_fns / module_def_ail_types);
(3) FreeFnCall synth pushes one ResidualConstraint per declared
forall-constraint with rigid vars substituted by fresh metavars.

T2: codegen_import_map_fallback_pin.rs (integration test) asserts
the synthesised prelude.print__<IntBox> body references
show_user_adt.show__<IntBox> AND prelude module's imports do not
contain show_user_adt — proving the cross-module ref bypasses
import_map at codegen.

T3: polyfn_dot_qualified_branch_pin.rs (integration test) asserts
bare-name print f (f : Int -> Int) fires exactly one no-instance
diagnostic at typecheck with zero unknown-variable diagnostics —
proving the bare-name resolution reaches the dot-qualified synth
branch where the constraint-residual push fires.

T4: check/lib.rs:2858 unwrap_or_default() replaced with .expect()
carrying the registry-coherence message — class_methods index
drift now surfaces explicitly rather than rendering NoInstance
with an empty method name.

T5: mono.rs gains apply_subst_and_normalize helper (Option<Type>
return) extracted from two byte-identical call sites at
collect_mono_targets and collect_residuals_ordered. Each call site
retains its own rigid-var / unit-default policy in the None arm
(site 1: rigid → has_rigid+break, unbound → Type::unit; site 2:
non-concrete → Type::unit). Byte-identity invariant on mono-symbol
hashes enforced by construction.

Tests: 558 passed (was 556 + 2 new pins). No production semantic
change — pure documentation + test pin + error-handling tightening
+ helper refactor. bench/cross_lang exit 0; bench/compile_check +
bench/check exit 0 this run (latency.implicit_at_rc / latency.explicit_at_rc /
bench_list_sum.bump_s noise envelope unobserved, lineage continues
at 10th consecutive observation without firing this run).
This commit is contained in:
2026-05-13 04:28:15 +02:00
parent 0e27533e73
commit 4e8447d15d
7 changed files with 502 additions and 41 deletions
+8 -1
View File
@@ -2855,7 +2855,14 @@ pub(crate) fn synth(
.find_map(|((cls, m), _)| {
if *cls == c_class { Some(m.clone()) } else { None }
})
.unwrap_or_default();
.expect(
"class_methods registry coherence — a declared constraint's \
class is missing from env.class_methods. The pre-pass \
`MissingClass` diagnostic should have rejected this earlier; \
reaching here means workspace-registry / class-index drift. \
Surface to debug skill rather than silently render NoInstance \
with an empty method name.",
);
residuals.push(ResidualConstraint {
class: c_class,
type_: c_ty,
+52 -40
View File
@@ -552,6 +552,37 @@ fn apply_per_module_types_overlay(env: &mut crate::Env, ws: &Workspace, module_n
/// 22b.2 typecheck pass has already fired
/// `MissingConstraint`/`NoInstance` for any that should not exist
/// at this point.
/// Apply the current substitution to a meta and, if the result is
/// fully concrete, normalise it to canonical-form for registry lookup.
///
/// Returns `Some(normalised)` if the meta resolves to a concrete type;
/// `None` if it does not (rigid var or unbound meta — the caller
/// decides the policy: break with `has_rigid = true` at the FreeFn
/// target-collection site, or `Type::unit()`-default at the residual-
/// ordering site).
///
/// Iter 24.tidy: extracted from two byte-identical call sites at
/// `collect_mono_targets` and `collect_residuals_ordered` per
/// audit-24's [medium-2] drift item. The byte-identity invariant
/// (Phase 2 synthesis name must match Phase 3 rewrite cursor's
/// lookup name) is now enforced by construction.
fn apply_subst_and_normalize(
env: &crate::Env,
module_name: &str,
m: &Type,
subst: &crate::Subst,
) -> Option<Type> {
let resolved = subst.apply(m);
if crate::is_fully_concrete(&resolved) {
Some(
env.workspace_registry
.normalize_type_for_lookup(module_name, &resolved),
)
} else {
None
}
}
pub fn collect_mono_targets(
f: &AstFnDef,
module_name: &str,
@@ -685,32 +716,25 @@ pub fn collect_mono_targets(
let mut type_args: Vec<Type> = Vec::with_capacity(fc.metas.len());
let mut has_rigid = false;
for m in &fc.metas {
let resolved = subst.apply(m);
if crate::is_fully_concrete(&resolved) {
// Iter 24.3: normalise bare type-cons references to the
// canonical `<owner>.<bare>` form before they enter the
// MonoTarget. The synthesised body for a poly free fn
// lives in the fn's `owner_module` (e.g. `prelude` for
// `print`), but its `type_args` typically come from
// user-defining modules. If left bare, the synthesised
// body's `param_tys` carry bare references that later
// mono-walks (in the synthesised body's caller-module
// context — i.e. the fn's owner module) cannot resolve
// back to the registry's qualified instance key — and
// any nested class-method call (e.g. `show x` inside
// `print`'s body) silently produces no mono target,
// leaving the synthesised body referencing a bare class
// method that codegen later rejects.
let normalised = env
.workspace_registry
.normalize_type_for_lookup(module_name, &resolved);
type_args.push(normalised);
} else if contains_rigid_var(&resolved) {
has_rigid = true;
break;
} else {
// Unbound metavar — default to Unit (iter 23.4 behaviour).
type_args.push(Type::unit());
match apply_subst_and_normalize(&env, module_name, m, &subst) {
Some(normalised) => type_args.push(normalised),
None => {
// Helper returned None: either rigid var or unbound
// metavar. Site-1 policy diverges: rigid → break with
// `has_rigid = true` (the enclosing poly fn will be
// monomorphised in its own right and this site will
// be re-observed with concrete substitution); unbound
// metavar → default to Unit (iter 23.4 behaviour,
// matching `derive_substitution`'s unobservable-var
// policy in codegen).
let resolved = subst.apply(m);
if contains_rigid_var(&resolved) {
has_rigid = true;
break;
} else {
type_args.push(Type::unit());
}
}
}
}
if has_rigid {
@@ -1285,20 +1309,8 @@ pub(crate) fn collect_residuals_ordered(
.metas
.iter()
.map(|m| {
let resolved = subst.apply(m);
if crate::is_fully_concrete(&resolved) {
// Iter 24.3: canonical-form normalisation — see
// matching site in `collect_mono_targets` for
// rationale. Must agree byte-identically with
// that site or Phase 3 rewrite cursor produces
// a mono-symbol name that differs from the
// Phase 2 synthesis name.
env
.workspace_registry
.normalize_type_for_lookup(module_name, &resolved)
} else {
Type::unit()
}
apply_subst_and_normalize(&env, module_name, m, &subst)
.unwrap_or_else(Type::unit)
})
.collect();
Some(MonoTarget::FreeFn {