feat(compiler): implement typed registry and production PBX conformance (AGD76)

This commit is contained in:
2026-10-14 21:04:04 +01:00
parent a9ede541af
commit bd5694dbdf
54 changed files with 2298 additions and 357 deletions
@@ -0,0 +1,145 @@
---
id: LSN-0079
ticket: compiler-pbx-registry-conformance
title: Typed common IR through production PBX admission
created: 2026-10-14
tags: [runtime-integration]
---
## Original problem and ownership
Owner: compiler/general; interfaces: compiler/pbs and studio.
The old producer carried parameter/result slot counts without complete semantic
types and emitted a retired PBX function layout. A writer-only repair could not
recover signatures, distinguish nominal identities or describe closures and
trait implementations. The fix had to cross the entire common producer chain.
This lesson consolidates AGD-0076, accepted DEC-0063 and completed PLN-0142
(DSC-0074). Those workflow artifacts were removed by housekeeping after their
normative content and evidence were propagated. The active integration umbrella
is [AGD75](../../workflow/agendas/AGD-0075-studio-runtime-readiness.md).
## Consolidated decisions
Use stable declaration references before assigning deterministic dense image
IDs. Preserve Struct/Trait nominal identity; canonicalize Builtin imports,
Array elements and Fn signatures. Names are descriptive, not nominal keys.
Parameters, results, captures, implementations and lifecycle roles are explicit
common values, preserved through IRVM, optimization and emission.
The common IR remains serializable by design, but a concrete codec was
explicitly deferred. Complete representation does not require selecting a
transport format. References avoid recursive Java object graphs and the public
contract audit rejects mutable or frontend-specific shapes.
PBS is one frontend. Optional and Result already belong to PBS's normative
language contract and have parser/semantic implementations. Defects in their
executable lowering do not justify new backend categories or rejection rules.
Their implementation and carrier choices remain frontend-owned. The user
explicitly scoped consumer migration to subsequent tickets and a single AGD75
integrated delivery. No PBS semantics were added to this backend change.
## Final implementation
- IRRegistry and FunctionMetadata represent all five type categories, ordered
signatures/captures, roles and implementations. Aggregation remaps callable
references while preserving stable type identity.
- LinkedRegistry canonicalizes imports/structural declarations deterministically
with an iterative dependency traversal. Nominal anchors permit recursion;
purely structural cycles reject.
- Lowering derives widths from semantic signatures, links typed operands and
remaps implementation targets. IRVM coherence and optimization preserve the
Registry and function metadata.
- The PBX writer emits the 32-byte header and all eight mandatory sections,
optional debug, strict UTF-8, exact function records and explicit empty capture
environments. Width caches are not serialized. Constant deduplication now
relocates PUSH_CONST indices rather than silently changing their meanings.
- Local verification decodes all function ranges, validates references and
operand categories, forbids retired/raw opcodes and analyzes reachable stack
and type facts to convergence. Conflicts become Unknown; exact semantic groups
retain provenance when available. Unknown remains subject to runtime checks.
- Production loading remains authoritative for native identity/capability/ABI,
runtime budgets and executable admission.
- Studio previously discarded error.details when a headless response rejected
boot. AutomationFailure now preserves the entire runtime error envelope,
including initialization, binding and resource details, through MCP output.
## Examples and pitfalls
A `vec2 -> vec2` function has logical arity one/one and derived slot widths two/two.
The function record writes the two TypeId lists, not the numbers two/two. A test
compares that record with independent fixed bytes from the runtime contract.
A capturing body is not a direct-call target. MAKE_CLOSURE names the body and
expected Fn type, consumes its explicit capture groups and produces a callable.
CALL_CLOSURE consumes that callable after the explicit arguments. The synthetic
frontend test proves this path without PBS source, SDK or language ASTs.
Jumps contain absolute offsets from the current function start. They are not
relative to the next PC. A taken jump to function end is a return boundary;
ordinary fallthrough is invalid. These details were checked against the actual
runtime verifier, not inferred from older emitter behavior.
Do not derive type identity from slot width, spelling or display names. Do not
claim a self-round-trip proves external conformance. Do not treat parser tests
as execution evidence or a load-only argument-taking entry as a boot test.
Initialization diagnostics have null outer executed PC. A verifier PC remains
nested in initError.load.pc; file offsets remain offsets. Preserve the original
JSON structure rather than flattening it into human-readable messages.
## Qualification evidence
Runtime: `f7d7c167531bb662a1af9d73fc326bb476bf8aa7`.
Platform: macOS 27.0.1 arm64. Rust harness uses the runtime Cargo.lock, default
load limits and NONE capabilities except the positive native case (SYSTEM).
Resource-negative cases explicitly lower Types, TemporaryBytes or Work.
Runtime checkout remained unchanged.
| Gate | Result |
| --- | --- |
| Build-pipeline suite | 178 tests: 163 passed, 15 skipped, no failures |
| Frontend-api suite | 28 passed |
| PBS suite | 245 passed; not a claim of complete executable migration |
| Headless process suite | 9 passed, including six observed runtime fault payloads |
| Architecture suite | 17 passed |
| Independent binary oracle | Exact 194-byte minimal image and fixed vec2 function bytes |
| Production loader positives | 12 admitted images, including native binding |
| Genuine execution | 11 programs: direct/common path, closures/captures, trait, Array/Dynamic, joins, roles, intrinsic and native; vec2 signature is load-only |
| Production negative corpus | 32 rejected malformed/binding/code/resource fixtures |
| Workflow and patch integrity | discussion validate and git diff --check passed |
The 15 skipped tests are older conditional integration adapters. The dedicated
production harness above ran explicitly; their skip state is not substituted
for runtime evidence. The intrinsic/native catalogue goldens are serialization
fixtures and do not claim current PBS catalogue compatibility.
Reproduce with the commands in
[the harness README](../../../tools/pbx-conformance/README.md). The harness
creates its Cargo build outside the runtime checkout and saves generated PBX and
observed JSON under the build-pipeline build directory.
## Remaining integration work
The runtime LoadReason enum has four values missing from the published headless
schema: LifecycleRole, LifecycleSignature, DuplicateLifecycleRole and
NonFiniteValue. The corpus observes the first and last. Both payloads fail the
original schema solely because of the missing enum value. The harness explicitly
reports this upstream gap, validates the original payload with that single enum
addition, and leaves the payload unchanged. It does not claim those two cases
conform to the unmodified schema. Runtime must correct the schema under AGD75.
PBS typed producer migration, Optional/Result executable lowering, catalogue
alignment, installed runtime delivery, hook selection, memcard gating and
persistence remain with their consumer tickets. The common schema and synthetic
producer work without those features. There is no legacy PBX fallback and no
slot-to-type inference to conceal an incomplete handoff.
## References
- [Typed common Registry/PBX specification](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md)
- [Backend conformance matrix](../../../docs/specs/compiler/22.%20Backend%20Spec-to-Test%20Conformance%20Matrix.md)
- [Runtime qualification harness](../../../tools/pbx-conformance/README.md)
- Runtime sources: registry_v0.rs, program_image.rs, registry_verifier, and
devtools/headless-protocol/response.schema.json at the revision above.