rename std/build.sx -> modules/compiler.sx (the compiler-API surface)

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.
This commit is contained in:
agra
2026-06-19 08:17:35 +03:00
parent f7362ee013
commit d8affd45e8
5 changed files with 36 additions and 32 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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).

View File

@@ -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 ... }`,