Skip to content

Commit

Permalink
[compiler] Migrate PruneNonEscapingScopes to HIR
Browse files Browse the repository at this point in the history
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: 63aad5c97e8bd6ea58fb1363854d081f50a31fa3
Pull Request resolved: #31882
  • Loading branch information
mvitousek committed Dec 20, 2024
1 parent 6907aa2 commit faa3f49
Show file tree
Hide file tree
Showing 3 changed files with 968 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
promoteUsedTemporaries,
propagateEarlyReturns,
pruneHoistedContexts,
pruneNonEscapingScopes,
pruneNonReactiveDependencies,
pruneUnusedLValues,
pruneUnusedLabels,
Expand Down Expand Up @@ -98,6 +97,7 @@ import {validateNoJSXInTryStatement} from '../Validation/ValidateNoJSXInTryState
import {propagateScopeDependenciesHIR} from '../HIR/PropagateScopeDependenciesHIR';
import {outlineJSX} from '../Optimization/OutlineJsx';
import {optimizePropsMethodCalls} from '../Optimization/OptimizePropsMethodCalls';
import {pruneNonEscapingScopesHIR} from '../HIR/PruneNonEscapingScopesHIR';
import {transformFire} from '../Transform';

export type CompilerPipelineValue =
Expand Down Expand Up @@ -364,6 +364,13 @@ function runWithEnvironment(
inferEffectDependencies(hir);
}

pruneNonEscapingScopesHIR(hir);
log({
kind: 'hir',
name: 'PruneNonEscapingScopesHIR',
value: hir,
});

if (env.config.inlineJsxTransform) {
inlineJsxTransform(hir, env.config.inlineJsxTransform);
log({
Expand All @@ -390,13 +397,6 @@ function runWithEnvironment(
});
assertScopeInstructionsWithinScopes(reactiveFunction);

pruneNonEscapingScopes(reactiveFunction);
log({
kind: 'reactive',
name: 'PruneNonEscapingScopes',
value: reactiveFunction,
});

pruneNonReactiveDependencies(reactiveFunction);
log({
kind: 'reactive',
Expand Down
Loading

0 comments on commit faa3f49

Please sign in to comment.