Fixes for the previous PR. What was happening is that our inference was inferring the correct mutable ranges and reactive scopes, but the inlining process left the instructions from the IIFEs inside a separate block, with a 'label' terminal preceding it. When we converted to ReactiveFunction this was preserved as a ReactiveLabelTerminal, which meant that the first instruction for the mutable range could be nested inside one LabelTerminal, while more would be in a subsequent LabelTerminal. But we close blocks based on the block scope! This meant that we'd have leftover instructions (in the second LabelTerminal) that got left out of the block. Furthermore, because inlining was happening after EnterSSA we weren't creating phis correctly. This PR fixes a bunch of these issues, and a subsequent PR handles the remaining cases: * We move DropManualMemo and InlineIIFEs before EnterSSA. This means we lose the ability to use type information, but we ensure that we create proper SSA ids and phis for any reassignments within the IIFE * We also update PruneUnusedLabels to not just remove the unused labels, but to actually remove LabelTerminals that don't need them.
React Forget
React Forget is an experimental Babel plugin to automatically memoize React Hooks and Components.
Development
# tsc --watch
$ yarn dev
# in another terminal window
$ yarn test --watch
Notes
An overview of the implementation can be found in the Architecture Overview.
This transform
- needs plugin-syntax-jsx as a dependency to inherit the syntax from.
- should be run before plugin-transform-react-jsx
- assume the enforcement of rules of hooks, i.e.
- only call hooks from React functions
- only call hooks at the top level
- https://www.npmjs.com/package/eslint-plugin-react-hooks
Scaffolding
- https://github.com/facebook/flow/tree/master/packages/babel-plugin-transform-flow-enums
- https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-jsx/src/create-plugin.ts
Reference
Rust Development
First-Time Setup
- Install Rust using
rustup. See the guide at https://www.rust-lang.org/tools/install. - Install Visual Studio Code from https://code.visualstudio.com/. Note to Meta employees: install the stock version from that website, not the pre-installed version.
- Install the Rust Analyzer VSCode extension through the VSCode marketplace. See instructions at https://rust-analyzer.github.io/manual.html#vs-code.
- Install
cargo editwhich extends cargo with commands to manage dependencies. See https://github.com/killercup/cargo-edit#installation - Install
cargo instawhich extens cargo with a command to manage snapshots. See https://insta.rs/docs/cli/
Workspace Hygiene
Adding Dependencies
To add a dependency, add it to the top-level Cargo.toml
// Cargo.toml
[workspace.dependencies]
...
new_dep = { version = "x.y.z" }
...
Then reference it from your crate as follows:
// crates/forget_foo/Cargo.toml
[dependencies]
...
new_dep = { workspace = true }
...
Adding new crates
Rust's compilation strategy is largely based on parallelizing at the granularity of crates, so builds can be faster when projects have more but smaller crates. Where possible it helps to structure crates to minimize dependencies. For example, our various compiler passes depend on each other in the sense that they often must run in a certain order. However, they often don't need to call each other, so they can generally be split into crates of similar types of passes, so that those crates can compile in parallel.
As a rule of thumb, add crates at roughly the granularity of our existing top-level folds. If you have some one-off utility code that
doesn't fit neatly in a crate, add it to forget_utils rather than add a one-off crate for it.
Running Tests
Run all tests with the following from the root directory:
cargo test
The majority of our tests will (should) live in the forget_fixtures crate, which is a test-only crate that runs compilation end-to-end with snapshot
tests. To run just these tests use:
# quiet version
cargo test -p forget_fixtures
# without suppressing stdout/stderr output
cargo test -p forget_fixtures -- --nocapture
Another hint is that VSCode will show a "Run test" option if you hover over a test in the source code, this lets you run a single test easily. The command line will also give you the CLI command to run just that one test.
Updating Snapshots
The above tests make frequent use of snapshot tests. If snapshots do not match the tests will fail with a diff, if the new output is correct you can accept the changes with:
cargo insta accept
If this command fails, see the note in "first-time setup" about installing cargo insta.
CI Configuration
GitHub CI is configured in .github/workflows/rust.yml.