From 69fd76b02cf9defe53ba6cb685d13ba73a372254 Mon Sep 17 00:00:00 2001 From: agra Date: Fri, 26 Jun 2026 08:47:07 +0300 Subject: [PATCH] refactor: home the target facts in a dependency-free std/target.sx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move OS / ARCH / POINTER_SIZE + the OperatingSystem / Architecture enums out of build.sx into a new std/target.sx that imports NOTHING, so low-level code can name the target enum types without dragging the build/std barrel (build.sx transitively pulls std + compiler + bundle, ~16k lines of IR). build.sx flat-imports target.sx so the decls stay registered in the standard import graph (build.sx is reachable from std.sx — dropping it would shift every std program's type table). This is not a re-export: flat import only splices into build.sx's own scope. Consumers are unaffected — the compiler resolves OS / ARCH / POINTER_SIZE by name (comptime constants), so `inline if OS`/value reads need no import; a module that names the enum type imports target.sx. No behavior change (full suite green, 817/0); the enum types stay in the same import graph, so no .ir snapshot drift. --- library/modules/build.sx | 19 ++++++++++++------- library/modules/std/target.sx | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 library/modules/std/target.sx diff --git a/library/modules/build.sx b/library/modules/build.sx index 8d46107f..c2d1c02a 100644 --- a/library/modules/build.sx +++ b/library/modules/build.sx @@ -8,13 +8,18 @@ // (comptime-only, never emitted into the binary), and the build↔bundle import // cycle resolves like the std↔build one. #import "modules/platform/bundle.sx"; - -OperatingSystem :: enum { macos; linux; windows; wasm; ios; android; unknown; } -Architecture :: enum { aarch64; x86_64; wasm32; wasm64; unknown; } - -OS : OperatingSystem = .unknown; -ARCH : Architecture = .unknown; -POINTER_SIZE : i64 = 8; +// The target facts — OS / ARCH / POINTER_SIZE + the OperatingSystem / +// Architecture enums — live in a dependency-free module (std/target.sx) so +// low-level code can name the enum TYPES without the build/std baggage. +// build.sx imports it (flat) so those decls stay registered in the standard +// import graph (build.sx is reachable from std.sx — dropping the import would +// shift every std program's type table). This is NOT a re-export: flat import +// only splices the names into build.sx's own scope, never into build.sx's +// importers. Consumers need no import anyway — the compiler resolves OS / ARCH +// / POINTER_SIZE by name (comptime constants, for both `inline if` and value +// reads); a module that names OperatingSystem / Architecture imports +// std/target.sx directly. +#import "modules/std/target.sx"; // An opaque compile-time build-configuration handle. `build_options()` hands one // back; its real state lives on the compiler's threaded `BuildConfig`. The handle diff --git a/library/modules/std/target.sx b/library/modules/std/target.sx new file mode 100644 index 00000000..f7ec0541 --- /dev/null +++ b/library/modules/std/target.sx @@ -0,0 +1,23 @@ +// modules/std/target.sx — compiler-injected target facts. Dependency-free +// (imports NOTHING) so any low-level module can read the target enums/values +// without pulling the std barrel. +// +// The compiler sets OS / ARCH / POINTER_SIZE per build target (name-matched in +// src/imports.zig). NOTE: a top-level `inline if OS/ARCH/POINTER_SIZE` +// conditional is resolved by the compiler's flatten pre-pass and needs NO +// import at all (that is how std/net/epoll.sx selects its layout). Import this +// module only when you need the enum TYPE (`OperatingSystem` / `Architecture`) +// or a value in a non-`inline if` position. +// +// build.sx imports this (flat) so the decls stay registered in the standard +// import graph — NOT to re-export them (flat import doesn't propagate to a +// module's importers). Code that names the OperatingSystem / Architecture TYPE +// imports this module directly; OS / ARCH / POINTER_SIZE values and `inline if` +// conditions are resolved by the compiler by name and need no import. + +OperatingSystem :: enum { macos; linux; windows; wasm; ios; android; unknown; } +Architecture :: enum { aarch64; x86_64; wasm32; wasm64; unknown; } + +OS : OperatingSystem = .unknown; +ARCH : Architecture = .unknown; +POINTER_SIZE : i64 = 8;