8000 [c_api] Expose interpreter and JIT proc runtimes by cdleary · Pull Request #5531 · google/xls · GitHub
[go: up one dir, main page]

Skip to content

[c_api] Expose interpreter and JIT proc runtimes - #5531

Open
cdleary wants to merge 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-23-proc-runtime-c-api
Open

cdleary wants to merge 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-23-proc-runtime-c-api

Conversation

@cdleary
@cdleary cdleary commented Nov 23, 2026 •
Copy link
Copy Markdown
Collaborator

Expose interpreter and JIT proc runtimes through the C API. xls_proc_runtime_create creates an interpreter. xls_proc_runtime_create_jit compiles the procs at creation so subsequent ticks reuse native code. Both take an existing package and share the same operations for ticking, channel I/O, taking trace messages, and freeing the runtime.

Proc-scoped channel names

XLS permits a proc to declare an input and an output with the same name. During testing we found that both native runtimes can select the wrong queue when those interfaces bind to distinct queues. For example, a proc sent 7 on its output and then waited for input. With no input supplied, it consumed its own output. The receive should have blocked and left 7 available to the caller.

Both C constructors check for this ambiguity before creating the interpreter or compiling the JIT. If a reachable proc instance binds same-name interfaces to distinct queues, creation returns false, clears the runtime output, and identifies the proc instance and channel in error_out. A child whose two interfaces bind to one loopback queue is supported. The native fix for both runtimes is proposed in #5569. Once it lands, the C API can select boundary queues by direction and remove this guard.

C API behavior

The package must outlive the runtime. Free the runtime before rewriting IR it uses, and use a separate package for xls_schedule_and_codegen_package while the runtime is live. Proc-scoped channel I/O uses the top selected at creation, even if the caller later selects another package top. Writes select inputs and borrow the caller’s value. Try-reads select outputs and return true with an owned value or null for an empty queue. Package-scoped channels retain their name lookup. Callers free returned values with xls_value_free and error strings with xls_c_str_free.

xls_proc_runtime_take_trace_messages transfers traces from the latest tick, including traces emitted before an assertion failure. A second take returns an empty list. The next tick discards any untaken traces. Callers release the array with xls_trace_messages_free.

Tests

The optimized //xls/... sweep passed all 2,251 selected targets, including constructor rejection and shared-loopback execution on both backends. The sweep excluded contrib, dev_tools, visualization, and five individual targets.

@cdleary cdleary changed the title Expose proc runtime execution and channel I/O in the C API [c_api] Expose proc runtime execution and channel I/O in the C API Nov 23, 2026
@cdleary
cdleary force-pushed the cdleary/2026-11-23-proc-runtime-c-api branch 2 times, most recently from 3eeabcd to 952de66 Compare November 23, 2026 19:14
@cdleary
cdleary marked this pull request as ready for review November 23, 2026 20:04
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 23, 2026
…l I/O in the C API

Bind proc-scoped channel lookup to the elaborated top. Expose caller-owned reads and per-tick trace messages through the C API.

Upstream-head: 952de66
@cdleary
cdleary force-pushed the cdleary/2026-11-23-proc-runtime-c-api branch from 952de66 to b3edb28 Compare November 24, 2026 05:28
@cdleary cdleary changed the title [c_api] Expose proc runtime execution and channel I/O in the C API [c_api] Expose interpreter and JIT proc runtimes Nov 24, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
Let callers select an interpreter or JIT runtime when creating a proc network. Both use the same tick, channel I/O, trace transfer, and lifetime contracts.

Upstream-head: b3edb28
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
Let callers select an interpreter or JIT runtime when creating a proc network. Both use the same tick, channel I/O, trace transfer, and lifetime contracts.

Upstream-head: b3edb28
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
Let callers select an interpreter or JIT runtime when creating a proc network. Both use the same tick, channel I/O, trace transfer, and lifetime contracts.

Upstream-head: b3edb28
@cdleary
cdleary force-pushed the cdleary/2026-11-23-proc-runtime-c-api branch from b3edb28 to 42effaa Compare November 28, 2026 18:27
Expose ticking, channel I/O and trace collection on a borrowed package. Reject ambiguous proc-scoped queue bindings before creating either backend, while supporting intentional shared-queue loopbacks.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0