P5.4 core: drive the whole build from sx default_pipeline (no auto-emit/link)

The compiler's post-IR role shrinks to: codegen -> invoke the build callback.
There is NO Zig auto-emit / auto-link anymore; emit + link are sx-called actions.

- emit_object() is now an ACTION (verify + emit via a host BuildHooks vtable),
  returning the object path. New query primitives build_output/build_target/
  build_frameworks/build_flags (data reads from the merged BuildConfig).
- library/modules/build.sx imports compiler.sx and defines default_pipeline:
  emit_object -> gather c_object_paths -> link(objs, output, libs, fws, flags,
  target). The std<->build import cycle is handled by the resolver.
- The compiler FORCE-LOWERS default_pipeline (well-known name) and AUTO-INVOKES
  it post-codegen when no on_build/set_post_link_callback override was
  registered (driver's final fallback: invokeByName default_pipeline).
- Prelude-less programs (e.g. asm tests) don't import build.sx, so the BUILD
  path auto-imports modules/build.sx (idempotent if already transitive) so
  default_pipeline is always available. JIT sx run is untouched (emits in-process).
- Removed the build cache short-circuits (incompatible with the always-run sx
  driver; a future cache can live in default_pipeline).

Benign 37-.ir churn (build.sx grew); zero behavior changes (verified diff is
.ir-only). 705/0 both gates.
This commit is contained in:
agra
2026-06-19 09:22:54 +03:00
parent 1f796e92ec
commit d178454841
44 changed files with 93042 additions and 80510 deletions

View File

@@ -155,6 +155,14 @@ fn isExportedEntryName(name: []const u8) bool {
std.mem.startsWith(u8, name, "Java_");
}
/// The well-known stdlib build driver (`library/modules/build.sx`). It is invoked
/// by the compiler post-codegen when no `#run on_build(...)` override exists, but
/// is never CALLED from sx — so it must be force-lowered like an OS entry point,
/// else lazy lowering leaves it a bodiless `declare` stub the VM can't run.
fn isDefaultBuildPipeline(name: []const u8) bool {
return std.mem.eql(u8, name, "default_pipeline");
}
/// Lower all top-level declarations from a root node.
/// Pass 1: Scan all declarations (register ASTs, types, extern stubs).
/// Pass 2: Lower only `main` (everything else is lowered lazily on demand).
@@ -222,6 +230,12 @@ pub fn lowerRoot(self: *Lowering, root: *const Node) void {
self.checkInfiniteSize();
// Pass 2: lower main (and comptime side-effects)
self.lowerMainAndComptime(decls);
// Pass 2b: force-lower the stdlib build driver `default_pipeline` (in the
// flat-imported `modules/build.sx`, so NOT in the main `decls` above). The
// compiler auto-invokes it post-codegen when no `#run on_build(...)` override
// exists, but nothing CALLS it from sx — so without this it stays a bodiless
// stub the build VM can't run. No-ops when build.sx isn't imported.
self.lazyLowerFunction("default_pipeline");
// Pass 3: lower deferred functions (any_to_string etc.) now that all types are registered
self.lowerDeferredTypeFns();
// Pass 4: target-specific entry-point sanity checks
@@ -1457,7 +1471,7 @@ pub fn lowerMainAndComptime(self: *Lowering, decls: []const *const Node) void {
// consumption (often never called from sx), so force-lower
// them like OS-called entry points — else lazy lowering
// leaves them as bodiless `declare` stubs (Phase 2).
if (isExportedEntryName(cd.name) or cd.value.data.fn_decl.extern_export == .export_) {
if (isExportedEntryName(cd.name) or cd.value.data.fn_decl.extern_export == .export_ or isDefaultBuildPipeline(cd.name)) {
self.lazyLowerFunction(cd.name);
}
} else if (cd.value.data == .comptime_expr) {