Repository navigation
[compiler] Port React Compiler to Rust - #36173
Merged
Merged
Conversation
added 30 commits
March 21, 2026 11:17
…s in reactive printer Add HirFunctionFormatter callback to reactive DebugPrinter so FunctionExpression and ObjectMethod values can print their inner HIR functions with full detail. Bridge debug_print.rs formatting into the reactive printer via format_hir_function_into.
Remove blank line output for unprinted outlined functions that caused Environment section misalignment. 1285/1717 fixtures now pass.
…unction value blocks Port the TS logic that converts StoreLocal to LoadLocal when the last instruction of a value block stores to an unnamed temporary. This fixes identifier/place mismatches in the reactive function output. 1459/1717 fixtures now pass.
In BuildReactiveFunction, for-loops should use the update block as the continue target when present, falling back to the test block. Matches TS terminal.update ?? terminal.test pattern.
This is an experimental, work-in-progress port of React Compiler to Rust. Key points:
correctness:
development:
yarn snap --rustis the primary test suite, testing that we error or compile as expected. It does not test the inner state of the compiler along the way, though, making it less suitable for finding subtle logic gaps btw the TS and Rust versions. It's also Babel based, making it less easy to test OXC and SWC integrations.compiler/scripts/test-e2e.shis an e2e test of all 3 variants (babel wrapper around Rust, OXC/SWC integrations) against the TS implementation. This does a partial comparison, focused on final output code only (doesn't test error details etc). Useful for getting the swc and oxc integrations closer to parity.compiler/script/test-rust-port.shdoes detailed testing of the internal compiler state after each pass, in addition to checking the final output code. This is the key script used to port the compiler, ensuring not just that the output was the same but that each pass was capturing all the same detail. This script can be pointed at any directory of JS files, which we expect to use for internal testing at Meta.For Partners
We're excited to partner with teams to integrate the Rust version of React Compiler into other tools, like OXC and SWC. If you're interested in working with us on this, the best place to start is by taking a look at the react_compiler_swc and react_compiler_oxc crates. These give you an idea of the API shape that we're thinking of.
Note that the conversion from any AST into our HIR is complex, and we can only maintain one version. Hence we've aligned on using a Babel-like AST as our public API. Another key point is that we don't yet implement our own scope analysis (since the TS version of the compiler relied on Babel's scope analysis), so for now we require that the scope data be serialized. It's a denormalized graph, and some metadata has to be stored to associate nodes with scopes. We're open to feedback about the AST and scope representation - we iterated a bit just to get things to work, but it can be more optimal.
Key changes that we are considering:
Option<Program>, which isSomeif anything changed. This requires replacing the entire program. We plan to change this to return a series of patches to apply, in a form that is reasonably usable and efficient for all the integrations we care about (Babel, OXC, SWC, etc).In terms of the shape of the integration, we anticipate that each integration would have the following:
crates/react_compiler_<name>from our repoThis setup lets us make changes to the integration layer easily within our repo. Feedback appreciated!