This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

Compiler

import std/compiler

compiler.kz · 45 tors · ~[comptime]

flag.declare

comptimenorun koru_std/compiler.kz:726

paths

comptimenorun koru_std/compiler.kz:752

command.declare

comptimenorun koru_std/compiler.kz:794

coordinate

comptimeabstract koru_std/compiler.kz:802

elaborate

comptimeabstract koru_std/compiler.kz:931

analysis

comptimeabstract koru_std/compiler.kz:943

transform-taps

comptimeabstract koru_std/compiler.kz:961

test-generation

comptimeabstract koru_std/compiler.kz:996

emission

comptimeabstract koru_std/compiler.kz:1488

evaluate-comptime

koru_std/compiler.kz:1506

check-release-gate

koru_std/compiler.kz:1510

check-phantom-signatures

koru_std/compiler.kz:1529

check-phantom-args

koru_std/compiler.kz:1541

pass-auto-discharge

koru_std/compiler.kz:1547

check-phantom-semantic

koru_std/compiler.kz:1553

~part flags koru_std/compiler.flags.kz

Compiler flags

~part commands koru_std/compiler.commands.kz

Command surface — gated command imports and flag declarations for the CLI-facing verbs every program carries (310_146, 310_145). The `explain` command rides along under its own gate: every program can run `koruc <file> explain` (and see it in `help`) without a user-side import — the command= provider atom decides, not the file (310_146).

~part control koru_std/compiler.control.kz

Compiler pipeline control flow. [template] constructs (std/control:if, cond, for) splice host source text and only expand where the per-call template pass reaches. Compiler pipeline definitions — coordinate overrides and other impl-of-comptime flows — are rebuilt downstream of that pass, so templates never expand there; the fallback (calling the unreachable stub handler) always fails. Branch here on VALUES instead: a plain proc returning a branch union lowers in every position — pipeline overrides, walked flows, and plain runtime code.

~part paths koru_std/compiler.paths.kz

Koru Standard Library: the `paths` part of compiler.kz. Joined via `~part paths` in compiler.kz; merged into the compiler module at load. Helper: Join path segments with dots IMPORTANT: Takes an allocator to return heap-allocated memory (stack memory was causing corruption!)

~part context koru_std/compiler.context.kz

Koru Standard Library: the `context` part of compiler.kz — the compile-time context and diagnostic surface. Joined via `~part context` in compiler.kz; merged into the compiler module at load. `CompilerContext` threads state for all passes; `ErrorReporter` is the diagnostic channel re-exported under this module's name so a pass or a `[comptime|transform]` tor can spell it `std/compiler:ErrorReporter`. `std`, `ast` and `Program` are imported by the parent's preamble. The diagnostic channel, re-exported under this module's name so a pass or a `[comptime|transform]` tor can spell it `std/compiler:ErrorReporter`. `CompilerError` below is message-plus-location; this carries the code, the hint and the source preview that make a koru diagnostic look like one.

~part dump koru_std/compiler.dump.kz

Koru Standard Library: the `dump` part of compiler.kz. Joined via `~part dump` in compiler.kz; merged into the compiler module at load. Helper: Dump AST as JSON for introspection Usage: Insert at key points in pipeline to inspect AST state Void tor - just prints and continues Example: ast-dump(ctx: c, flag: "elaborate") |> ...

ast-dump

comptime koru_std/compiler.dump.kz:9

~part directives koru_std/compiler.directives.kz

Koru Standard Library: the `directives` part of compiler.kz — frontend-read compiler directives. Joined via `~part directives` in compiler.kz; merged into the compiler module at load. These tors are never dispatched: [norun] prevents auto-execution and the FRONTEND reads the invocation from the AST — discovered by parsing, not hardcoded. `requires` declares backend build requirements (build.zig generation is metacircular this way); `use` pins the backend itself to a minted compiler — it is consumed and stripped before backend emission, so the mint name never reaches the closure it selects.

requires

comptimenorun koru_std/compiler.directives.kz:11

~part stages koru_std/compiler.stages.kz

Koru Standard Library: the `stages` part of compiler.kz. Joined via `~part stages` in compiler.kz; merged into the compiler module at load. The pre-emission AST stage procs: the per-call template pass and the `.pre` transform stage that must run before it. They live apart from the pass-runner body because they are a named family — graft-aware ordering is their whole contract. Template processor: walks AST, renders any proc whose variant chain starts with `template|...` through Liquid, then strips the `template` tag so downstream emission sees a plain host-language proc. See memory project_proc_variant_pipeline / docs/EFFECT_BRANCHES for the `host[:processor]` story this implements.

process-template-procs

koru_std/compiler.stages.kz:14

~part prelate koru_std/compiler.prelate.kz

Koru Standard Library: the `prelate` part of compiler.kz. Joined via `~part prelate` in compiler.kz; merged into the compiler module at load. The pre-template transform sprinkle: runs the `.pre` stage (producers — component, store, channel) then `.pre_late` (consumers — std/ctx reads synthesized decls) BEFORE the per-call template pass, so consumer output is ordinary AST that expands normally. `.main`/`.post` still run at Phase 2.4 (evaluate-comptime); `.pre*` transforms carry @pass_ran so the later all-stages run re-visits them as no-ops.

~part materialize koru_std/compiler.materialize.kz

Compiler target routing + artifact materialization target-of reads the compile target (--lang / CompilerEnv.lang) and selects the matching emission arm; emit-js / emit-cs are the non-zig target emitters; the emit-*-artifact chains spell what emission does with the code string once it exists — write the artifact, validate it, invoke the host toolchain. Ordinary tors in the pipeline: a user emission override can drop, reorder, or interpose on any of them. Emit-only pipelines and custom Stage-D verbs are user-space decisions, not driver privileges. ARTIFACT MATERIALIZATION - what emission does with the code string once it exists. These are ordinary tors: write the artifact, validate it, invoke the host toolchain. A user emission override can drop, reorder, or interpose on any of them — emit-only pipelines and custom Stage-D verbs are user-space decisions, not driver privileges. Per-target composed artifact chains — one entry per target-of arm. `output` names the produced binary (defaults to the -o argv name); `dir` stages the emitted artifact under a directory instead of cwd.

~part materialize-build koru_std/compiler.materialize-build.kz

Compiler host-build drivers — Stage D of artifact materialization host-build-zig and host-build-cs are the pipeline-visible toolchain verbs: zig build / build-exe / dotnet build, the csproj driver, the overlay + optimize-mode + cross-target reads. Ordinary tors like the rest of materialization — a user emission override can swap them, interpose around them, or drop them for an emit-only pipeline. `output` names the produced binary (overrides the -o argv name); `dir` is where write-artifact staged the emitted source. Stage D for the Zig target: zig build (via build_output.zig when the program declared build:requires) or a direct build-exe, then place the artifact at the -o name. Failures exit non-zero — the compile's verdict IS the build's verdict. `output` overrides the -o argv name; `dir` is where write-artifact staged output_emitted.zig.

~part materialize-csbuild koru_std/compiler.materialize-csbuild.kz

C# Stage D — the dotnet driver of artifact materialization. A minimal csproj IS the driver (dotnet has no file-based run): OutputType flips with koruc lib (Exe apphost vs callable .dll), AssemblyName lands the artifact at the -o path. Ordinary pipeline tor — swappable by a user emission override like every other materialization step. Stage D for the C# target: a minimal csproj IS the driver — dotnet has no file-based run, so the apphost lands at exactly the path koruc was asked for via AssemblyName. `koruc lib` flips OutputType to Library — the artifact is a callable .dll (ASP.NET-loadable), not an apphost.

~part with koru_std/compiler.with.kz

Koru Standard Library: the `with` part of compiler.kz. Joined via `~part with` in compiler.kz; merged into the compiler module at load. resolve-with-scopes: the [with] vocabulary pass and its helpers. [with] scoped-vocabulary resolution (641_010; concept frag-with-declares-the-flows-vocabulary). Stage-A canonicalize stamps the MAIN module onto every bare name with no import lookup, so a bare `match` inside a grammar region arrives here as `<main>:match` and would die as an unknown tor. `[with]` colors its whole flow — position is meaningless, the gather runs over the entire subtree before any restamp — and the open set is the union of every opener it finds: bare `[with]` derives the annotated invocation's own module, `[with(a, b)]` names modules explicitly (import-spelled, and each must be imported — KORU142). A bare name stamped to its flow's home module that is NOT a real tor there but IS a real tor of an opened module is re-qualified to it; matching is on the full dotted event name, so `say.hi` and `log.hi` never collide on `hi`. Unresolved-only — a name that genuinely resolves at home is never shadowed. Runs BEFORE run-pre-transforms so the grammar transform (parser.kz `isVerb` keys off the qualifier being present) sees the resolved `std.parser:match`. Mirrors canonicalize_names' own flow/continuation/node recursion, so it visits exactly the paths it does.

resolve-with-scopes

koru_std/compiler.with.kz:24

~part desugars koru_std/compiler.desugars.kz

Koru Standard Library: the `desugars` part of compiler.kz. Joined via `~part desugars` in compiler.kz; merged into the compiler module at load. The chain-desugar stage tor: point-free pyramid, bind pun + type thread, flow return terminus, and the dead-produce audit — the pass that must run after resolve-with-scopes, where every callee name is finally visible. The AST desugars: the point-free pyramid, the bind pun + type thread, and the flow return terminus. They live HERE, and not in koruc, because each one looks a declaration up BY PATH. Stage-A canonicalize stamps `<main>:` onto every bare name, so a `[with]`-scoped name is not resolvable until `resolve-with-scopes` has run. A desugar running before that found no declaration, silently did nothing, and left the failure to surface passes later wearing a different name — an undischarged obligation, or a KORU100 for a binding whose only use the pun never filled. Ordering, not a lookup bug. Order among the three is load-bearing: the pyramid first, so the canonical explicit-continuation shape exists; then the pun and thread, so every step's args are in place; then the terminus, which needs the last step final.

~part ccp koru_std/compiler.ccp.kz

Koru Standard Library: the `ccp` part of compiler.kz. Joined via `~part ccp` in compiler.kz; merged into the compiler module at load. CCP Observability Injection Pass Injects universal observability taps into the user's AST This makes every compiled program self-observing by adding emit_json and * -> * tap

process-ccp-commands

koru_std/compiler.ccp.kz:25