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:
+20
-1
@@ -2748,7 +2748,8 @@ fn ail_run_accepts_ail_source_with_same_stdout_as_ail_json() {
|
||||
/// `int_to_str(42)` prints "42\n" through the standard
|
||||
/// `do io/print_str(...)` path. Smoke pin for the heap-Str builtin
|
||||
/// wired in hs.4 — exercises checker (signature install), codegen
|
||||
/// (lower_app arm + IR-header declare + is_static_callee whitelist),
|
||||
/// (lower_builtin arm + IR-header declare + `Callee::Builtin`
|
||||
/// classification in lower_to_mir),
|
||||
/// runtime (str.c's `ailang_int_to_str` allocates a heap-Str slab,
|
||||
/// @fputs reads from the bytes pointer at offset 8 with @stdout as
|
||||
/// the FILE*), and the
|
||||
@@ -2761,6 +2762,24 @@ fn int_to_str_smoke() {
|
||||
assert_eq!(out, "42\n");
|
||||
}
|
||||
|
||||
/// mir.2 end-to-end: a program whose `main` exercises all three
|
||||
/// resolved-callee kinds compiles and prints the correct result
|
||||
/// through codegen's post-mir.2 `MTerm::App` consumer. `bump`'s body
|
||||
/// `(app + n 1)` is a `Callee::Builtin` (inline opcode), `(app bump
|
||||
/// 41)` is a same-module `Callee::Static`, and `(app int_to_str r)`
|
||||
/// is a cross-module (prelude-fallback) `Callee::Static`. The
|
||||
/// property protected: codegen reads the callee identity off MIR and
|
||||
/// routes each kind to the right lowering — builtins inline, static
|
||||
/// fns to `emit_call` with the module pre-resolved, dynamic callees
|
||||
/// to the fn-pointer path — deriving nothing about the callee itself.
|
||||
/// A regression that mis-resolves any kind surfaces as a wrong result
|
||||
/// or a build failure here. `bump(41) = 42`, printed with no newline.
|
||||
#[test]
|
||||
fn mir2_resolved_callee_kinds_run_end_to_end() {
|
||||
let out = build_and_run("mir2_callee_kinds.ail");
|
||||
assert_eq!(out, "42");
|
||||
}
|
||||
|
||||
/// `float_to_str(3.5)` prints a libc-%g-conformant
|
||||
/// rendering of 3.5. The runtime's `ailang_float_to_str` uses
|
||||
/// `snprintf(..., "%g", x)` with no locale call, so the C locale
|
||||
|
||||
Reference in New Issue
Block a user