@samitouri / QOS-React / commits / 229038eab8

[compiler][be] Cleanup class naming in PromoteUsedTemporaries

I forgot to clean this up before landing #30573. ghstack-source-id: 2141471912e410aa12545dcf7989f45447007ba9 Pull Request resolved: https://github.com/facebook/react/pull/30632

Joe Savona committed Aug 7, 2024 at 22:06 UTC 229038eab8df49483eb0f960d4b935435f33b620
1 file changed +19 -4
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts
+19 -4
@@ -23,7 +23,10 @@ import {
23 } from '../HIR/HIR';
24 import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
25
26 -class Visitor extends ReactiveFunctionVisitor<State> {
26 +/**
27 + * Phase 2: Promote identifiers which are used in a place that requires a named variable.
28 + */
29 +class PromoteTemporaries extends ReactiveFunctionVisitor<State> {
30 override visitScope(scopeBlock: ReactiveScopeBlock, state: State): void {
31 for (const dep of scopeBlock.scope.dependencies) {
32 const {identifier} = dep;
@@ -95,7 +98,11 @@ class Visitor extends ReactiveFunctionVisitor<State> {
98 }
99 }
100
98 -class Visitor2 extends ReactiveFunctionVisitor<State> {
101 +/**
102 + * Phase 3: Now that identifiers which need promotion are promoted, find and promote
103 + * all other Identifier instances of each promoted DeclarationId.
104 + */
105 +class PromoteAllInstancedOfPromotedTemporaries extends ReactiveFunctionVisitor<State> {
106 override visitPlace(_id: InstructionId, place: Place, state: State): void {
107 if (
108 place.identifier.name === null &&
@@ -168,6 +175,10 @@ type State = {
175 >; // true if referenced within another scope, false if only accessed outside of scopes
176 };
177
178 +/**
179 + * Phase 1: checks for pruned variables which need to be promoted, as well as
180 + * usage of identifiers as jsx tags, which need to be promoted differently
181 + */
182 class CollectPromotableTemporaries extends ReactiveFunctionVisitor<State> {
183 activeScopes: Array<ScopeId> = [];
184
@@ -227,8 +238,12 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void {
238 promoteIdentifier(place.identifier, state);
239 }
240 }
230 - visitReactiveFunction(fn, new Visitor(), state);
231 - visitReactiveFunction(fn, new Visitor2(), state);
241 + visitReactiveFunction(fn, new PromoteTemporaries(), state);
242 + visitReactiveFunction(
243 + fn,
244 + new PromoteAllInstancedOfPromotedTemporaries(),
245 + state,
246 + );
247 }
248
249 function promoteIdentifier(identifier: Identifier, state: State): void {