From c4ac65c93cd9481e439090856812548db878af9f Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 7 Aug 2024 22:05:59 -0700 Subject: [PATCH] [compiler][be] Cleanup class naming in PromoteUsedTemporaries I forgot to clean this up before landing #30573. [ghstack-poisoned] --- .../ReactiveScopes/PromoteUsedTemporaries.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts index ac68050ddbf..d897b924ce6 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts @@ -23,7 +23,10 @@ import { } from '../HIR/HIR'; import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors'; -class Visitor extends ReactiveFunctionVisitor { +/** + * Phase 2: Promote identifiers which are used in a place that requires a named variable. + */ +class PromoteTemporaries extends ReactiveFunctionVisitor { override visitScope(scopeBlock: ReactiveScopeBlock, state: State): void { for (const dep of scopeBlock.scope.dependencies) { const {identifier} = dep; @@ -95,7 +98,11 @@ class Visitor extends ReactiveFunctionVisitor { } } -class Visitor2 extends ReactiveFunctionVisitor { +/** + * Phase 3: Now that identifiers which need promotion are promoted, find and promote + * all other Identifier instances of each promoted DeclarationId. + */ +class PromoteAllInstancedOfPromotedTemporaries extends ReactiveFunctionVisitor { override visitPlace(_id: InstructionId, place: Place, state: State): void { if ( place.identifier.name === null && @@ -168,6 +175,10 @@ type State = { >; // true if referenced within another scope, false if only accessed outside of scopes }; +/** + * Phase 1: checks for pruned variables which need to be promoted, as well as + * usage of identifiers as jsx tags, which need to be promoted differently + */ class CollectPromotableTemporaries extends ReactiveFunctionVisitor { activeScopes: Array = []; @@ -227,8 +238,12 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void { promoteIdentifier(place.identifier, state); } } - visitReactiveFunction(fn, new Visitor(), state); - visitReactiveFunction(fn, new Visitor2(), state); + visitReactiveFunction(fn, new PromoteTemporaries(), state); + visitReactiveFunction( + fn, + new PromoteAllInstancedOfPromotedTemporaries(), + state, + ); } function promoteIdentifier(identifier: Identifier, state: State): void {