Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code Generation Vocabulary

This appendix defines the vocabulary used throughout sigil-stitch. The architecture overview describes how these concepts flow through the implementation, while Declaration Specs and Language Lowering records their ownership boundaries. Versioned exceptions are catalogued in 0.6.8 Legacy Compatibility and Migration.

Declaration Intent

Declaration spec

A structured, language-independent request for a declaration such as a type, function, field, property, or variant. It records semantic intent, not target-language token placement or spelling.

Capability

A semantic feature that a target language may support, require, or reject for a particular declaration kind and context. A capability describes what can be represented; it is not a switch for target grammar.

Language adapter

The target-specific boundary that decides whether declaration intent is representable and converts accepted intent into target-language structure. It owns detailed declaration grammar such as keyword order, punctuation, and metadata placement.

Target grammar

The language-specific keyword order, punctuation, precedence, escaping, and metadata placement used to express accepted declaration intent. Target grammar belongs to the language adapter; it is not a general format abstraction or a capability.

Function intent

A complete function declaration classified by its role and context before target-language validation. It remains semantic and does not contain a partially rendered signature.

Type intent

One complete type declaration before target-language validation. TypeIntent exposes its kind, semantic modifiers, documentation, annotations, type parameters and constraints, type relationships, primary-constructor parameters, variants, and member families without choosing their source order or spelling.

Primary-constructor storage metadata

Metadata attached to storage promoted by a primary-constructor parameter. The parameter must request immutable or mutable property promotion; the metadata is not a general parameter annotation and does not select a target placement. ParameterSpec::annotate_storage() keeps an AnnotationSpec structured so an adapter can preserve imports, while storage_annotation() is an explicit target-specific escape hatch. PrimaryConstructorStorageAttributes is the capability for this semantic fact. Each language that supports it owns the attachment spelling and placement; the built-in Kotlin adapter emits @field: before val or var.

Primary-constructor storage visibility

The accessibility of storage promoted by a primary-constructor parameter. Like storage metadata, the parameter must request immutable or mutable property promotion; the visibility is not the visibility of the type declaration and not a separately declared field. ParameterSpecBuilder::storage_visibility() sets it, and PrimaryConstructorStorageVisibility is the capability for this semantic fact. It governs the promoted property’s accessor — its getter, setter, and destructuring component — not the secrecy of the value: a target may still include the value in generated value functions. Kotlin and Scala own the modifier spelling and placement; they emit it before the val or var keyword, after any storage annotations.

Closed sum

A type declaration whose complete ordered set of named cases is part of its semantic intent. Each case is unit-shaped or carries positional or named record data. A closed sum may contain no cases: the empty sum is uninhabited. The declaration does not prescribe whether a target uses an enum, algebraic data type, sealed root with generated case declarations, nested declarations, or sibling declarations.

The zero-case form declares a named uninhabited type. A particular target may have a Never or bottom type with the same absence of values, but that is a type-expression or subtype concept rather than this caller-named declaration. The shared model does not equate them; a target may reuse such a type only if it preserves the declaration’s name and every valid use position.

Closed-sum intent is not a sealed modifier or an enum-formatting option. A case carrying a TypeName owns that payload relationship; it does not assert that an already-declared type is a nominal subtype of the sum root.

Validated type

A crate-constructed view whose type-level intent and every child declaration have passed intrinsic, capability, and target-local validation against the same adapter. ValidatedType exposes child declarations only through their validated wrappers. The adapter lowers the complete declaration and chooses whether it produces one block or several; every returned block must be non-empty.

Type name

A semantic type reference. It remains structured until one selected language adapter lowers the complete value before import collection. A TypeName may contain other type names, but it never contains a language-neutral choice of punctuation, precedence, or layout. Primitive and Raw are explicit target-aware leaves rather than a general type grammar.

Structured source block

A CodeBlock is the shared Rust container for source nodes associated with one selected target. Its Rust type is language-agnostic so declaration lowerers, rewrite, import collection, and rendering can compose it, but its literal content and structure are not a portable cross-language program.

Layout capsule

The parser lowers its choices through a closed macro-owned LayoutPlan (Inline or Delimited) rather than passing independent layout booleans through codegen. The delimited plan is converted once into the hidden grammar-neutral LayoutOptions carrier before it becomes a LayoutBlock; the shared renderer never sees parser-owned Python roles or separator expressions. The older hidden edge constructor remains only as a compatibility wrapper for already-expanded macros.

CodeNode::Layout(LayoutBlock) is the shared structured carrier for a target-owned fit/break recipe. A capsule stores flat and broken delimiter alternatives, edge, item, and clause break policy, conditional trailing-comma behavior, one consistent or independent group policy, and explicit Indent/Dedent nodes around broken continuation items. The scopes are interpreted only while the Layout group is active, so flat output remains unindented and nested groups do not inherit a leaked continuation depth. Python lowers its private group/item policy into this carrier and validates structured output against the pinned Ruff fixed-point oracle; other targets continue using their existing Nested, Sequence, and SoftBreak semantics. TrailingCommaPolicy records whether a comma is never emitted, emitted only on a broken path, or requires a broken path. Target-local comment width behavior and parser-known separator intent are carried as small policy facts; the shared renderer does not infer grammar from extensions or runtime strings. It is not a public Python AST, and raw $L content is never re-tokenized into a capsule. Raw/provider-owned source is outside sigil-stitch’s Ruff repair responsibility.

Generic binding and kind expression

A declaration-owned name with a single, pack, or lifetime domain, optional kind intent, and supplied bounds. GenericParamSpec records the binding; GenericParamView borrows the owner’s complete ordered sequence. Uses refer to names without a shared scope resolver. The target compiler owns inference and instantiation.

KindExpr records Type, a named kind, or a constructor’s parameter and result kinds. Declaration lowering owns representation or rejection. Named kinds are not inferred; legacy raw binder suffixes are not modern kind expressions.

Type application and expansion pattern

Application of a supplied type-level base to ordered arguments. An expansion retains its complete pattern, including every referenced pack. The library does not evaluate the pattern, solve its arity, or reinterpret a tuple as an argument list.

Callable parameter sequence

Ordered scalar slots, repeated-element segments, and complete expansion patterns. Optional presence belongs to a scalar slot and differs from an optional value. Labels and ordering restrictions belong to the selected language, not to a shared rest-parameter grammar.

Function return sequence

Ordered typed return slots shared by declaration and callable intent. An explicitly empty sequence means no payload; a tuple-valued return is one slot. A declaration may leave return information unspecified instead. Languages own the native representation and supported slot counts; the sequence does not define shared return grammar or infer a type from the body.

String literal type

A type inhabited by exactly one decoded string value. TypeName::StringLiteral stores the value without target quotes or escapes. The language adapter either lowers it exactly or rejects it; several string literal types compose through TypeName::Union, not a string-enum or literal-set abstraction.

Integer literal type

A type inhabited by exactly one mathematical integer, without a machine-word width. Value identity ignores source spelling and integer zero has one identity; the target preserves the value exactly or rejects it.

This definition distinguishes a singleton value from a fixed-width integer carrier, a BigInt literal, a numeric source token, or a constant expression. Different primitive domains do not become interchangeable merely because their values have the same mathematical magnitude. A semantic value domain without a word-size bound does not promise unlimited resources or support on every target.

TypeName::IntegerLiteral stores canonical decimal integer text. Intrinsic validation checks that representation before language-owned lowering; TypeScript preserves it as a number singleton or rejects it, Python lowers it through typing.Literal, and Scala uses native Int/Long literal types within their exact range. A string literal type remains a separate semantic form, and target-specific syntax outside these forms can use the Raw escape hatch.

Floating value

A machine floating-point value whose identity includes its scalar format and every bit of its encoding. Target construction preserves both or rejects the request. Construction is deferred until the target language is selected. It is not a singleton type, decimal source spelling, numeric conversion, or a block of values with a shared scale.

FloatValue stores binary32 or binary64 bits as integers. Signed zeros and distinct NaN encodings have distinct identities. %L and macro $L retain the value in structured source; preparation asks the file or renderer’s selected language for a structured expression, not a byte-array fallback.

Field sequence

The ordered fields owned by one type declaration or one record payload, considered together in their semantic context. A language adapter handles the complete sequence so it can validate collisions and own sequence-level grammar.

Field context

The semantic role in which a field sequence appears: direct emission, ordinary type members, an ordinary variant record payload, or a closed-sum case record payload. Keeping the payload contexts distinct prevents support for generated closed-sum cases from widening ordinary enum behavior. A field context identifies representability; it does not prescribe placement, punctuation, or separators. The Direct(DeclarationContext) payload retains only the pre-0.6.8 direct-emission placement input. It is a narrow compatibility exception, not a reusable placement or target-grammar model.

Property intent

One computed property with a value type, read and/or write behavior, semantic modifiers, documentation, and attributes before target-language validation. It does not choose accessor syntax or a field-style representation.

Property context

The semantic role in which one computed property appears: direct emission or a member of an owning TypeKind. The Direct(DeclarationContext) payload exists only to retain the pre-0.6.8 public emission facade; it is not a general accessor-placement model.

Type members intent

A validation-only view of one owning type’s semantic fields, computed properties, and explicit methods. TypeMembersIntent exists for relationships that cannot be checked within one member family, such as target-derived name collisions. It contains no target grammar, has no validated wrapper, and does not participate in lowering. It is not a sequence-level replacement for PropertyIntent. Each adapter defines its own emitted namespaces: a field/property pair collides in TypeScript, Kotlin, Swift, and Scala only when both declarations occupy the same target-local namespace, while PHP properties instead derive case-insensitive accessor-method names.

Read accessor and write accessor

Semantic read and write behavior supplied by a property’s getter and setter bodies. A language adapter may express that behavior as accessor declarations, a computed-property body, or target-local methods. The capability names do not prescribe getter keywords, setter placement, or surrounding grammar.

Optional presence

A field semantic in which the containing value may omit the field entirely. FieldSpec::is_optional() requests this meaning. It is distinct from an optional value.

Optional value

A value semantic in which a present field can carry the target language’s absence or null representation. TypeName::Optional expresses this meaning; it does not make the field itself omissible.

Variant sequence

The ordered variants owned by one type declaration, together with the semantic presence of non-variant members. A variant lowerer handles the sequence as a whole; the owning type lowerer chooses where that sequence appears relative to other member families. Non-variant members include fields, properties, methods, embedded types, and opaque members.

For a closed sum, an empty sequence is meaningful rather than missing input: it declares an empty sum. Ordinary value-enum validation remains independent and may continue to require at least one member for a particular target.

Variant Data

Discriminant

An explicit value that identifies an enum member in a representation where members map to values. It is distinct from an expression passed to an enum constructor.

Constructor arguments

Expressions passed when an enum entry constructs an instance of its declaring enum type. They are values evaluated at the declaration site, not types carried by a sum-type case.

Positional payload

Types carried in order by a sum-type constructor or enum case. The payload has positions but no field names.

Record payload

Named, typed fields carried by a sum-type constructor or enum case. These are case-local payload fields, not ordinary members of the enclosing type.

Transformation Boundaries

Source-tree rewrite

One language-local structural correction is applied exactly once to each source CodeBlock after declaration lowering and before floating-value and type-name lowering. It is for target source fixups that require a tree-level view, such as joining a Go IIFE close to its invocation. It does not own declaration grammar, floating-value construction, type grammar, validation, or final layout. Raw content, raw import metadata, and blocks returned by floating-value or type-name lowering are not source-rewrite inputs.

Type-name lowering

The fallible conversion of one complete TypeName into a non-empty CodeBlock before import collection. The selected language adapter owns representability, precedence, punctuation, string escaping, and any target-derived type imports. A successful lowering block may retain only terminal import-aware type references; unresolved compound type names fail closed.

Import conflict set

The complete peer set of semantic imports that request the same local binding within one file. Exact explicit bindings are hard constraints; preferred aliases and natural names are soft requests. The resolver assigns every peer atomically and does not receive an incoming import, current owner, winner/loser pair, or mutable claim table.

Lowering

The conversion of validated declaration intent into structured output that follows one target language’s grammar. Lowering decides source structure but does not perform final layout.

Rendering

The final interpretation of structured output into source text, including layout, indentation, import aliases, and width-aware line breaking. Rendering does not decide whether a declaration is representable.

Escape hatch

An explicitly target-specific payload embedded in otherwise structured intent when the shared declaration vocabulary cannot express a source fragment. An escape hatch deliberately gives up portability for that fragment.