compiler: More precise escape analysis
Our current escape analysis currently works by determing values which are returned, finding the scope those values are produced in, and then walking the dependencies of those scopes. Notably, when we traverse into scopes, we _force_ their values to be memoized — even in cases where we can prove it isn't necessary. The idea of this PR is to change escape analysis to be purely based on the flow of values. So rather than assume all scope deps need to be force-memoized, we look at how those values are used. Note: the main motivation for this PR is the follow-up, which allows us to infer dependencies for pruned scopes. Without this change, inferring deps for pruned scopes causes the escape analysis pass to consider values as escaping which shouldn't be. [ghstack-poisoned]
Showing
- compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts 47 additions, 16 deletions...act-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts
- compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md 10 additions, 2 deletions...tests__/fixtures/compiler/capturing-func-mutate.expect.md
- compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/method-call-computed.expect.md 10 additions, 18 deletions..._tests__/fixtures/compiler/method-call-computed.expect.md
- compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutate-outer-scope-within-value-block.expect.md 9 additions, 15 deletions...opes-fork/mutate-outer-scope-within-value-block.expect.md
Please register or sign in to comment