react/compiler
Jordan Brown 03297e048d
[compiler] transform fire calls (#31796)
This is the diff with the meaningful changes. The approach is:
1. Collect fire callees and remove fire() calls, create a new binding
for the useFire result
2. Update LoadLocals for captured callees to point to the useFire result
3. Update function context to reference useFire results
4. Insert useFire calls after getting to the component scope

This approach aims to minimize the amount of new bindings we introduce
for the function expressions
to minimize bookkeeping for dependency arrays. We keep all of the
LoadLocals leading up to function
calls as they are and insert new instructions to load the originally
captured function, call useFire,
and store the result in a new promoted temporary. The lvalues that
referenced the original callee are
changed to point to the new useFire result.

This is the minimal diff to implement the expected behavior (up to
importing the useFire call, next diff)
and further stacked diffs implement error handling. The rules for fire
are:
1. If you use fire for a callee in the effect once you must use it for
every time you call it in that effect
2. You can only use fire in a useEffect lambda/functions defined inside
the useEffect lambda

There is still more work to do here, like updating the effect dependency
array and handling object methods

--
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31796).
* #31811
* #31798
* #31797
* __->__ #31796
2024-12-20 15:09:09 -05:00
..
apps/playground [compiler][be] Playground now compiles entire program (#31774) 2024-12-16 14:43:21 -05:00
crates Fix rust lints 2024-08-06 14:48:32 -04:00
docs Punctuation & correcting spelling mistakes (#30592) 2024-08-09 14:53:53 -07:00
fixtures [cleanup] Remove compiler runtime-compat fixture library (#31430) 2024-11-05 14:14:39 -05:00
packages [compiler] transform fire calls (#31796) 2024-12-20 15:09:09 -05:00
scripts [ci:compiler] Only add latest tag to non-experimental (#31288) 2024-10-18 13:24:30 -04:00
.eslintrc.js
.gitignore
Cargo.lock
Cargo.toml
package.json [compiler] Update hermes deps (#31586) 2024-11-19 10:52:48 -05:00
README.md
rust-toolchain.toml
rustfmt.toml
yarn.lock Revert "Replace deprecated dependency in eslint-plugin-react-compiler" (#31665) 2024-12-03 11:46:08 -05:00

React Compiler

React Compiler is a compiler that optimizes React applications, ensuring that only the minimal parts of components and hooks will re-render when state changes. The compiler also validates that components and hooks follow the Rules of React.

More information about the design and architecture of the compiler are covered in the Design Goals.

More information about developing the compiler itself is covered in the Development Guide.