@samitouri / QOS-React-2 / commits / 7a92b2fe5d

[be] Cleanup logic that matches mutatedId and mutatedDep

Sathya Gunasekaran committed Feb 2, 2023 at 14:05 UTC 7a92b2fe5d322f4b821db43f50c9687705b8575d
1 file changed +12 -16
compiler/forget/src/Inference/AnalyseFunctions.ts
+12 -16
@@ -76,29 +76,25 @@ function infer(
76 value: FunctionExpression,
77 properties: Map<Identifier, Dependency>
78 ) {
79 - const func = value.loweredFunc;
80 - const mutations = func.context.filter((dep) => isMutated(dep.identifier));
81 - const mutatedVariables = new Set(
82 - mutations
79 + const mutations = new Set(
80 + value.loweredFunc.context
81 + .filter((dep) => isMutated(dep.identifier))
82 .map((m) => m.identifier.name)
83 .filter((m) => m !== null) as string[]
84 );
86 - const mutatedDeps: Place[] = [];
85
86 + const mutatedDeps: Place[] = [];
87 for (const dep of value.dependencies) {
89 - if (properties.has(dep.identifier)) {
90 - let captured = properties.get(dep.identifier)!;
91 - let name = captured.place.identifier.name;
88 + let name: string | null = null;
89
93 - if (name === null || !mutatedVariables.has(name)) {
94 - continue;
95 - }
90 + if (properties.has(dep.identifier)) {
91 + const receiver = properties.get(dep.identifier)!;
92 + name = receiver.place.identifier.name;
93 + } else {
94 + name = dep.identifier.name;
95 + }
96
97 - mutatedDeps.push(dep);
98 - } else if (
99 - dep.identifier.name !== null &&
100 - mutatedVariables.has(dep.identifier.name)
101 - ) {
97 + if (name !== null && mutations.has(name)) {
98 mutatedDeps.push(dep);
99 }
100 }