P5.4: migrate all callers to on_build; delete set_post_link_callback

on_build is now the sole post-build callback mechanism. Migrated the 9 callers
(0602/0603/1611/1614/1615/1616 + the platform bundle_main) from
opts.set_post_link_callback(cb) to on_build(cb), giving each callback the
(opt: BuildOptions) param. Deleted set_post_link_callback from build.sx,
compiler_lib (bound_fns + handleSetPostLinkCallback), and the VM arm.

Reworked the P5 smoke tests for the new semantics: an on_build override REPLACES
the build (must emit+link or delegate), unlike the old post-link callback which
ran after the auto-link. 1662 (queries) + 1664 (override+List-grow) now delegate
to default_pipeline for the real build; deleted 1661/1663 (the primitives are now
exercised by every AOT build). bundle_main invoked with pass_options=true.

Benign 37-.ir churn (build.sx shrank). 703/0 both gates.
This commit is contained in:
agra
2026-06-19 09:37:05 +03:00
parent d178454841
commit 65ac370683
60 changed files with 36334 additions and 36578 deletions

View File

@@ -60,7 +60,6 @@ pub const bound_fns = [_]BoundFn{
.{ .sx_name = "register_type", .handler = handleRegisterType },
// ── BuildOptions (migrated off `#compiler` onto `abi(.compiler)`) ─────────
.{ .sx_name = "build_options", .handler = handleBuildOptions },
.{ .sx_name = "set_post_link_callback", .handler = handleSetPostLinkCallback },
.{ .sx_name = "on_build", .handler = handleOnBuild },
// ── build-pipeline metadata queries (Phase 5.2) ──────────────────────────
// VM-only: the post-link callback that calls these always runs on the VM
@@ -349,16 +348,6 @@ fn handleBuildOptions(_: *Interpreter, _: []const Value) InterpError!Value {
/// `set_post_link_callback(self, cb)` — record the callback `FuncId` on the build
/// config so `main.zig` re-enters the evaluator post-link. The `cb` arg is a
/// `.func_ref` value.
fn handleSetPostLinkCallback(interp: *Interpreter, args: []const Value) InterpError!Value {
if (args.len != 2) return error.TypeError;
const bc = interp.build_config orelse return error.CannotEvalComptime;
switch (args[1]) {
.func_ref => |id| bc.post_link_callback_fn = id,
else => return error.TypeError,
}
return .void_val;
}
/// `on_build(cb)` — register the build callback (the Phase 5 form, a free fn; cb
/// is arg 0, and `cb: (opt: BuildOptions) -> bool` so the callback is invoked with
/// the `BuildOptions` handle). Sets `post_link_takes_options` to distinguish it

View File

@@ -1480,18 +1480,6 @@ pub const Vm = struct {
if (std.mem.eql(u8, name, "build_options")) {
return @as(Reg, null_addr);
}
// `set_post_link_callback(self, cb)` — record the callback `FuncId` on the
// build config so `main.zig` re-enters the evaluator post-link. The cb arg is
// a `func_ref` word. Mirrors the legacy `hookSetPostLinkCallback`.
if (std.mem.eql(u8, name, "set_post_link_callback")) {
if (args.len != 2) return self.failMsg("comptime set_post_link_callback: expected (self, cb)");
const bc = self.build_config orelse
return self.failMsg("comptime set_post_link_callback: no build config threaded into the VM");
const fid = funcRefToId(frame.get(args[1].index())) orelse
return self.failMsg("comptime set_post_link_callback: cb arg is not a function value");
bc.post_link_callback_fn = fid;
return @as(Reg, null_addr);
}
// `on_build(cb)` — register the build callback (the Phase 5 form, `cb:
// (opt: BuildOptions) -> bool`). Like `set_post_link_callback` but a free
// fn (cb is arg 0, no self) and the callback receives the `BuildOptions`

View File

@@ -824,7 +824,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons
} else if (comp.getPostLinkModule()) |mod_name| {
const qualified = try std.fmt.allocPrint(allocator, "{s}.bundle_main", .{mod_name});
defer allocator.free(qualified);
const ret_opt = comp.invokeByName(qualified, false) catch |err| {
const ret_opt = comp.invokeByName(qualified, true) catch |err| {
const label = try std.fmt.allocPrint(allocator, "post-link module '{s}.bundle_main'", .{mod_name});
defer allocator.free(label);
printInterpBailDiag(&comp, label, err);