From d8affd45e83439ba51cc9472da292e0f74d2f671 Mon Sep 17 00:00:00 2001 From: agra Date: Fri, 19 Jun 2026 08:17:35 +0300 Subject: [PATCH] rename std/build.sx -> modules/compiler.sx (the compiler-API surface) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per user direction: the low-level abi(.compiler) primitive surface is the comptime 'compiler' library, so name the file compiler.sx (a peer of build.sx) instead of the interim std/build.sx — which also frees the 'build' name for the default build IMPLEMENTATION (default_build + on_build slot), which will live in modules/build.sx alongside the BuildOptions DSL. Updated the two example imports + the plan's Phase 5 file-split note. 704/0 both gates. --- current/CHECKPOINT-COMPILER-API.md | 6 +-- current/PLAN-COMPILER-VM.md | 41 +++++++++++-------- .../1662-platform-build-pipeline-queries.sx | 2 +- examples/1663-platform-build-pipeline-link.sx | 2 +- library/modules/{std/build.sx => compiler.sx} | 17 ++++---- 5 files changed, 36 insertions(+), 32 deletions(-) rename library/modules/{std/build.sx => compiler.sx} (62%) diff --git a/current/CHECKPOINT-COMPILER-API.md b/current/CHECKPOINT-COMPILER-API.md index 6cafc89e..dfc3d160 100644 --- a/current/CHECKPOINT-COMPILER-API.md +++ b/current/CHECKPOINT-COMPILER-API.md @@ -88,7 +88,7 @@ with ONE welded mechanism. Branch: `reify` (off `master`). Update after every st > bails on legacy with `struct_get`); build succeeds (exit 0) only via the VM. `flushInterpOutput` deleted (VM > writes `out` direct via host-FFI). **702/0 both gates.** **P5.2 metadata queries DONE (2026-06-19, newest Log > entry):** `c_object_paths() -> List(string)` + `link_libraries() -> List(string)` are `abi(.compiler)` primitives -> (new stdlib home `library/modules/std/build.sx`), serviced by `comptime_vm.callCompilerFn` reading `BuildConfig` +> (new stdlib home `library/modules/compiler.sx`), serviced by `comptime_vm.callCompilerFn` reading `BuildConfig` > fields `main.zig` forwards (`c_object_paths`/`link_libraries`). New reusable VM helper `makeStringList` builds a > `List(string)` in flat memory (target-aware via the result type's offsets); `invoke`/`callCompilerFn` now thread > the call's result type (`ins.ty`). Legacy handlers bail loudly (VM-only by nature — post-link). Smoke test @@ -424,7 +424,7 @@ when reached (sentinels or accessor fns; see the design doc Risks). ## Log - **P5.2b (`link` ACTION) — the sx `link` primitive links on the VM via a host-installed vtable; build callback de-failable'd (2026-06-19).** Phase 5's one genuine ACTION primitive: `link(objects, output, libraries, frameworks, flags, target)` (in - `library/modules/std/build.sx`). **USER DECISION this step: drop fallibility from the build callback** — so + `library/modules/compiler.sx`). **USER DECISION this step: drop fallibility from the build callback** — so `link` is a plain VOID primitive (no `-> !`), and a link failure BAILS on the VM → hard build error (sidesteps the failable-tuple-return construction entirely). **The vtable:** `comptime_vm.zig` can't depend on the driver (`core`/`main`/`target`), so `link` dispatches through a new `compiler_hooks.BuildHooks { ctx, link_fn }` that @@ -444,7 +444,7 @@ when reached (sentinels or accessor fns; see the design doc Risks). - **P5.2 (metadata queries) — `c_object_paths` / `link_libraries` compiler primitives + the VM `List(string)` builder (2026-06-19).** Phase 5 step 2 (the read-only slice): two `abi(.compiler)` primitives that the sx build driver will pass to `link` — `c_object_paths() -> List(string)` (the `#import c` companion `.o`s) and `link_libraries() -> List(string)` - (the `#library` names). They live in a NEW stdlib file `library/modules/std/build.sx` (the Phase 5 home the sx + (the `#library` names). They live in a NEW stdlib file `library/modules/compiler.sx` (the Phase 5 home the sx `default_build` grows into) and are serviced by `comptime_vm.callCompilerFn` reading two new `BuildConfig` fields (`c_object_paths`/`link_libraries`) that `main.zig` forwards before the post-link callback (alongside `binary_path`/`target_triple`/…). **Reusable new piece:** `Vm.makeStringList(table, list_ty, items)` builds a diff --git a/current/PLAN-COMPILER-VM.md b/current/PLAN-COMPILER-VM.md index 38c7faf6..82a8341a 100644 --- a/current/PLAN-COMPILER-VM.md +++ b/current/PLAN-COMPILER-VM.md @@ -471,27 +471,32 @@ a few `abi(.compiler)` PRIMITIVES that take **explicit args** (so nothing is sha keeps the proven Zig linker as a primitive; sx owns config + orchestration + bundle. (Option A — sx shells `cc`/`ld` itself — is a later refinement once the per-target link-line logic is ported to sx.) -Shape (all syntax verified on the current build 2026-06-18 — void `#run`, `-> !` / `-> !E` failable `#run`, -a `raise` at `#run` fails the build with a return trace): +**File split (user decision 2026-06-19):** the low-level compiler-API PRIMITIVES live in +`library/modules/compiler.sx` (the comptime `compiler` library — renamed from the interim `std/build.sx`); the +default `build` IMPLEMENTATION (`default_build` + the `on_build` slot + the sx `BuildConfig`) lives in +`library/modules/build.sx` alongside the existing `BuildOptions` DSL. So `compiler.sx` = primitives, `build.sx` = +orchestration/default impl. **Build-callback fallibility was DROPPED (user 2026-06-19):** the primitives + the +build callback are NOT `-> !` — a failed action (e.g. `link`) BAILS on the VM (hard build error). So the shapes +below shed their `-> !`. + +Shape (build-callback fallibility dropped 2026-06-19): ```sx -// library/modules/std/build.sx (stdlib) -BuildErr :: error { EmitFailed, LinkFailed, BundleFailed } -BuildConfig :: struct { output: string; target: string; flags: List(string); - frameworks: List(string); bundle_path: string; bundle_id: string; - is_macos :: (self: *BuildConfig) -> bool { ... } - add_framework :: (self: *BuildConfig, n: string) { self.frameworks.append(n); } } -// compiler primitives — explicit args, failure on the error channel (NO bool): -emit_object :: () -> !string abi(.compiler); // IR → .o path +// library/modules/compiler.sx (the comptime `compiler` library — PRIMITIVES) +emit_object :: () -> string abi(.compiler); // emitted .o path (query) link :: (objects: List(string), output: string, libraries: List(string), - frameworks: List(string), flags: List(string), target: string) -> ! abi(.compiler); + frameworks: List(string), flags: List(string), target: string) abi(.compiler); // void; bails on failure c_object_paths :: () -> List(string) abi(.compiler); // metadata queries link_libraries :: () -> List(string) abi(.compiler); -default_build :: (config: BuildConfig) -> ! abi(.compiler) { // the default pipeline - obj := try emit_object(); objs := c_object_paths(); objs.append(obj); - try link(objs, config.output, link_libraries(), config.frameworks, config.flags, config.target); - if config.bundle_path.len > 0 { try bundle_app(config); } } // bundle_app = today's sx bundler -on_build : (BuildConfig) -> ! abi(.compiler) = default_build; // the override slot -// user overrides: build :: (config: BuildConfig) -> ! abi(.compiler) { ... } #run on_build = build; + +// library/modules/build.sx (the build DSL — DEFAULT IMPLEMENTATION + slot) +BuildConfig :: struct { output: string; target: string; flags: List(string); + frameworks: List(string); bundle_path: string; bundle_id: string; ... } +default_build :: (config: BuildConfig) abi(.compiler) { // the default pipeline (void) + obj := emit_object(); objs := c_object_paths(); objs.append(obj); + link(objs, config.output, link_libraries(), config.frameworks, config.flags, config.target); + if config.bundle_path.len > 0 { bundle_app(config); } } // bundle_app = today's sx bundler +on_build : (BuildConfig) abi(.compiler) = default_build; // the override slot +// user overrides: build :: (config: BuildConfig) abi(.compiler) { ... } #run on_build = build; ``` The compiler's whole post-IR role: codegen → build the CLI-derived `BuildConfig` → read `on_build` → invoke `on_build(config)` on the VM; a `raise` fails the build. Plain `sx run` fires none of it. @@ -505,7 +510,7 @@ The compiler's whole post-IR role: codegen → build the CLI-derived `BuildConfi bails on legacy with `struct_get`), so the build succeeds (exit 0) only via the VM. Non-empty callback `args` rejected loudly (the `on_build(config)` arg-marshaling entry is P5.3). **702/0 both gates.** - **P5.2 — primitives.** Split: the read-only **metadata queries are DONE (2026-06-19)** — `c_object_paths() -> - List(string)` + `link_libraries() -> List(string)` as `abi(.compiler)` fns (stdlib `library/modules/std/build.sx`), + List(string)` + `link_libraries() -> List(string)` as `abi(.compiler)` fns (stdlib `library/modules/compiler.sx`), serviced by `comptime_vm.callCompilerFn` over `BuildConfig` fields `main.zig` forwards; new VM `makeStringList` builds the `List(string)` in flat memory from the call's result type (`ins.ty` now threaded through `invoke`/`callCompilerFn`). Smoke test `1662-platform-build-pipeline-queries` (AOT + C companion). 703/0 both diff --git a/examples/1662-platform-build-pipeline-queries.sx b/examples/1662-platform-build-pipeline-queries.sx index 8498ffb9..60a11872 100644 --- a/examples/1662-platform-build-pipeline-queries.sx +++ b/examples/1662-platform-build-pipeline-queries.sx @@ -1,6 +1,6 @@ #import "modules/std.sx"; #import "modules/build.sx"; -#import "modules/std/build.sx"; +#import "modules/compiler.sx"; // P5.2 smoke test — the build-pipeline query primitives (`c_object_paths` / // `link_libraries` / `emit_object`) run on the comptime VM: the list queries diff --git a/examples/1663-platform-build-pipeline-link.sx b/examples/1663-platform-build-pipeline-link.sx index 68a0de65..8e90d0f7 100644 --- a/examples/1663-platform-build-pipeline-link.sx +++ b/examples/1663-platform-build-pipeline-link.sx @@ -1,6 +1,6 @@ #import "modules/std.sx"; #import "modules/build.sx"; -#import "modules/std/build.sx"; +#import "modules/compiler.sx"; // P5.2b smoke test — the `link` build-pipeline ACTION runs on the comptime VM, // dispatching through the host-installed linker hook (the VM can't link itself). diff --git a/library/modules/std/build.sx b/library/modules/compiler.sx similarity index 62% rename from library/modules/std/build.sx rename to library/modules/compiler.sx index bb804a1b..2975bd8a 100644 --- a/library/modules/std/build.sx +++ b/library/modules/compiler.sx @@ -1,13 +1,12 @@ -// Phase 5 — sx-driven build pipeline (compiler primitives). +// The comptime `compiler` library — the low-level compiler-API surface. // -// These run in the comptime evaluator (`abi(.compiler)`), serviced by -// `comptime_vm.callCompilerFn`. They are called from the post-link build driver -// (a callback registered via `set_post_link_callback`), which always runs on the -// comptime VM (`core.invokeByFuncId`) — the VM, unlike the legacy interpreter, -// can allocate/grow the `List`s the driver builds (issue 0141). -// -// This is the home the sx `default_build` pipeline grows into; for now it exposes -// the read-only build metadata queries. +// These primitives run in the comptime evaluator (`abi(.compiler)`), serviced by +// `comptime_vm.callCompilerFn`. They are the building blocks of the sx-driven +// build pipeline (Phase 5); the default `build` implementation that orchestrates +// them lives in `modules/build.sx`. They are reached from the post-link build +// driver (a callback registered via `set_post_link_callback`), which always runs +// on the comptime VM (`core.invokeByFuncId`) — the VM, unlike the legacy +// interpreter, can allocate/grow the `List`s the driver builds (issue 0141). #import "modules/std.sx"; // The C companion object files for this build (`#import c { #source ... }`,