feat(codegen): pre-resolve the App callee in MIR; delete is_static_callee + type_home_module (mir.2)
Second re-deriver removal of the typed-MIR milestone (spec
docs/specs/0060-typed-mir.md, plan docs/plans/0116-mir.2-callee-static.md).
Static-callee resolution moves out of codegen and into lower_to_mir:
every Term::App callee is classified once, mirroring check's own synth
Term::Var ladder (lib.rs:3409-3582), and emitted as a resolved Callee.
Codegen reads the callee identity off MIR and routes each kind to the
right lowering. The codegen re-derivers is_static_callee and
type_home_module are deleted, and the lower_app <-> is_static_callee
lockstep pair is struck from CLAUDE.md.
Callee reshape (beyond the spec's original {module, fn_name} sketch —
spec 0060's Concrete-code-shapes block is updated in this iteration):
pub enum Callee {
Static { module, fn_name, sig: Type }, // user/prelude fn -> emit_call, module pre-resolved
Builtin { name, sig: Type }, // operator/intrinsic -> inline opcode lowering
Indirect(Box<MTerm>), // dynamic: fn-pointer / closure / shadowed name
}
Two forced refinements, both settled in planning:
- sig:Type on each resolved variant. drop::synth_callee_ret_mode reads
the callee ret_mode, today off Callee::Indirect(inner).ty(). A
resolved callee has no sub-term, so the sig (= synth_pure(callee),
mode-preserving) is the lossless replacement. This is NOT a mir.3
pull-forward: the MArg param-mode / consume_count fields stay at their
mir.1 defaults. Without it, every statically-resolved call would lose
its drop signal and the RawBuf / int_to_str RC-stats pins mir.1b fixed
would regress.
- Builtin variant. Operators and the str-num builtins (+, not,
str_concat, ...) are lowered inline by name and have no module/fn_name;
a separate variant is cleaner than a sentinel module. The classifier
decides Builtin vs Static from CHECK'S OWN resolution (a name in
env.globals with no owning module is a builtin), never a copy of
codegen's old is_static_callee allowlist. The recon's divergence audit
confirmed check's builtin set and codegen's inline-arm set match
exactly, so the single-engine rule is mechanically satisfiable with no
env threading gap.
type_home_module is fully deletable: a workspace-wide grep confirmed no
program references a type-scoped T.fn as a value, so its only other
consumer (resolve_top_level_fn) collapses to the module-name fallback
with no behaviour change. (The spec's "x3 mirrors" wording over-counted;
the live surface was the definition plus two call sites.)
Alternatives rejected during planning: sentinel module in Static
(ugly); builtins left as Indirect (breaks — no fn-pointer for an
operator); name-rewrite Static{name,sig} keeping lower_app's by-name
dispatch (blurs builtin/user and still needs sig). The mir.1b
re-synth-strictness trap (post-mono synth_pure re-unify surfacing
mode-strip / bare-vs-qualified / metavar leaks) did NOT fire under the
new producer path — qualify_local_types mode-preservation and the $u
wildcard normalisation from mir.1b held.
Verification (orchestrator, post-implement inspect): diff matches the
plan; grep-clean for is_static_callee + type_home_module across
ailang-codegen and ail; cargo build --workspace green; cargo test
--workspace 700 passed / 0 failed / 3 ignored (no #[ignore] added this
iteration — the 3 are the pre-existing #49 Str-leg pin + two doctests).
Acceptance witnesses green: #53 (mono_new_over_user_adt_builds_and_runs),
#51 (rawbuf_new_int_size_only_builds_and_runs still builds), show_print
cross-module (print_user_adt_runs_end_to_end), the new mir.2 pins
(mir2_resolved_callee_kinds_run_end_to_end, callee_classification_*,
strengthened new_over_user_adt_carries_node_types asserting Callee::Static).
#49 heap-Str loop binder stays #[ignore] (lifts at mir.4).
Two new examples/ fixtures back the new pins (classify_pin.ail for the
producer classification pin, mir2_callee_kinds.ail for the E2E),
ail-parse / round-trip clean.
Forward note (cycle-close architect): crates/ail/tests/codegen_import_map_fallback_pin.rs:14-15
doc prose names lower_app's cross-module arm and synth_with_extras as
failure-mode targets — both now deleted (mir.2 / mir.1b). The pin's
protected invariant is still valid and green; the prose is stale and
wants a doc-honesty reword, left out of this iteration's footprint.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
//! pins protect the producer; codegen consumption arrives in mir.1b.
|
||||
|
||||
use ailang_check::elaborate_workspace;
|
||||
use ailang_mir::{MTerm, MirWorkspace, StrRep};
|
||||
use ailang_mir::{Callee, MTerm, MirWorkspace, StrRep};
|
||||
use ailang_surface::load_workspace;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -70,6 +70,22 @@ fn new_over_user_adt_carries_node_types() {
|
||||
ty_str.contains("Counter"),
|
||||
"lowered (new Counter 42) init node ty is Counter, got {ty_str}"
|
||||
);
|
||||
|
||||
// mir.2: the `(new Counter 42)` desugars to `App{callee:
|
||||
// Var{"Counter.new"}}`; lower_to_mir must resolve it to a
|
||||
// `Callee::Static` whose module is `Counter`'s home (its own
|
||||
// module, spelled bare per the own-module-types-stay-bare rule),
|
||||
// NOT leave it `Indirect` for codegen's deleted ladder to resolve.
|
||||
let MTerm::App { callee, .. } = init.as_ref() else {
|
||||
panic!("let init is the (new Counter 42) App node");
|
||||
};
|
||||
match callee {
|
||||
ailang_mir::Callee::Static { module, fn_name, .. } => {
|
||||
assert_eq!(module, "new_counter_user_adt", "Counter.new home module");
|
||||
assert_eq!(fn_name, "new", "Counter.new fn_name");
|
||||
}
|
||||
other => panic!("expected Callee::Static for Counter.new, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -102,6 +118,37 @@ fn poly_free_fn_accumulating_into_own_adt_elaborates() {
|
||||
assert!(mir.modules.contains_key("std_list"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn callee_classification_builtin_and_static() {
|
||||
// mir.2: `lower_to_mir::classify_callee` resolves each App callee
|
||||
// against check's own synth ladder, so codegen reads the resolved
|
||||
// identity off MIR. This pins two of the three legs from the
|
||||
// `classify_pin` witness: an arithmetic op (`+`) is a `Builtin`
|
||||
// (no owning module), a bare same-module user fn (`bump`) is a
|
||||
// `Static` carrying its own module name. The `Indirect` leg (a
|
||||
// fn-typed local) is covered by the existing closure e2e tests.
|
||||
let m = "classify_pin";
|
||||
let mir = elaborate_fixture(m);
|
||||
|
||||
// `bump`'s body is `(app + n 1)` → the `+` callee is a Builtin.
|
||||
match body(&mir, m, "bump") {
|
||||
MTerm::App { callee: Callee::Builtin { name, .. }, .. } => {
|
||||
assert_eq!(name, "+", "arithmetic op classified as Builtin");
|
||||
}
|
||||
other => panic!("expected Builtin `+`, got {other:?}"),
|
||||
}
|
||||
|
||||
// `main`'s body is `(app bump 41)` → `bump` is a same-module user
|
||||
// fn → Static{module: "classify_pin", fn_name: "bump"}.
|
||||
match body(&mir, m, "main") {
|
||||
MTerm::App { callee: Callee::Static { module, fn_name, .. }, .. } => {
|
||||
assert_eq!(module, "classify_pin", "own-module callee module");
|
||||
assert_eq!(fn_name, "bump", "own-module callee fn_name");
|
||||
}
|
||||
other => panic!("expected Static `bump`, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Recursively search for a `MTerm::Str { rep: Static }` reachable
|
||||
/// from a loop binder init (the seed).
|
||||
fn find_static_str_seed(t: &MTerm) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user