@samitouri / QOS-React / commits / e7fcc4e6a8

Rename promoteTemporary helpers

Renames the helpers for promoting temporaries to named identifiers, per feedback earlier in the stack.

Joe Savona committed Mar 6, 2024 at 11:16 UTC e7fcc4e6a8116e1fde722b383dc7ad54e550a55a
7 files changed +26 -32
compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+6 -6
@@ -44,7 +44,7 @@ import {
44 Type,
45 makeInstructionId,
46 makeType,
47 - promoteTemporaryToNamedIdentifier,
47 + promoteTemporary,
48 } from "./HIR";
49 import HIRBuilder, { Bindings } from "./HIRBuilder";
50 import { BuiltInArrayId } from "./ObjectShape";
@@ -1216,7 +1216,7 @@ function lowerStatement(
1216 reactive: false,
1217 loc: handlerBindingPath.node.loc ?? GeneratedSource,
1218 };
1219 - promoteTemporaryToNamedIdentifier(place.identifier);
1219 + promoteTemporary(place.identifier);
1220 lowerValueToTemporary(builder, {
1221 kind: "DeclareLocal",
1222 lvalue: {
@@ -3422,7 +3422,7 @@ function lowerAssignment(
3422 builder,
3423 element.node.loc ?? GeneratedSource
3424 );
3425 - promoteTemporaryToNamedIdentifier(temp.identifier);
3425 + promoteTemporary(temp.identifier);
3426 items.push({
3427 kind: "Spread",
3428 place: { ...temp },
@@ -3450,7 +3450,7 @@ function lowerAssignment(
3450 builder,
3451 element.node.loc ?? GeneratedSource
3452 );
3453 - promoteTemporaryToNamedIdentifier(temp.identifier);
3453 + promoteTemporary(temp.identifier);
3454 items.push({ ...temp });
3455 followups.push({ place: temp, path: element as NodePath<t.LVal> }); // TODO remove type cast
3456 }
@@ -3521,7 +3521,7 @@ function lowerAssignment(
3521 builder,
3522 property.node.loc ?? GeneratedSource
3523 );
3524 - promoteTemporaryToNamedIdentifier(temp.identifier);
3524 + promoteTemporary(temp.identifier);
3525 properties.push({
3526 kind: "Spread",
3527 place: { ...temp },
@@ -3602,7 +3602,7 @@ function lowerAssignment(
3602 builder,
3603 element.node.loc ?? GeneratedSource
3604 );
3605 - promoteTemporaryToNamedIdentifier(temp.identifier);
3605 + promoteTemporary(temp.identifier);
3606 properties.push({
3607 kind: "ObjectProperty",
3608 type: "property",
compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+2 -6
@@ -1004,9 +1004,7 @@ export function makeIdentifierName(name: string): ValidatedIdentifier {
1004 /**
1005 * Given an unnamed identifier, promote it to a named identifier.
1006 */
1007 -export function promoteTemporaryToNamedIdentifier(
1008 - identifier: Identifier
1009 -): void {
1007 +export function promoteTemporary(identifier: Identifier): void {
1008 CompilerError.invariant(identifier.name === null, {
1009 reason: `Expected a temporary (unnamed) identifier`,
1010 loc: GeneratedSource,
@@ -1027,9 +1025,7 @@ export function isPromotedTemporary(name: string): boolean {
1025 * Given an unnamed identifier, promote it to a named identifier, distinguishing
1026 * it as a value that needs to be capitalized since it appears in JSX element tag position
1027 */
1030 -export function promoteTemporaryJsxTagToNamedIdentifier(
1031 - identifier: Identifier
1032 -): void {
1028 +export function promoteTemporaryJsxTag(identifier: Identifier): void {
1029 CompilerError.invariant(identifier.name === null, {
1030 reason: `Expected a temporary (unnamed) identifier`,
1031 loc: GeneratedSource,
compiler/packages/babel-plugin-react-forget/src/Inference/InlineImmediatelyInvokedFunctionExpressions.ts
+2 -2
@@ -20,7 +20,7 @@ import {
20 Place,
21 makeInstructionId,
22 makeType,
23 - promoteTemporaryToNamedIdentifier,
23 + promoteTemporary,
24 reversePostorderBlocks,
25 } from "../HIR";
26 import { markInstructionIds, markPredecessors } from "../HIR/HIRBuilder";
@@ -159,7 +159,7 @@ export function inlineImmediatelyInvokedFunctionExpressions(
159 declareTemporary(fn.env, block, result);
160
161 // Promote the temporary with a name as we require this to persist
162 - promoteTemporaryToNamedIdentifier(result.identifier);
162 + promoteTemporary(result.identifier);
163
164 /*
165 * Rewrite blocks from the lambda to replace any `return` with a
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2 -4
@@ -2060,13 +2060,11 @@ function codegenPlace(cx: Context, place: Place): t.Expression | t.JSXText {
2060 }
2061
2062 function convertIdentifier(identifier: Identifier): t.Identifier {
2063 - if (identifier.name !== null) {
2064 - return t.identifier(identifier.name.value);
2065 - }
2066 - CompilerError.invariant(false, {
2063 + CompilerError.invariant(identifier.name !== null, {
2064 reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`,
2065 loc: GeneratedSource,
2066 description: `identifier ${identifier.id} is unnamed`,
2067 suggestions: null,
2068 });
2069 + return t.identifier(identifier.name.value);
2070 }
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.ts
+2 -2
@@ -15,7 +15,7 @@ import {
15 ReactiveInstruction,
16 ReactiveScopeBlock,
17 ReactiveStatement,
18 - promoteTemporaryToNamedIdentifier,
18 + promoteTemporary,
19 } from "../HIR";
20 import { eachPatternOperand, mapPatternOperands } from "../HIR/visitors";
21 import {
@@ -159,7 +159,7 @@ function transformDestructuring(
159 name: null, // overwritten below
160 },
161 };
162 - promoteTemporaryToNamedIdentifier(temporary.identifier);
162 + promoteTemporary(temporary.identifier);
163 renamed.set(place, temporary);
164 return temporary;
165 });
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PromoteUsedTemporaries.ts
+10 -10
@@ -15,8 +15,8 @@ import {
15 ReactiveFunction,
16 ReactiveScopeBlock,
17 ReactiveValue,
18 - promoteTemporaryJsxTagToNamedIdentifier,
19 - promoteTemporaryToNamedIdentifier,
18 + promoteTemporary,
19 + promoteTemporaryJsxTag,
20 } from "../HIR/HIR";
21 import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
22
@@ -29,7 +29,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
29 for (const dep of block.scope.dependencies) {
30 const { identifier } = dep;
31 if (identifier.name == null) {
32 - promoteTemporary(identifier, state);
32 + promoteIdentifier(identifier, state);
33 }
34 }
35 /*
@@ -41,14 +41,14 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
41 */
42 for (const [, declaration] of block.scope.declarations) {
43 if (declaration.identifier.name == null) {
44 - promoteTemporary(declaration.identifier, state);
44 + promoteIdentifier(declaration.identifier, state);
45 }
46 }
47 }
48
49 override visitParam(place: Place, state: VisitorState): void {
50 if (place.identifier.name === null) {
51 - promoteTemporary(place.identifier, state);
51 + promoteIdentifier(place.identifier, state);
52 }
53 }
54
@@ -72,7 +72,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
72 for (const operand of fn.params) {
73 const place = operand.kind === "Identifier" ? operand : operand.place;
74 if (place.identifier.name === null) {
75 - promoteTemporary(place.identifier, state);
75 + promoteIdentifier(place.identifier, state);
76 }
77 }
78 visitReactiveFunction(fn, this, state);
@@ -102,13 +102,13 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void {
102 for (const operand of fn.params) {
103 const place = operand.kind === "Identifier" ? operand : operand.place;
104 if (place.identifier.name === null) {
105 - promoteTemporary(place.identifier, state);
105 + promoteIdentifier(place.identifier, state);
106 }
107 }
108 visitReactiveFunction(fn, new Visitor(), state);
109 }
110
111 -function promoteTemporary(identifier: Identifier, state: VisitorState): void {
111 +function promoteIdentifier(identifier: Identifier, state: VisitorState): void {
112 CompilerError.invariant(identifier.name === null, {
113 reason:
114 "promoteTemporary: Expected to be called only for temporary variables",
@@ -117,8 +117,8 @@ function promoteTemporary(identifier: Identifier, state: VisitorState): void {
117 suggestions: null,
118 });
119 if (state.tags.has(identifier.id)) {
120 - promoteTemporaryJsxTagToNamedIdentifier(identifier);
120 + promoteTemporaryJsxTag(identifier);
121 } else {
122 - promoteTemporaryToNamedIdentifier(identifier);
122 + promoteTemporary(identifier);
123 }
124 }
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateEarlyReturns.ts
+2 -2
@@ -16,7 +16,7 @@ import {
16 ReactiveStatement,
17 ReactiveTerminalStatement,
18 makeInstructionId,
19 - promoteTemporaryToNamedIdentifier,
19 + promoteTemporary,
20 } from "../HIR";
21 import { createTemporaryPlace } from "../HIR/HIRBuilder";
22 import { EARLY_RETURN_SENTINEL } from "./CodegenReactiveFunction";
@@ -275,7 +275,7 @@ class Transform extends ReactiveFunctionTransform<State> {
275 earlyReturnValue = state.earlyReturnValue;
276 } else {
277 const identifier = createTemporaryPlace(this.env).identifier;
278 - promoteTemporaryToNamedIdentifier(identifier);
278 + promoteTemporary(identifier);
279 earlyReturnValue = {
280 label: this.env.nextBlockId,
281 loc,