Skip to content

Commit

Permalink
Update base for Update on "[compiler] Instruction reordering"
Browse files Browse the repository at this point in the history
Adds a pass just after DCE to reorder safely reorderable instructions (jsx, primitives, globals) closer to where they are used, to allow other optimization passes to be more effective. Notably, the reordering allows scope merging to be more effective, since that pass relies on two scopes not having intervening instructions — in many cases we can now reorder such instructions out of the way and unlock merging, as demonstrated in the changed fixtures.

The algorithm itself is described in the docblock.

note: This is a cleaned up version of #29579 that is ready for review.

[ghstack-poisoned]
  • Loading branch information
josephsavona committed Jun 12, 2024
2 parents 2774208 + 55fdcf8 commit 0ab6d89
Show file tree
Hide file tree
Showing 93 changed files with 1,953 additions and 1,539 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ module.exports = {
},
],
'no-shadow': ERROR,
'no-unused-vars': [ERROR, {args: 'none'}],
'no-unused-vars': [ERROR, {args: 'none', ignoreRestSiblings: true}],
'no-use-before-define': OFF,
'no-useless-concat': OFF,
quotes: [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true}],
Expand Down Expand Up @@ -571,6 +571,7 @@ module.exports = {
TimeoutID: 'readonly',
WheelEventHandler: 'readonly',
FinalizationRegistry: 'readonly',
Omit: 'readonly',

spyOnDev: 'readonly',
spyOnDevAndProd: 'readonly',
Expand Down
8 changes: 0 additions & 8 deletions compiler/.vscode/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion compiler/apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"vercel-build": "yarn workspaces run build",
"start": "next start",
"lint": "next lint",
"postinstall": "yarn playwright install",
"test": "playwright test"
},
"dependencies": {
Expand Down
2 changes: 0 additions & 2 deletions compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"url": "git+https://github.com/facebook/react-forget.git"
},
"scripts": {
"bundle:meta": "scripts/bundle-meta.sh",
"bundle:oss": "scripts/bundle-oss.sh",
"copyright": "node scripts/copyright.js",
"hash": "scripts/hash.sh",
"start": "yarn workspace playground run start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const CompilationModeSchema = z.enum([
* This is the default mode
*/
"infer",
// Compile only components using Flow component syntax and hooks using hook syntax.
"syntax",
// Compile only functions which are explicitly annotated with "use forget"
"annotation",
// Compile all top-level functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ import {
} from "../ReactiveScopes";
import { alignMethodCallScopes } from "../ReactiveScopes/AlignMethodCallScopes";
import { alignReactiveScopesToBlockScopesHIR } from "../ReactiveScopes/AlignReactiveScopesToBlockScopesHIR";
import { flattenReactiveLoopsHIR } from "../ReactiveScopes/FlattenReactiveLoopsHIR";
import { flattenScopesWithHooksOrUseHIR } from "../ReactiveScopes/FlattenScopesWithHooksOrUseHIR";
import { pruneAlwaysInvalidatingScopes } from "../ReactiveScopes/PruneAlwaysInvalidatingScopes";
import pruneInitializationDependencies from "../ReactiveScopes/PruneInitializationDependencies";
import { stabilizeBlockIds } from "../ReactiveScopes/StabilizeBlockIds";
import { eliminateRedundantPhi, enterSSA, leaveSSA } from "../SSA";
import { inferTypes } from "../TypeInference";
Expand All @@ -91,7 +94,6 @@ import {
validatePreservedManualMemoization,
validateUseMemo,
} from "../Validation";
import pruneInitializationDependencies from "../ReactiveScopes/PruneInitializationDependencies";

export type CompilerPipelineValue =
| { kind: "ast"; name: string; value: CodegenFunction }
Expand Down Expand Up @@ -281,6 +283,20 @@ function* runWithEnvironment(
});

assertValidBlockNesting(hir);

flattenReactiveLoopsHIR(hir);
yield log({
kind: "hir",
name: "FlattenReactiveLoopsHIR",
value: hir,
});

flattenScopesWithHooksOrUseHIR(hir);
yield log({
kind: "hir",
name: "FlattenScopesWithHooksOrUseHIR",
value: hir,
});
}

const reactiveFunction = buildReactiveFunction(hir);
Expand Down Expand Up @@ -320,23 +336,23 @@ function* runWithEnvironment(
name: "BuildReactiveBlocks",
value: reactiveFunction,
});
}

flattenReactiveLoops(reactiveFunction);
yield log({
kind: "reactive",
name: "FlattenReactiveLoops",
value: reactiveFunction,
});
flattenReactiveLoops(reactiveFunction);
yield log({
kind: "reactive",
name: "FlattenReactiveLoops",
value: reactiveFunction,
});

assertScopeInstructionsWithinScopes(reactiveFunction);
flattenScopesWithHooksOrUse(reactiveFunction);
yield log({
kind: "reactive",
name: "FlattenScopesWithHooks",
value: reactiveFunction,
});
}

flattenScopesWithHooksOrUse(reactiveFunction);
yield log({
kind: "reactive",
name: "FlattenScopesWithHooks",
value: reactiveFunction,
});
assertScopeInstructionsWithinScopes(reactiveFunction);

propagateScopeDependencies(reactiveFunction);
yield log({
Expand Down
Loading

0 comments on commit 0ab6d89

Please sign in to comment.