Expand description
Multi-file project compilation (v0.3 §3.2 and §3.3, v0.4 §3.5).
A “project” is a directory tree of .bynk source files. The dotted name
of a commons or context (e.g., bynk.time, commerce.orders) maps to a
path under the project root — either a single file (bynk/time.bynk) or
a directory of files all sharing the same header (bynk/time/*.bynk).
v0.4: each file is one of two kinds — commons or context. Both kinds share
the same multi-file directory machinery; they differ in body content
(contexts have consumes/exports, types are nominally per-context), in
visibility (contexts export only the types listed), and in TypeScript
emission (contexts re-brand types from used commons).
Compilation proceeds in two passes:
- Discover and parse every
.bynkfile. Group by qualified name and kind. Build a global symbol table where each unit contributes its declarations. - Resolve, type-check, and emit each unit with full visibility of
the units it transitively
usesorconsumes. Two passes keepusescycles trivial — there is no order-of-evaluation, only declarative mixin.
Structs§
- Attributed
Error - v0.24 (ADR 0052): a compile error attributed — where possible — to the
project-relative source file it belongs to, tagged at the collection
point (the phase that produced it knows which file it was processing).
Noneis the project-level bucket: validations spanning files (group/cycle/directory consistency) with no single owning file. - Compile
Options - Options for
compile_project. Construct withCompileOptions::singleorCompileOptions::split, then chain.target(…)/.platform(…)/.import_ext(…)to override the bundle/default-platform/.jsdefaults. - Compiled
File - One generated TypeScript file.
- Discovered
Case - One discovered
test "<name>"case.locationpoints at the case-name literal (a run failure instead points at the failingassert), giving the editor click-through to the declaration before any run. - Discovered
Suite - v0.67: a discovered test suite — one
test <target>group (unit) ortest integration "<suite>"(integration).name+kindmirror exactly what the NDJSON runner emits atsuite-begin(kind"unit"carries the joined target name;"integration"carries the bare suite name), so the editor reconciles discovery and run documents to the same tree items. - Emit
Project Ctx - Context passed to the emitter so it can resolve cross-file and cross-unit references into TypeScript import statements.
- File
Decl Index - For each name declared in the unit (type, fn, method), record which source file declared it. Used by the emitter to render relative imports.
- Project
Analysis - v0.24: the analyse-mode result — every discovered file’s analysed text snapshot (positions must convert against the text that was analysed, not a newer buffer) plus the attributed diagnostics.
- Project
Failure - v0.24: a failed build with its attribution and snapshots intact — what
the CLI renders rich (ariadne source context per file); the plain
compile_project*wrappers flatten it to the pre-v0.24 error list. - Project
Output - Result of compiling a project.
- Project
Paths - v0.113 (DECISION S): the project’s source tree, read from
bynk.toml’s[paths]section. Test-ness is a property of thesuitedeclaration, not of a directory, so the layout is a flatincludelist of trees to compile and anexcludelist of subtrees to skip — not the role-namedsrc/testssplit. Eachincludeentry is a root walked for.bynkfiles; a file’s identity path is relative to theincluderoot that contains it. - Test
Location - A project-root-relative
path:line:colsource location, structured. Line and col are 1-indexed (the [bynk_syntax::span::line_col] convention). - Unit
Table - Combined symbol tables for a single logical commons or context.
Enums§
- Boundary
Owner - Where a boundary-crossing type was declared.
- Build
Target - The build target. Determines how cross-context calls and per-context modules are emitted (v0.8). Bundle mode is the default — all contexts emit into one TypeScript bundle and cross-context calls are direct function invocations. Workers mode produces per-context Cloudflare Worker bundles that communicate via Service Bindings.
- Import
Ext - The extension emitted import specifiers use (
import … from "./x.<ext>"). - Roots
- Where a project’s
.bynkfiles live. - Unit
Kind - Distinguishes a commons from a context (and from a test) in the project graph. Tests are a third kind in v0.7.
Functions§
- analyse_
in_ memory - Analyse a single in-memory Bynk source and return all diagnostics —
non-bailing, no emission (in-browser track, slice 5d). The editor calls this
on every (debounced) keystroke for live diagnostics: unlike
compile_in_memory(build mode, which bails at the first failing phase), this runs inAnalysemode, so parse / resolve / check diagnostics are recovered and reported together — and it works for acontext(the playground’s typical program), not only a commons. Same fs-free seam ascompile_in_memory. - analyse_
project - v0.24: analyse a project without building — non-bailing, overlay-aware,
file-attributed (ADR 0052).
overlaymaps canonicalised absolute paths to buffer text layered over disk reads (unsaved editor buffers). - check_
function_ type_ boundary_ items - Item-level body of the boundary confinement, shared with the single-file
(legacy) compile path in
bynkc’slib.rs. - compile_
in_ memory - Compile a single in-memory Bynk source through the full project pipeline —
no filesystem access (in-browser track, slice 3). The source is the in-process
Bundlesubset thatconsumes bynk; first-party injection and the per-platform binding emission run exactly as for an on-disk build, so the returnedProjectOutputis the complete module graph (the user unit +runtime.ts+ thebynk-<platform>.tsbinding +compose.ts). The wasm entry point pairs this withbynk-stripto produce JavaScript for the playground. - compile_
project - Compile a Bynk project, keeping error attribution + snapshots on failure
(so the CLI can render project errors with source context, ADR 0052). Use
.map_err(ProjectFailure::flatten)for the flattenedVec<CompileError>shape. - read_
project_ paths - v0.113: read
bynk.tomlfromproject_root. Returns the conventional layout (seeProjectPaths::conventional) if the file is missing or declares no[paths] include. Honoursinclude/excludeunder[paths], each an array of path strings; anything else is ignored. A minimal hand-rolled TOML reader — we only need string and string-array values here. - worker_
dir_ name - v0.8: directory name of a Worker for a given context, with dots replaced
by dashes (
commerce.payment→commerce-payment). - worker_
handlers_ output_ path - v0.8: project-relative output path of the workers-mode handlers file.
- worker_
handlers_ source_ path - v0.8: project-relative synthetic source path of the workers-mode handlers file for a given context. Used so the emitter’s relative-import machinery resolves correctly against the workers layout.