Repository navigation
Conversation
…peration handler it names A LuaJIT program calls its Rust library through the FFI by symbol, often through one shared export that runs a different handler for each operation name. Static extraction stopped at both: the Lua call named a C symbol no Lua file defines, and the export's match reached every handler. A synthesis pass, gated on projects holding both languages, links a call through a proven FFI receiver to the one Rust C-ABI export with its symbol, and a literal operation forwarded through Lua and Rust wrappers to the handler its match arm selects. The call into a dispatching export stays as a transport reference that every walk treats as a boundary: the export's callers and impact list its Lua call sites, and code behind it doesn't fan back out to every Lua caller. A call inside a closure counts for the function around it, as the extractor's own calls do. The pass analyzes only the Lua files that can matter: those holding the literal "ffi", then each round those naming a module a carrier was found in. Each file's analysis is stored in the index under a fingerprint of the analyzers and grammars, so a sync re-analyzes only what changed, and a sync that brings a project its first Lua and first Rust files refreshes the bridge. Lua and Rust go to the native kernel by default. The bridge parses with the wasm grammars and builds the same graph from either extractor, which kernel-lua-rust-bridge.test.ts checks. EXTRACTION_VERSION is 29. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ahaeflig
marked this pull request as draft
November 15, 2026 16:47
Author
|
Closing this in favour of three smaller PRs that can be reviewed one at a time:
Before splitting it, I reviewed this PR adversarially and fixed what turned up. Each problem has a test that fails without its fix. The larger ones:
Each new PR's description and 🤖 Generated with Claude Code |
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.
A fresh take on #2331, which you closed with three asks. Each is done:
CODEGRAPH_KERNEL_EXPECT=1. A new kernel test indexes a Lua + Rust project on both paths and requires the same graph. The real repositories below were indexed on both paths and compared row by row.Beyond those asks, three things changed since #2331:
The problem
A LuaJIT program that loads a Rust library calls it through the FFI by symbol. Often it goes through one shared export that runs a different handler for each operation name, like
core.call("task.run", …)→#[no_mangle] extern "C" fn wire_send(op, …)→match op { "task.run" => run(), … }. Static extraction stops at both steps. The Lua call names a C symbol that no Lua file defines, so callers, impact and explore flows end on the Lua side. And reading through the export'smatchwould make every Lua caller reach every handler.What it does
A synthesis pass, run only in projects that hold both Lua and Rust, works from the source alone:
require("ffi"),ffi.C,ffi.load(...)and their aliases) links by exact symbol to the one Rust C-ABI export with that symbol. If two exports share it, neither is linked.matcharm selects.It refuses rather than guesses on shadowed or mutated receivers, ambiguous exports, guarded or
#[cfg]arms, and unsupported transforms. There are no built-in names.docs/design/lua-rust-bridge.mdhas the rules, the limits and the validation.On cost:
"ffi", then, round by round, the files that name a module where a carrier was found. A carrier is a function that forwards an operation into a dispatching export.The hop wording lives in
graph/synthesized-hop.ts, andsrc/index.tsreaches the new sync gate throughengine().What I ran
Linux x64 (WSL2), Node 24.19.0, main at
f72c9d2against this branch.npm run build:kernel,CODEGRAPH_KERNEL_EXPECT=1): 11,283 passed, 2 expected failures, 58 skipped (platform-gated), none failed.CODEGRAPH_KERNEL=0), together with every Lua and Rust resolution test: 53 files, 461 passed.__tests__/kernel-lua-rust-bridge.test.ts(new). It indexes one Lua + Rust project on each path. On the kernel arm it requires both languages to route to the kernel with no file deferred. It requires the same nodes, edges, bridge edges, callers, callees and impact from both. The release gate'skernel-*.test.tsglob picks it up.Real repositories, each indexed fresh with main and with this branch, on both extraction paths. On every corpus the two paths gave byte-identical graphs, as a SHA-256 over every node and edge row (timestamps and the edge rowid aside), for both builds:
sendreachescommand,concedeandcancel, neverderive,historyorcreate.codegraph_explorequery returns each flow, and the native export's callers list its Lua call site as transport.Cost, timed on the monorepo with the native kernel on an otherwise idle machine, alternating the builds. Each figure is the median of six fresh indexes or three sync rounds:
The bridge pass is 7.8 s of that fresh index and the longest synthesis pass. It analyzes all 181 Rust files but only 280 of the 1,158 Lua files. Analyzing every Lua file gives the identical graph at 25.8 s. If the remaining cost matters, the next steps would be following the Rust side from the exports in the same way, or splitting the analyses across the resolver workers. Ruff, with no Lua, runs no bridge pass.
Not done
ffi.load(path)on one branch, and the handle is exported to other modules ascdefs.clib, as in Kong's atc-router above. That needs two proofs the analysis doesn't make yet, so those calls stay unlinked rather than guessed.Existing indexes need a re-index after upgrading, and so does a project after a Cargo manifest edit. No version, dependency or kernel code changed.
🤖 Generated with Claude Code