Skip to content

Commit faa3f49

Browse files
committed
[compiler] Migrate PruneNonEscapingScopes to HIR
Summary: PruneNonEscapingScopes does a pretty powerful escape analysis, which we might want to apply for other purposes in our HIR passes. This ports this pass to HIR. For the most part, this implementation is identical to the ReactiveFunction version. It now handles phis instead of conditional ReactiveExpressions, which it does by treating all the phi operands as possibly aliasing the lvalue. This also requires that we iterate the aliasing analysis to a fixpoint, because the HIR has backedges which the ReactiveFunctions don't. In our fixtures, this only changes one result, which appears to have become more accurate. I plan on testing this internally in a sync before landing. ghstack-source-id: 63aad5c Pull Request resolved: #31882
1 parent 6907aa2 commit faa3f49

File tree

3 files changed

+968
-16
lines changed

3 files changed

+968
-16
lines changed

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import {
5959
promoteUsedTemporaries,
6060
propagateEarlyReturns,
6161
pruneHoistedContexts,
62-
pruneNonEscapingScopes,
6362
pruneNonReactiveDependencies,
6463
pruneUnusedLValues,
6564
pruneUnusedLabels,
@@ -98,6 +97,7 @@ import {validateNoJSXInTryStatement} from '../Validation/ValidateNoJSXInTryState
9897
import {propagateScopeDependenciesHIR} from '../HIR/PropagateScopeDependenciesHIR';
9998
import {outlineJSX} from '../Optimization/OutlineJsx';
10099
import {optimizePropsMethodCalls} from '../Optimization/OptimizePropsMethodCalls';
100+
import {pruneNonEscapingScopesHIR} from '../HIR/PruneNonEscapingScopesHIR';
101101
import {transformFire} from '../Transform';
102102

103103
export type CompilerPipelineValue =
@@ -364,6 +364,13 @@ function runWithEnvironment(
364364
inferEffectDependencies(hir);
365365
}
366366

367+
pruneNonEscapingScopesHIR(hir);
368+
log({
369+
kind: 'hir',
370+
name: 'PruneNonEscapingScopesHIR',
371+
value: hir,
372+
});
373+
367374
if (env.config.inlineJsxTransform) {
368375
inlineJsxTransform(hir, env.config.inlineJsxTransform);
369376
log({
@@ -390,13 +397,6 @@ function runWithEnvironment(
390397
});
391398
assertScopeInstructionsWithinScopes(reactiveFunction);
392399

393-
pruneNonEscapingScopes(reactiveFunction);
394-
log({
395-
kind: 'reactive',
396-
name: 'PruneNonEscapingScopes',
397-
value: reactiveFunction,
398-
});
399-
400400
pruneNonReactiveDependencies(reactiveFunction);
401401
log({
402402
kind: 'reactive',

0 commit comments

Comments
 (0)