iter 24.3: fn print + E2E + 3 compiler-path repairs; milestone 24 close
Ships fn print : forall a. Show a => (a borrow) -> () !IO in the
prelude with explicit-let body \\x -> let s = show x in do
io/print_str s. Three new E2E fixtures + tests verify the full
path:
- show_print_smoke: 4 primitives smoke (print 42 / true / 'hello' /
3.14) — compile, run, expected stdout
- show_user_adt: data IntBox + instance prelude.Show IntBox +
print (MkIntBox 7) — stdout '7'
- show_no_instance: let f : Int -> Int = \\x -> x in do print f —
fires Show-aware NoInstance with DESIGN.md §Prelude(built-in)
classes cross-reference
IR-shape pin in print_mono_body_shape.rs asserts post-mono
print__Int.body is structurally Term::Let → App(show__Int) →
Do(io/print_str). Protects the explicit let-binder for the heap-Str
RC discipline per eob.1 Str carve-out.
Three plan-defects-fixed-inline surfaced during user-ADT E2E,
necessary repairs to make the spec's stated user-ADT trajectory
work end-to-end:
(a) mono.rs (2 sites): MonoTarget::FreeFn::type_args were carrying
bare type-cons references; normalised to canonical
<owner>.<bare> form via workspace_registry.normalize_type_for_lookup
so synthesised cross-module bodies' post-mono walks reach the
registry-keyed instance entries. Symmetric to the existing
class-method-arm normalisation.
(b) codegen/lib.rs (3 sites: resolve_top_level_fn, lower_app
cross-module arm, synth_with_extras Var arm): post-mono
synthesised bodies may carry cross-module references to modules
their source template didn't import (prelude.print__<UserType>
references show_user_adt.show__<UserType> even though prelude
does not import user modules). Fall back to direct
module_user_fns lookup when prefix not in import_map. Both
ends were independently typechecked before mono ran; the
cross-module ref is created by mono not by source.
(c) lib.rs synth FreeFnCall arm: walked Type::Forall.constraints,
substituted rigid vars with fresh metavars, pushed one
ResidualConstraint per declared constraint. Without this,
print f at Int -> Int would silently typecheck and fail with
a confusing 'unknown variable: show' at codegen rather than
fire the right typecheck-time NoInstance diagnostic.
NoInstance Float-aware arm in check/lib.rs:770-779 extended with
a parallel class == 'prelude.Show' branch that cross-references
DESIGN.md §Prelude(built-in) classes verbatim. Negative-fixture
test asserts code 'no-instance' + Show substring + Prelude-(built-in)-
classes substring.
DESIGN.md §Prelude(built-in) classes milestone-24 paragraph flips
fn print from 'ships in 24.3' to 'shipped in iter 24.3' with body
shape + pin file reference. §Float semantics gains a Show-Float
NaN-spelling cross-reference paragraph linking show 1.5 / show nan /
show inf to instance Show Float via float_to_str.
Roadmap P1 'Post-22 Prelude — Show + print rewire' flipped to [x]
with closing summary naming all three shipped iters (24.1 / 24.2 /
24.3). New P2 entry 'Retire io/print_int|bool|float effect-ops +
migrate example corpus to print' inserted at top of P2.
Tests: 556 passed (was 552 + 4 new). bench/cross_lang exit 0;
bench/compile_check + bench/check exit 1 on documented noise-class
metrics per the audit-cma lineage envelope (8th consecutive
audit-grade observation, baseline pristine per conservative-call).
Milestone 24 closes structurally with this iter. Standard audit
pipeline next.
This commit is contained in:
@@ -776,6 +776,23 @@ impl CheckError {
|
||||
orderability per IEEE-754); see DESIGN.md §\"Float semantics\".",
|
||||
d.message
|
||||
);
|
||||
} else if class == "prelude.Show" {
|
||||
// Iter 24.3: Show-aware addendum on `NoInstance`. Fires
|
||||
// for any type lacking a Show instance — most commonly
|
||||
// a function type (`print f` where f is bare-fn-typed)
|
||||
// or a user type the LLM-author forgot to give an
|
||||
// instance for. Cross-references DESIGN.md §"Prelude
|
||||
// (built-in) classes" so the author learns which types
|
||||
// ship with built-in Show immediately.
|
||||
d.message = format!(
|
||||
"{} — `print` and `show` require a Show instance. \
|
||||
Built-in Show ships for Int, Bool, Str, Float in \
|
||||
the prelude; see DESIGN.md §\"Prelude (built-in) \
|
||||
classes\". User types declare their own \
|
||||
`instance prelude.Show <T>` in the type's defining \
|
||||
module per Decision 11 coherence.",
|
||||
d.message
|
||||
);
|
||||
}
|
||||
}
|
||||
d
|
||||
@@ -2800,10 +2817,52 @@ pub(crate) fn synth(
|
||||
// by bare name); the source-level `name` may be a
|
||||
// dot-qualified form (`prefix.suffix`) the synth started
|
||||
// with.
|
||||
if let (Type::Forall { vars, constraints: _, body }, Some((owner, unqualified_name))) =
|
||||
if let (Type::Forall { vars, constraints, body }, Some((owner, unqualified_name))) =
|
||||
(&raw, &free_fn_owner)
|
||||
{
|
||||
let (metas, inst) = instantiate(vars, body, counter);
|
||||
// Iter 24.3: push a residual for each declared constraint
|
||||
// of the poly free fn with the rigid var substituted by
|
||||
// its fresh metavar. The discharge loop at the enclosing
|
||||
// `check_fn`'s post-synth phase resolves the residual
|
||||
// against the workspace registry (fully-concrete after
|
||||
// App-arm unification) and fires `NoInstance` if no
|
||||
// instance ships for the unified type. Without this push,
|
||||
// `print f` at a function type `f : Int -> Int` would
|
||||
// typecheck silently — the `Show f`-shaped obligation
|
||||
// would only surface at codegen as an `unknown variable`
|
||||
// error from the synthesised mono body.
|
||||
//
|
||||
// The substitution mirrors `instantiate`'s body-side
|
||||
// mapping: position-by-position pairing of `vars` with
|
||||
// the freshly-generated `metas`. The discharge path
|
||||
// post-`subst.apply` produces the same concrete type
|
||||
// that the App-arm unified into the metavars.
|
||||
let cmapping: BTreeMap<String, Type> = vars
|
||||
.iter()
|
||||
.cloned()
|
||||
.zip(metas.iter().cloned())
|
||||
.collect();
|
||||
for c in constraints {
|
||||
let c_class = qualify_class_ref_in_check(&c.class, owner);
|
||||
let c_ty = substitute_rigids(&c.type_, &cmapping);
|
||||
// Look up the class's method name via the workspace
|
||||
// class index; we need it for the `ResidualConstraint`'s
|
||||
// `method` field (used by `NoInstance`'s rendering).
|
||||
let method_name = env
|
||||
.class_methods
|
||||
.iter()
|
||||
.find_map(|((cls, m), _)| {
|
||||
if *cls == c_class { Some(m.clone()) } else { None }
|
||||
})
|
||||
.unwrap_or_default();
|
||||
residuals.push(ResidualConstraint {
|
||||
class: c_class,
|
||||
type_: c_ty,
|
||||
method: method_name,
|
||||
candidates: None,
|
||||
});
|
||||
}
|
||||
free_fn_calls.push(FreeFnCall {
|
||||
name: unqualified_name.clone(),
|
||||
owner_module: owner.clone(),
|
||||
|
||||
@@ -687,7 +687,24 @@ pub fn collect_mono_targets(
|
||||
for m in &fc.metas {
|
||||
let resolved = subst.apply(m);
|
||||
if crate::is_fully_concrete(&resolved) {
|
||||
type_args.push(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;
|
||||
@@ -1270,7 +1287,15 @@ pub(crate) fn collect_residuals_ordered(
|
||||
.map(|m| {
|
||||
let resolved = subst.apply(m);
|
||||
if crate::is_fully_concrete(&resolved) {
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user