@samitouri / QOS-React / commits / da004f1885

Add GetIterator instruction

ghstack-source-id: 8ed2deed7606c48414de74cb2781a5fde6cd6f59 Pull Request resolved: https://github.com/facebook/react-forget/pull/2892

Joe Savona committed Apr 24, 2024 at 14:59 UTC da004f18853f84c16c2c053a9336f069d80c6755
9 files changed +34 -2
compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+6 -1
@@ -957,10 +957,15 @@ export type InstructionValue =
957 loc: SourceLocation;
958 }
959 | {
960 - kind: "NextIterableOf";
960 + kind: "GetIterator";
961 value: Place; // the collection
962 loc: SourceLocation;
963 }
964 + | {
965 + kind: "NextIterableOf";
966 + value: Place; // the iterator created with GetIterator
967 + loc: SourceLocation;
968 + }
969 | {
970 kind: "NextPropertyOf";
971 value: Place; // the collection
compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts
+4
@@ -609,6 +609,10 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
609 value = `Await ${printPlace(instrValue.value)}`;
610 break;
611 }
612 + case "GetIterator": {
613 + value = `GetIterator ${printPlace(instrValue.value)}`;
614 + break;
615 + }
616 case "NextIterableOf": {
617 value = `NextIterableOf ${printPlace(instrValue.value)}`;
618 break;
compiler/packages/babel-plugin-react-forget/src/HIR/visitors.ts
+2
@@ -208,6 +208,7 @@ export function* eachInstructionValueOperand(
208 yield instrValue.value;
209 break;
210 }
211 + case "GetIterator":
212 case "NextIterableOf": {
213 yield instrValue.value;
214 break;
@@ -527,6 +528,7 @@ export function mapInstructionValueOperands(
528 instrValue.value = fn(instrValue.value);
529 break;
530 }
531 + case "GetIterator":
532 case "NextIterableOf": {
533 instrValue.value = fn(instrValue.value);
534 break;
compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
+14 -1
@@ -1810,7 +1810,7 @@ function inferBlock(
1810 }
1811 continue;
1812 }
1813 - case "NextIterableOf": {
1813 + case "GetIterator": {
1814 effect = { kind: Effect.Capture, reason: ValueReason.Other };
1815 lvalueEffect = Effect.Store;
1816 valueKind = {
@@ -1820,6 +1820,19 @@ function inferBlock(
1820 };
1821 break;
1822 }
1823 + case "NextIterableOf": {
1824 + effect = {
1825 + kind: Effect.Capture,
1826 + reason: ValueReason.Other,
1827 + };
1828 + lvalueEffect = Effect.Store;
1829 + valueKind = {
1830 + kind: ValueKind.Mutable,
1831 + reason: new Set([ValueReason.Other]),
1832 + context: new Set(),
1833 + };
1834 + break;
1835 + }
1836 case "NextPropertyOf": {
1837 effect = { kind: Effect.Read, reason: ValueReason.Other };
1838 lvalueEffect = Effect.Store;
compiler/packages/babel-plugin-react-forget/src/Optimization/DeadCodeElimination.ts
+1
@@ -325,6 +325,7 @@ function pruneableValue(value: InstructionValue, state: State): boolean {
325 // Potentially safe to prune, since they should just be creating new values
326 return false;
327 }
328 + case "GetIterator":
329 case "NextPropertyOf":
330 case "NextIterableOf": {
331 /*
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+4
@@ -1772,6 +1772,10 @@ function codegenInstructionValue(
1772 value = t.awaitExpression(codegenPlaceToExpression(cx, instrValue.value));
1773 break;
1774 }
1775 + case "GetIterator": {
1776 + value = codegenPlaceToExpression(cx, instrValue.value);
1777 + break;
1778 + }
1779 case "NextIterableOf": {
1780 value = codegenPlaceToExpression(cx, instrValue.value);
1781 break;
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+1
@@ -188,6 +188,7 @@ function mayAllocate(env: Environment, instruction: Instruction): boolean {
188 case "JSXText":
189 case "TemplateLiteral":
190 case "Primitive":
191 + case "GetIterator":
192 case "NextIterableOf":
193 case "NextPropertyOf":
194 case "Debugger":
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PruneNonEscapingScopes.ts
+1
@@ -475,6 +475,7 @@ function computeMemoizationInputs(
475 }
476 case "Await":
477 case "TypeCastExpression":
478 + case "GetIterator":
479 case "NextIterableOf": {
480 return {
481 // Indirection for the inner value, memoized if the value is
compiler/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts
+1
@@ -337,6 +337,7 @@ function* generateInstructionTypes(
337 case "ComputedLoad":
338 case "TaggedTemplateExpression":
339 case "Await":
340 + case "GetIterator":
341 case "NextIterableOf":
342 case "UnsupportedNode":
343 case "Debugger":