Conversation
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
…remove spawnTagged (pr2 of closure-cabi series)
arrow-function callbacks now work with child_process.spawn(). captured
variables are lifted into a gc-allocated env struct, registered with the
trampoline slot table (pr1 infrastructure), and dispatched through a
per-shape trampoline that the c bridge invokes after recovering env via
cs_tramp_get(handle).
this removes a long-standing constraint that spawn callbacks had to be
named function references. multi-session demuxing (formerly spawnTagged,
which is hard-removed here) is now a natural capture:
child_process.spawn(cmd, args,
(d) => onOut(sessionId, d),
(d) => onErr(sessionId, d),
(c) => onExit(sessionId, c))
changes:
- c_bridges/child-process-spawn.c: cs_spawn_v2 takes per-callback
{fn_ptr, tramp_handle} pairs. handle == -1 keeps the legacy bare-fn
path; handle >= 0 routes through the trampoline. slots freed in the
pipe-close / post-exit callbacks.
- src/codegen/stdlib/child-process.ts: spawn() accepts arrow functions
alongside variable refs; generates trampoline env + cs_tramp_alloc.
- src/codegen/infrastructure/trampoline-emitter.ts: instantiated on the
llvm generator, emitAll() called after lifted lambdas. stores user fn
as i8* to sidestep the store-type validator.
- chadscript.d.ts, llvm-declarations.ts: spawnTagged and cs_spawn_tagged
removed. spawn signatures updated to document closure support.
- src/codegen/expressions/method-calls/named-object-dispatch.ts: emits a
clear compile error if anyone still calls spawnTagged.
- tests/fixtures/closures-cabi/: three new fixtures cover single-session
closure capture, multi-session demux, and named-fn back-compat.
- tests/fixtures/builtins/cp-spawn-tagged.ts removed (closure form
subsumes it).
…DE.md rule #5) stage1 self-compiled binary crashed on Array.isArray because inserting a new field mid-class shifted GEP indices for subsequent fields (most notably lastInlineLambdaEnvPtr in BaseGenerator, although the same rule applies to LLVMGenerator's own fields). moving trampolineEmitter to the END of both IGeneratorContext and LLVMGenerator's field lists restores the expected struct layout and unblocks stage2 self-hosting.
e0ba0e5 to
8d745e7
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
child_process.spawn(). Captures like per-session state, counters, and object pointers are lifted into a GC-allocated env struct and dispatched through a per-shape C-ABI trampoline (PR1 infrastructure, feat(runtime): C-ABI trampoline closure infrastructure (PR1/4) #560).child_process.spawnTaggedis hard-removed — the closure form is a drop-in replacement:VariableNode, it passes-1as the trampoline handle and the bridge dispatches directly to the bare C fn ptr.Breaking change
child_process.spawnTaggedis removed with no deprecation period. A clear compile error points users to the closure form. The C functioncs_spawn_taggedand its LLVM declaration are gone.Implementation notes
cs_spawninc_bridges/child-process-spawn.cis now a shim over a widenedcs_spawn_v2that takes{fn_ptr, tramp_handle}per callback. Codegen emitscs_spawn_v2directly.uv_spawnfailure also drains any registered slots.TrampolineEmitteris now instantiated onLLVMGenerator, withemitAll()wired in after lifted lambdas. The env struct stores the user fn asi8*to sidestep the codegen store-type validator's inability to parse parenthesised LLVM function-pointer types — the trampoline bitcasts it back before dispatch.handle = -1. Keeps the simple case simple.Scope
child_process.spawnclosure wiring,spawnTaggedremoval, three new fixtures, bridge ABI change.setTimeout/setInterval(PR3), libwebsockets / treesitter bridges (PR4), fat-pointer function values, capture-by-reference.Test plan
npm run verify— all 809 unit tests + stage 0/1/2 self-hosting pass locallytests/fixtures/closures-cabi/spawn-closure-single.ts— arrow closure captures a class pointer and mutates fields across stdout + exit eventstests/fixtures/closures-cabi/spawn-closure-multi-session.ts— two concurrent spawns, each captures its own session, no cross-talk (replaces thespawnTaggeddemonstrator)tests/fixtures/closures-cabi/spawn-named-fn-backcompat.ts— classic named-function-reference form still greentests/fixtures/builtins/cp-spawn*.ts— existing spawn tests untouched and passingtests/fixtures/closures-cabi/trampoline-bridge-smoke.ts— PR1 smoke still passescp-spawn-tagged.ts— the closure-formspawn-closure-multi-sessionsubsumes itchild_process.spawnTagged(...)now emits a clear compile error referencing the closure formDepends on #560.