@samitouri / QOS-React / commits / 5e51d767d1

[compiler] Stop reusing ScopeDep type in AnalyzeFunctions

AnalyzeFunctions was reusing the `ReactiveScopeDependency` type since it happened to have a convenient shape, but we need to change this type to represent optionality. We now use a locally defined type instead. ghstack-source-id: e305c6ede4bcbdffce606336c572cdc6dc1556c3 Pull Request resolved: https://github.com/facebook/react/pull/30811

Joe Savona committed Aug 28, 2024 at 10:44 UTC 5e51d767d179fda586f28e1118fb9ec5c200e35e
1 file changed +8 -6
compiler/packages/babel-plugin-react-compiler/src/Inference/AnalyseFunctions.ts
+8 -6
@@ -13,7 +13,6 @@ import {
13 IdentifierName,
14 LoweredFunction,
15 Place,
16 - ReactiveScopeDependency,
16 isRefOrRefValue,
17 makeInstructionId,
18 } from '../HIR';
@@ -25,9 +24,14 @@ import {inferMutableContextVariables} from './InferMutableContextVariables';
24 import {inferMutableRanges} from './InferMutableRanges';
25 import inferReferenceEffects from './InferReferenceEffects';
26
27 +type Dependency = {
28 + identifier: Identifier;
29 + path: Array<string>;
30 +};
31 +
32 // Helper class to track indirections such as LoadLocal and PropertyLoad.
33 export class IdentifierState {
30 - properties: Map<Identifier, ReactiveScopeDependency> = new Map();
34 + properties: Map<Identifier, Dependency> = new Map();
35
36 resolve(identifier: Identifier): Identifier {
37 const resolved = this.properties.get(identifier);
@@ -39,7 +43,7 @@ export class IdentifierState {
43
44 declareProperty(lvalue: Place, object: Place, property: string): void {
45 const objectDependency = this.properties.get(object.identifier);
42 - let nextDependency: ReactiveScopeDependency;
46 + let nextDependency: Dependency;
47 if (objectDependency === undefined) {
48 nextDependency = {identifier: object.identifier, path: [property]};
49 } else {
@@ -52,9 +56,7 @@ export class IdentifierState {
56 }
57
58 declareTemporary(lvalue: Place, value: Place): void {
55 - const resolved: ReactiveScopeDependency = this.properties.get(
56 - value.identifier,
57 - ) ?? {
59 + const resolved: Dependency = this.properties.get(value.identifier) ?? {
60 identifier: value.identifier,
61 path: [],
62 };