Expand description
Code generator trait and output types.
Structs§
- Enum
Variant Info - What the registry knows about one enum variant: the enum it belongs to and its payload shape.
- EsmExport
- One exportable, runtime-valued public declaration of a module: the raw
emitted name plus whether it is a function (camelCased on emit). Returned by
exportable_value_names. - EsmSymbol
- One public symbol exposed by the per-module ESM analysis. Carries the
declaring module-path and the declaration kind. The kind drives both the
emitted-name transform (only a function is camelCased:
get_or→getOr) and the import form each backend selects (value vsimport typevs skip in JS) — seeEsmDeclKind. - Generated
Code - Output from code generation — consistent across all targets.
- Implicit
EsmImport - One implicit cross-module import computed by
implicit_esm_imports_for: the declaring module-path, the raw symbol name, and the declaration kind (so the backend can camelCase a function, route a type toimport type, or skip a JS type-only name). - Output
File - A single generated output file.
- Source
Info - Metadata for a source file referenced by a
SourceMap. - Source
Map - Maps AIR source spans to generated code spans.
- Source
MapEntry - A single source-map entry linking an AIR span to a target span.
- Source
Mapping - A single pointwise mapping from a position in generated code to a position in the originating Bock source.
- Test
Artifacts - The output of
CodeGenerator::generate_tests: the transpiled test files plus an optional snippet appended to the entry file. - Trait
Decl Info - What the registry knows about one trait declaration: its declared generic
parameters and its methods (each an
AIRNode::FnDecl), partitioned by the caller viais_default_method.
Enums§
- EsmDecl
Kind - The declaration kind of a public symbol exposed by the per-module ESM
analysis. Each backend maps this to the right cross-module import form,
because the JS and TS emitted shapes differ (a trait is a JS
constmixin value but a TSinterfacetype; an enum type name has no JS binding but is a TS type; a type alias is erased in JS but a TS type). - Keyword
Target - The codegen target whose reserved-word set an identifier is being escaped against. Mirrors the five v1 backends.
- Test
Assertion - A recognized Bock test assertion (
expect(actual).<method>(...)). - Variant
Payload Kind - The payload shape of an enum variant, as needed to lower a construction or a match arm in any target.
Constants§
- DECL_
ONLY_ META - Metadata key marking a synthesised temp
NodeKind::LetBindingas declare-only: it introduces the binding with no initialiser. The sharedhoist_value_cfdesugar emits these; every backend’sletemitter checks this key and emits the bare declaration (let x;/var x T/ Rust deferredlet mut x;) rather than a= <value>initialiser. The carriedbock_air::stubs::Value::Boolis alwaystrue. - ESM_
RUNTIME_ PRELUDE_ NAMES - Runtime-prelude value names that the JS/TS backends lower inline to
tagged objects (
{ _tag: "Some", _0: v },{ _tag: "Less" }, …) — NOT from a cross-modulecore.*import. The implicit-import pass and the public-symbol map must never route these through acore.option/core.compareimport: the declaring module does not actually export them (they are compiler built-ins), so a real import would be an unresolved reference. - FUNCTIONAL_
LIST_ METHODS - The functional
Listbuilt-in methods that take a closure argument and must be lowered to each target’s native iteration idiom (seedesugared_list_functional_method). - INPLACE_
LIST_ MUTATORS - The DQ30 in-place
Listmutators, lowered natively per target viadesugared_list_inplace_mutator. All aremut self(E5004-enforced like DQ18’spush/append); the per-method contracts: - MAP_
METHODS - The built-in
Map[K, V]methods this codegen lowers natively per target. - MUTATING_
LIST_ METHODS - The in-place
Listmutators (DQ18) lowered natively per target viadesugared_list_mutating_method. These resolve in the checker to aVoidreturn and require amutreceiver (enforced by the ownership pass), so each backend emits them in statement position as a value-less mutation: - OPTIONAL_
METHODS - The built-in
Optional[T]methods this codegen lowers on the tagged value. - ORDERING_
VARIANTS - The three variants of the prelude
Orderingenum (core.compare), in the order the comparison ladder produces them. - PRIMITIVE_
BRIDGE_ METHODS - The primitive trait-bridge methods this codegen lowers to a target intrinsic.
- PRIMITIVE_
CONVERSION_ TARGETS - The set of primitive type names that can appear as the callee of a
canonical primitive associated conversion (
Prim.from(x)/Prim.try_from). - READ_
ONLY_ LIST_ METHODS - The read-only / non-mutating
Listbuilt-in methods this codegen lowers natively per target (seedesugared_list_method). The in-place mutators are excluded:push/appendlower viadesugared_list_mutating_method(DQ18) andpop/remove_at/insert/reverse/setviadesugared_list_inplace_mutator(DQ30). - RESULT_
METHODS - The built-in
Result[T, E]methods this codegen lowers on the tagged value. - SET_
METHODS - The built-in
Set[E]methods this codegen lowers natively per target. - STRING_
METHODS - The built-in
Stringmethods this codegen lowers to each target’s native string ops.
Traits§
- Code
Generator - The trait all per-target code generators implement.
- JsTs
Expr Emitter - Lowers a single AIR expression to its target string, for the shared js/ts
test-file builder. Implemented by a thin adapter over each backend’s private
emit context so
js_ts_generate_testscan reuse the exact expression lowering the runtime tree uses (function casing, enum/Optional reps, …).
Functions§
- arm_
body_ is_ statement - Returns true if a
match-arm body is a statement body — either the body is itself a statement node, or it is a{ ... }block whose tail is a statement node (or which has no tail at all, e.g. a block ending in a statement with no value). - assoc_
fn_ def - True when an impl/trait
method(anbock_air::NodeKind::FnDecl) is an associated function — it does not bind a leadingselfreceiver, so it is reached asType.method(...)rather thanvalue.method(...). - classify_
assertion - If
stmtis anexpect(actual).<assertion>(expected?)chain, classify it. - collect_
class_ fields - Collect every class declared across
modules, mapping each class name to its field names in declaration order. - collect_
const_ names - Pre-scan every reached module and collect the declared names of all
module-scope
consts. - collect_
enum_ variants - Pre-scan every reached module and build the
EnumVariantRegistry. - collect_
exported_ type_ names - Pre-scan every module’s top-level type declarations and collect the names of
those declared
public(records, enums, traits, classes). A backend that emits a declaration-merging companion (TS’sinterface Targetthat mirrors animpl’s prototype methods) needs this: TS requires every declaration in a merged declaration to agree on export-ness, so the companioninterfacemust beexported exactly when the target type is. Mirrorscollect_generic_decls. - collect_
generic_ decls - Pre-scan every reached module and build the
GenericDeclRegistry. Records the generic parameters declared on each top-levelRecordDecl,EnumDecl, andClassDecl. Non-generic decls are recorded with an empty parameter list (their presence still lets a backend distinguish a known concrete type from an unknown one). - collect_
public_ symbol_ modules - Build a map from every public top-level symbol name declared across
modulesto the dotted declared module-path that declares it (e.g.Iterable→core.iter). Covers functions, records, enums (the type name), traits, classes, effects, type aliases, and consts. - collect_
public_ symbols_ for_ esm - Build a map from every public top-level symbol name (the raw Bock name)
declared across
modulesto itsEsmSymbol(declaring module-path + whether it is a function). Covers functions, records, enums (and each variant’s emittedEnum_Variantfactory/const name), traits, classes, effects, type aliases, and consts. - collect_
record_ field_ names - Collect every record/class field name in the module, mapped through the
backend’s
casedname function (to_pascal_casefor Go,to_camel_casefor js/ts, identity/snake for Python). Backends use the returned set withdisambiguate_method_nameto detect a method whose emitted name collides with a field’s emitted name. - collect_
record_ names - Collect the names of every record declared across
modules(the names the JS/TS backends emit as classes and construct withnew Name(...)). - collect_
test_ fns - Collect every
@test-annotated top-level function across the given modules, paired with the module’s declared path (dotted, or""if anonymous). - collect_
trait_ decls - Pre-scan every reached module and build the
TraitDeclRegistry. - container_
recv_ kind - The receiver-kind annotation value, when it is one of the built-in container
categories
Optional,Result,Map, orSet. - derive_
output_ path - Derive the output path for a generated file from its source
.bockpath. - derives_
structural_ eq - True when a
RecordDecl/EnumDeclnode carries the checker’sbock_types::checker::DERIVE_EQ_META_KEYstamp — the type conforms toEquatablestructurally (DQ29) and declares no explicit impl, so the Rust backend addsPartialEqto its#[derive(..)]list. - desugared_
list_ functional_ method - Recognise a desugared
Listfunctional (closure-taking) method call. - desugared_
list_ inplace_ mutator - Recognise a desugared DQ30 in-place
Listmutator call (pop/remove_at/insert/reverse/set). - desugared_
list_ method - Recognise a desugared
Listbuilt-in method call. - desugared_
list_ mutating_ method - Recognise a desugared in-place
Listmutator call (push/append, DQ18). - desugared_
map_ method - Recognise a desugared
Map[K, V]built-in method call. - desugared_
optional_ method - Recognise a desugared
Optional[T]built-in method call. - desugared_
result_ method - Recognise a desugared
Result[T, E]built-in method call. - desugared_
self_ call - Recognise a desugared instance method call.
- desugared_
set_ method - Recognise a desugared
Set[E]built-in method call. - desugared_
string_ method - Recognise a desugared
Stringbuilt-in method call. - disambiguate_
method_ name - Disambiguate a method’s emitted name against the type’s field names.
- enum_
variant_ value_ names - The public enum-variant value names (
Color_Red, …) declared inmodule— the names a TS per-module file must re-export in a trailingexport { … }. - escape_
target_ keyword - Escape
name(an already case-converted value identifier) against the target’s reserved-word set: a name that collides with a keyword gets a trailing_, otherwise it is returned unchanged. - esm_
relative_ specifier - Compute the relative ES-module import specifier from the file that hosts
module
from_pathto the file that hosts moduleto_path, both keyed on their declared dotted module-paths and laid out at the mirrored path (core.option→core/option.<ext>). The entry module is always at the build root asmain.<ext>regardless of its declared path, so callers pass the empty string asfrom_pathfor the entry file. - explicitly_
imported_ names - Names brought into scope by
module’s explicitusedeclarations (the imported leaf names and their aliases) — already emitted as real imports, so the implicit-import pass must skip them. - exportable_
value_ names - The set of JS/TS-emitted, exportable public top-level value declarations
a module declares — the names the per-module path lists in a trailing
export { … }(or, for functions, that the backend exports inline). Covers functions, records, enums (+ eachEnum_Variant), traits, classes, effects, and consts. Type aliases are excluded: they are erased in JS (a comment, no runtime binding) and emitted as anexport typealias inline in TS, so they need no trailing re-export. Runtime-prelude names are excluded (lowered inline). Each entry carries the function flag so the backend camelCases function names to match their inlineexport functionform. - fn_
decl_ name - The method name of a
FnDeclnode, orNonefor a non-FnDecl. - fn_
is_ test - Returns
trueifnodeis a function declaration carrying the@testannotation. Matches the discovery rule used bybock test(bock-cli::test::discover_test_functions): an@test-annotatedFnDecl. - hoist_
value_ cf - impl_
has_ instance_ method - True when an
implblock (anbock_air::NodeKind::ImplBlock) declares at least one instance method — one that bindsself, or an effect operation (which is dispatched on a handler instance despite taking noself; seeis_associated_impl_method). - implicit_
esm_ imports_ for - Compute the implicit cross-module imports for
module: public symbols declared in other reachable modules thatmodulereferences but neither declares locally nor imports explicitly. - implicit_
imports_ for - Compute the implicit cross-module imports for
module: public symbols declared in other reachable modules thatmodulereferences but neither declares locally nor imports explicitly. Returns(module_path, name)pairs. - inherited_
default_ methods - Resolve, for an
impl Trait for Typeblock, the trait default methods that the impl does not override and that must therefore be synthesized onto the target.trait_pathis theImplBlock’strait_path;impl_methodsits own methods. Returns cloned default-methodFnDeclnodes, in trait-declaration order. Empty when the impl has no trait, the trait is unknown, or every default is overridden. Returns owned clones (rather than registry borrows) so a backend can iterate them while mutating its own emission buffer, without holding a borrow of the registry across the&mut selfwrites. - is_
associated_ call - True when
nodeis aCallthe lowerer classified as an associated-function call (Type.method(args)— noselfprepended), via thebock_air::lower::ASSOC_CALL_META_KEYstamp. - is_
associated_ impl_ method - True when an impl/trait
methodshould be emitted as an associated function —assoc_fn_defholds and the method is not an effect operation. - is_
bool_ stringify - True when an expression node is a
Boolvalue that must stringify to the canonical lowercase"true"/"false"(§3.5) — the checker stamped it withbock_types::checker::BOOL_STRINGIFY_META_KEYbecause it appears as an${expr}interpolation part ofBooltype. - is_
default_ method - True when
fn_declis a trait default method — one that carries a body. - is_
int_ arith - True when a
BinaryOp { op: Div | Rem, .. }is integer division / remainder and must be lowered to DQ23’s cross-target integer semantics (§3.6) rather than the target’s native//%. - is_
list_ concat - True when a
BinaryOp { op: Add, left, right }is list concatenation and must be lowered to the target’s concat idiom rather than a native+. - is_
target_ keyword - True when
nameis a reserved word in the given target’s keyword set. - is_
unimplemented_ sealed_ core_ trait - True when
trait_nameis a compiler-provided sealed core trait (bock_types::traits::SEALED_CORE_TRAITS) that is NOT declared as a user trait intrait_decls. Such a bound is the primitive conformance and must be lowered to the target’s built-in (native==/comparison/stringification and the built-in ordered/equality constraint) rather than referenced as a real trait/interface, which does not exist in any target. Shared by the generic-bound renderers and the method-call bridge so the two stay in lockstep. - is_
user_ compare - True when a
BinaryOp { op: Lt | Le | Gt | Ge, .. }is an ordering comparison on a userComparabletype and must be lowered through the type’scompare(self, other)method rather than the target’s native</<=/>/>=. - js_
ts_ generate_ tests - Build the Vitest/Jest test file for the project’s
@testfunctions (S7), shared by the JS and TS backends (identical apart from the file extension and the concrete emit context, both injected by the caller). - locally_
declared_ names - Top-level symbol names declared locally in
module(item names plus each enum variant’s emittedEnum_Variantname) — the names a per-module implicit import must never shadow with a cross-module import. - loop_
needs_ break_ label - Decide whether a loop must be given a target label so that a
break/continueinside a statement-armmatchreaches the loop rather than theswitchthematchlowers to. - lower_
blanket_ into - Run the shared temp-hoist desugar over a fully-lowered, type-checked AIR module, returning the rewritten module. Idempotent on trees with no value-position diverging control flow (returns an equivalent tree).
- match_
has_ statement_ arm - Returns true if any arm of a
matchcarries a statement body (seearm_body_is_statement). When true, backends without a statement-admitting expression form (Go, Python, JS, TS) must emit thematchin statement position rather than as an expression. - match_
needs_ ifchain - Returns true if a
match’s arms require the if/else-if-chain lowering (JS, TS, Go) rather than the value/tagswitchfast-path. - merge_
where_ bounds_ into_ generics - Fold a function/impl
where-clause’s trait bounds onto the matching generic params, returning an owned param list with the constraints attached inline. - module_
declares_ main_ fn - Returns true if the given AIR module declares a top-level function named
main. Used by the build pipeline to decide whether to append an entry-point invocation to the generated output of targets without a native main convention. - module_
main_ fn_ is_ async - Returns true if the given AIR module declares a top-level
async fn main. Used bygenerate_projectto select an async-aware entry invocation. - module_
path_ string - The declared module-path of an AIR module as a dotted string
(e.g.
core.option), orNoneif the module declares nomodule <path>. - module_
tree_ relpath - Map a module’s declared dotted path (
core.option) to its relative output path in a per-module tree, with the target’s file extension (core/option.<ext>). The entry module is laid out separately (alwaysmain.<ext>at a stable location), so callers pass non-entry modules here; a module with no declared path falls back to its source-mirrored path. - node_
is_ statement - Returns true if
nodeis a statement-like AIR node — one that performs control flow or mutation and yields no usable value in expression position. - ordering_
variant - Returns the variant name if
nameis one of the preludeOrderingvariants (Less/Equal/Greater), elseNone. The returned&'static stris the canonical spelling, suitable for emitting into target source. - param_
binds_ self - If
paramis a method parameter that binds the receiverself, returnSome(is_mut)carrying its mutability; otherwiseNone. - primitive_
bridge_ call - Recognise a desugared primitive trait-bridge method call.
- primitive_
conversion_ call - Q-prim-assoc: when
nodeis a primitive associated-conversion call (Float.from(x)/Int.try_from(s)/String.from(c)), returns(target_prim_name, method, arg), wheremethodis"from"or"try_from"andargis the single source-value argument. - primitive_
recv_ kind - The receiver-kind annotation value, parsed into the primitive type name.
- raw_
recv_ kind - The raw
recv_kindannotation tag the checker stamped on a desugared method call node, if any. - reachable_
modules - Restrict
modulesto those reachable from the entry module via realuseedges, returned in a deterministic dependency-before-dependent order (a post-order DFS of theusegraph withusetargets visited in declared module-path order). The result is independent of the input slice’s order, so the emitted per-module tree is byte-stable across the per-process topo-sort shuffling described below. - registered_
variant - Look up the last segment of a
TypePath(the variant name) in the registry. ReturnsNonewhen the path is empty or the name is not a known variant. - trait_
bound_ bridge_ call - Recognise a desugared sealed-core-trait bridge method call on a bounded generic type variable.
- trait_
bound_ recv_ kind - The receiver-kind annotation value, parsed into the bounding trait name.
- trait_
uses_ self_ operand - True if any of
trait_info’s methods referenceSelfin a (non-receiver) parameter type or in the return type. - user_
compare_ variant - Map an ordering
BinOp(</<=/>/>=) onto theOrderingvariant name and whether the comparison is an equality (true) or inequality (false) against it, for lowering a user-Comparablecomparison throughcompare: - user_
eq_ kind - The DQ29 equality lane a
BinaryOp { op: Eq | Ne, .. }node was stamped with by the checker (bock_types::checker::USER_EQ_META_KEY), orNonefor an unstamped (native-equality) comparison. - value_
cf_ diverges - True when a value-position node is a control-flow construct whose branches
diverge — at least one branch yields a value AND at least one branch
exits via
return/break/continue/a diverging intrinsic. These are the nodeshoist_value_cfrewrites; a construct where every branch yields a value already lowers fine via the existing expression paths and is left untouched (so valueif/match/loopcodegen does not regress).
Type Aliases§
- Enum
Variant Registry - Maps an enum-variant name to its
EnumVariantInfo. Variant names are globally unique within a v1 Bock program (no per-enum namespacing at use sites —Red, notColor.Red), so a flat map keyed by the bare variant name resolves every construction and pattern site. - Generic
Decl Registry - Maps a generic type’s declared name to its generic parameters. Built by a
pre-scan of every
RecordDecl/EnumDecl/ClassDeclacross the reached modules. - Trait
Decl Registry - Maps a trait’s declared name to its
TraitDeclInfo. Trait names are globally unique within a Bock program, so a flat map keyed by the bare name resolves everyimpl Trait for Typeblock to its trait.