Skip to content

spike(codegen): compile complete callable contracts before emission #335

Closed

Description

@bbopen

Compile each callable once, preserving its arguments, overloads, logical result type, numeric constraints, wire representation, decoded JavaScript representation, required capabilities, and diagnostics.

Current generation makes these decisions in separate places: generate, IR conversion, and return-schema emission.

Consume the frozen internal value-contract interface owned by #343. Keep Python callable resolution and emission owned by this issue. TypeScript declarations, call wrappers, and validators must consume the same resolved contract.

Prototype an integer, a float16 ndarray reused by Torch, and an overloaded function returning a nested record. Limit this compiler investigation to two engineering days, one design iteration, and an independent review. Coordinate integration with the separate codec prototype.

Acceptance criteria:

  • A pure validation step accepts unknown input and validates the complete IR 0.4 structure with located errors.
  • Internal compileContract consumes validated IR plus explicit conversion and capability descriptions, then returns files and structured diagnostics.
  • Compilation performs no filesystem, subprocess, interpreter, cache, or runtime-registry access.
  • generate owns interpreter discovery, caching, and writes. Preserve offline contracts and check mode from PR9: [breaking] pinned IR contract artifact + TS/Python IR-version check #269.
  • Arguments, Python binding, overload relationships, logical value constraints, representations, and capability requirements survive resolution.
  • Precise result types require a supported conversion and validation path. A dataclass annotation alone cannot justify Promise.
  • Distinguish supported, known unsupported, and unresolved behavior. Unresolved annotations retain explicit unknown behavior.
  • Known unsupported conversions and execution requirements produce diagnostics, with clear strict-mode behavior.
  • Declarations, wrappers, and validators consume the same resolved contract.
  • Separate input and decoded output representations, including numeric policy.
  • The selected overload fixture preserves its input-to-return relationship in compile-only tests.
  • Runtime tests reject invalid returns through the generated wrapper.
  • Scientific marker provenance, dtype handling, and fast paths remain intact.
  • Diagnostics remain local; frozen inputs yield stable outputs with reviewed differences.
  • Preserve the documented tywrap facade and existing transports.
  • Independent review records proceed, revise, or stop, with compatibility and implementation evidence.

Use #344 for independent end-to-end proof and #345 for coordination. #336 remains the broader overload implementation issue. #338 still owns coroutine execution; recording capabilities does not implement it.

Keep IR 0.5, public compiler APIs, and broad parser/emitter replacement deferred until evidence justifies them.

Activity

  1. added this to the Backlog milestone on Sep 11, 2026
  2. self-assigned this
    on Sep 11, 2026
  3. modified the milestones: Backlog, Next on Sep 11, 2026
  4. changed the title [-]spike(codegen): resolve callable contracts in a pure compiler stage[/-] [+]spike(codegen): compile complete callable contracts before emission[/+] on Sep 11, 2026
  5. bbopen commented on Sep 20, 2026

    @bbopen
    OwnerAuthor

    The generator now consumes a validated IR and a pure callable compiler. One compiled description determines declarations, calls, binding, overload selection, conversions, and return validation. Discovery, caching, and output writes remain outside that compiler. Unsupported conversions and unresolved annotations have distinct diagnostics; precise return types require matching conversion and validation.

    Coverage includes nested records, aliases, generics, selected wrong returns, scientific provenance, malformed IR, recursion bounds, stable output, and existing runtime compatibility. This is an internal architecture change, not a new public compiler API.

    Evidence: src/core/ir-contract.ts, src/core/callable-compiler.ts, src/core/generator.ts, test/callable-compiler.test.ts, and docs/maintainers/architecture-decision-0.11.md.

    Verified release evidence:

    The architecture decision records the accepted scope and prototype limits.

    Closing with the implemented and verified 0.11 release outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions