Implement DEC-0084 with factory-only Sprite/Animator structs, complete result lowering, validated animation sidecars, generated PBS factories and JavaFX/MCP authoring through shared services. Qualify native dev/release with ordinary and optimized producers, zero-allocation playback, private-cycle reclamation, canonical Composer pixels, installed JARs and JavaFX lifecycle. Preserve the runtime checkout and existing host ABI.
15 KiB
PBS Lowering IRBackend Specification
Status: Draft v1 (PBS Frontend Scope + Common Handoff Emission)
Applies to: first lowering boundary from bound PBS frontend model into the common IRBackend/IRBackendFile handoff
1. Purpose
This document defines the normative frontend lowering contract from PBS source semantics to the common IRBackend handoff.
Its purpose is to keep PBS lowering deterministic while preserving the common frontend-to-backend contract owned by compiler-general backend specs.
2. Scope
This document defines:
- required preconditions before lowering starts,
- AST invariants that lowering may assume as hard contract,
- semantic obligations preserved in
IRBackend, - deterministic rejection behavior for unsupported frontend-lowering forms,
- diagnostics attribution obligations for lowering failures in frontend scope,
- PBS obligations for emitting the common executable
IRBackendhandoff, - and backend-owned symbolic lowering obligations for asset-facing references.
This document does not define:
- VM lowering (
IRVM), - bytecode/PBX mapping,
- runtime execution behavior,
- verifier/loader internals,
- or common backend ownership of the
IRBackend -> IRVMcontract.
Those concerns belong to shared acceptance specs under docs/specs/compiler.
3. Authority and Precedence
Normative precedence:
3. Core Syntax Specification.md4. Static Semantics Specification.md11. AST Specification.md12. Diagnostics Specification.md- This document
If a lowering rule here conflicts with higher-precedence syntax/semantics rules, the higher-precedence rule wins.
4. Normative Inputs
This document depends on:
3. Core Syntax Specification.md4. Static Semantics Specification.md11. AST Specification.md12. Diagnostics Specification.mddocs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md
5. Lowering Preconditions
Frontend lowering into IRBackend may start only when:
- source has been tokenized and parsed,
- required syntax diagnostics have been emitted,
- AST output satisfies
11required invariants for this source unit, including:- one root per file,
- deterministic child ordering,
- mandatory node attribution (
file/start/end) on nodes consumed by lowering, - mandatory declaration metadata on declaration nodes required by the active source slice,
- and structural coherence after any parser recovery.
- linking/name-resolution outcomes required for the current lowering slice are available,
- and no unresolved semantic ambiguity is deferred to lowering.
Lowering must not invent unresolved semantic answers that belong to syntax/static/linking phases.
When the active source slice depends on a backend-owned symbolic surface such as PBS asset references:
- the frontend may assume access to the admitted frontend surface context selected for the build;
- the frontend must not query domain services directly to discover operational assets;
- and lowering must preserve enough identity for the backend to complete final operational resolution.
6. PBS IRBackend Emission Obligations
For each admitted PBS source unit and callable in the current lowering slice, PBS lowering must emit IRBackend that preserves at minimum:
- callable identity (name/category as applicable),
- callable arity,
- declared return surface information,
- source attribution anchor (
file + span) for diagnostics and traceability, - source-observable parse intent for statement/expression structure (including precedence/associativity outcome already fixed by AST shape).
- deterministic
requiredCapabilitiesderived from admitted host-binding metadata for packer/runtime-manifest assistance. - a typed
IRLifecycleDeclarationfor executable programs, with file-init fragment, optional project-init, and required frame-root references, - explicit user globals and frontend-lowered file-init fragments required by later common lifecycle assembly,
- backend-owned symbolic identities that must survive to later executable lowering, including symbolic asset references when admitted by the source slice.
PBS lowering MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard. Those artifacts are produced exclusively by common lifecycle assembly.
Lowering must not collapse source categories in a way that erases required declaration/callable identity needed by downstream diagnostics or conformance assertions.
The normative contract is obligation-based, not tied to one mandatory in-memory class graph.
IRBackend itself is the common frontend-to-backend executable handoff. This PBS spec owns only the PBS-specific admission and translation path into that handoff. Common backend rules for consuming IRBackend are owned by docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md.
7. Deterministic Rejection Policy
If a source form is outside current frontend-lowering support:
- rejection must be deterministic,
- diagnostics must expose stable
code,severity,phase,message template id, and primary attribution, - and unsupported forms must not silently degrade into different valid lowered behavior.
Lowering must not convert a required syntax/static rejection into accepted lowered behavior.
For multi-module builds, lowering admission must apply dependency-scoped fail-fast:
- a module rejected in syntax, static semantics, linking, host-admission, or load-facing gates must not be emitted;
- any module that imports a rejected module (directly or transitively) must also be excluded from
IRBackendemission; - modules independent from the rejected dependency subgraph may continue to lower and emit in the same build.
8. Conformance Boundary
PBS emission into IRBackend is the first PBS lowering boundary (frontend responsibility).
Conformance-valid claims at this boundary require Gate U evidence from docs/specs/compiler/13. Conformance Test Specification.md.
For this frontier, Gate U evidence is expected to cover at minimum:
- lexer behavior for covered inputs,
- parser behavior and AST shape invariants required by
11, - lowering outcomes at
IRBackendboundary, - and deterministic diagnostics identity/attribution for rejection cases.
Conformance at this boundary may be claimed only when the full claimed PBS source surface is implemented at IRBackend level.
9. Explicit Deferrals
The following are intentionally out of scope for this document:
IRBackend -> IRVMlowering,- artifact encoding and binary layout,
- runtime lifecycle behavior,
- verifier and loader checks.
10. Non-Goals
- Freezing one optimizer strategy.
- Freezing one compiler architecture.
- Repeating runtime or bytecode authority.
11. Exit Criteria
This document is healthy when:
- lowering preconditions are explicit,
- preserved
IRBackendobligations are explicit, - deterministic rejection policy is explicit and test-backed,
- and scope boundaries with general/backend acceptance specs are explicit.
12. PBS Executable Handoff Emission Obligations (v1)
For executable backends, PBS lowering must emit IRBackend satisfying the additional handoff obligations below before common backend lowering starts.
12.1 Callable obligations
For each executable callable admitted into IRBackend, the frontend must preserve:
- stable callable identity in the current build graph,
- observable callable signature (input arity and return shape),
- callable category needed by downstream lowering,
- source attribution anchor (
fileId,start,end), - and executable body representation that is backend-lowerable.
12.2 Callsite classification obligations
Each executable callsite in IRBackend must be classified into exactly one category:
CALL_FUNC,CALL_HOST,CALL_INTRINSIC.
PBS lowering must not leave this category for backend inference by textual heuristics.
12.3 Host-backed metadata obligations
Each host-backed callsite admitted at this boundary must preserve canonical host identity:
module,name,version.
When available at this boundary, declared host ABI shape (arg_slots, ret_slots) must also be preserved for downstream validation.
When a host-backed callsite also depends on backend-owned symbolic asset lowering:
- the frontend boundary MUST preserve which callsite argument is asset-facing;
- for PBS v1 this asset-facing designation is carried by reserved host metadata
[AssetLowering(param = N)]; - the preserved symbolic operand MUST remain attributable to a backend-provided
Addressableidentity; - common backend stages MUST be able to rewrite that symbolic operand into runtime-facing
asset_idbefore the final low-level host path is emitted.
When an expression statement leaves a materialized runtime value on the stack:
- PBS lowering into
IRBackendMUST emit explicit discard behavior rather than relying on implicit backend stack cleanup; - for single-slot materialized values this discard is represented by
POP; - and the discard path MUST preserve stack-accounting validity for subsequent backend lowering stages.
12.4 VM-owned metadata obligations
VM-owned intrinsic callsites admitted at this boundary must preserve canonical intrinsic identity:
canonicalName,canonicalVersion.
VM-owned builtin projections/constants/intrinsics must not be reclassified as host bindings.
12.5 Deterministic capability obligations
requiredCapabilities derived at this boundary must be deterministic for the same admitted input graph.
12.6 Boundary with backend lowering specs
This addendum defines obligations preserved at the IRBackend boundary only.
It does not replace:
docs/specs/compiler/20. IRBackend to IRVM Lowering Specification.md,docs/specs/compiler/21. IRVM Optimization Pipeline Specification.md,- or
docs/specs/compiler/15. Bytecode and PBX Mapping Specification.md.
12.7 Executable Lifecycle Declaration Obligation
For executable PBS frontends, PBS lowering MUST emit a typed IRLifecycleDeclaration rather than assembling the published lifecycle.
At frontend IRBackend emission time:
- PBS MUST retain marker admission for
[Init],[Frame],[BeforePause],[BeforeResume], andInitAllowed, - PBS MUST emit typed references for:
- file-init fragments that include global materialization and non-project
[Init], - the optional project-init callable, which is the
[Init]colocated with[Frame], - and the required frame-root callable marked with
[Frame],
- file-init fragments that include global materialization and non-project
- the colocated project init MUST be excluded from file-init fragments,
- module order in the declaration MUST propagate the explicit dependency order already derived from resolved project/module data, without sorting by
FileId, textual module name, or synthetic callable name, - PBS MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard,
- and common lifecycle assembly remains the owner of derived artifacts, including the published wrapper that becomes the physical entrypoint and owns the final frame return.
Existing values and input runtime alignment
The PBS input and value alignment contract governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
Typed arrays and optional execution extension
The Array owner chapter defines the complete type, optional-flow and storage contract. This chapter owns source-to-common-IR projection; the owner chapter defines Array storage, optional carriers and complete-group requirements.
Array spelling and construction are owned by Core Syntax and the Array chapter; AST, diagnostics and lowering MUST consume that same syntax.
Parameterized contracts
The frontend substitutes each closed application and emits a concrete nominal Trait descriptor shared by equivalent uses. Distinct logical applications remain distinct despite shared physical carriers. Concrete implementation functions take the receiver first. CALL_TRAIT evaluates and roots the receiver before arguments, evaluates arguments left to right, then places the complete receiver/ImplementationId view after the argument groups as required by the runtime ABI. Preserve exact signatures, absence, ImplementationId zero, ownership, GC and quotas; generic calls do not add a Dynamic ABI or adaptation wrapper.
Concrete generic structs and free functions
Instantiate structs, free functions and owner-bound implementations within PBS before publishing executable descriptors. Registry receives concrete fields, signatures, bodies, capture groups and targets. Specialized free-function references use existing empty-environment Closure values; Fn remains structural. Preserve receiver identity, implementation zero, singletons, rooting, GC, ownership, evaluation/fault order and quotas. No generic Dynamic/boxing ABI, opcode, descriptor category or runtime instantiation engine is introduced.
See Concrete generic structs and free functions.
Lowering optional runtime hook roles
Map BEFORE_PAUSE/BEFORE_RESUME to IRRegistry.Role.BEFORE_PAUSE (1) /
BEFORE_RESUME (2) in typed FunctionMetadata. Preserve the declaration/callable
identity, empty signature and capture list; no hidden receiver or parameter is
introduced. INIT/FRAME and ordinary functions retain role None (0). Function
names/exports/manifests are not role binding mechanisms. No MemcardBoot role is
inferred or emitted by these markers.
Each role target and its dependencies are externally entered retention roots, even without source callers. Merge, lifecycle assembly, linking and optimization MUST preserve bodies and metadata. Common code consumes neutral typed roles, never PBS ASTs/names. The ordinary assembled entry remains physical FunctionId zero; hook targets are nonzero after deterministic linking. Common Registry/PBX validation and production runtime admission remain mandatory defenses.
Memcard integration
The Memcard Bootstrap and SDK contract defines the additional [MemcardBoot] marker, exact signature, neutral once-only bootstrap, project identity/slot validation and complete installed mem ABI. Its requirements apply in addition to this chapter; pause/resume remain independent.
Executable result return groups
Emit an existing typed return group: Int32 status 0 for success or canonical nominal error case index 1..N, followed by the complete plain payload group. Unit result has only status. Error payloads use admitted typed defaults, including nullable references, without constructing payload objects. Preserve typed reference/builtin/Fn/trait groups across signatures, Registry, direct/contract calls, branches and discard. Propagation fills the enclosing inactive payload and returns immediately; handle recovers locally or remaps outward. The common backend consumes neutral typed IR with no PBS branches.
See Core Sprite and Animation for the complete API, ranges, state table and conformance obligations.