@samitouri / QOS-React / commits / 34595b84c8

[syntax] Followup: clean up InferReactiveIdentifiers

Mofei Zhang committed Feb 3, 2023 at 15:44 UTC 34595b84c8e836bb56b9d495aea5c1d7cd46bbe6
1 file changed +11 -4
compiler/forget/src/ReactiveScopes/InferReactiveIdentifiers.ts
+11 -4
@@ -6,6 +6,7 @@
6 */
7
8 import {
9 + Effect,
10 Identifier,
11 ReactiveFunction,
12 ReactiveInstruction,
@@ -44,7 +45,10 @@ class Environment extends ReactiveFunctionVisitor<IdentifierReactivity> {
45 if (hasReactiveInput) {
46 // all mutating effects must also be marked as reactive
47 for (const operand of eachReactiveValueOperand(value)) {
47 - if (operand.effect === "store" || operand.effect === "mutate") {
48 + if (
49 + operand.effect === Effect.Store ||
50 + operand.effect === Effect.Mutate
51 + ) {
52 // Explicitly compare to `false` here, since absence from the
53 // map indicates a free variable
54 // todo [@mofeiZ] add knowledge about free variables
@@ -78,11 +82,15 @@ class Environment extends ReactiveFunctionVisitor<IdentifierReactivity> {
82 * ```
83 * This an overestimate when two identifiers have overlapping scope, but
84 * one is not actually reactive. However, since the same ReactiveBlock now
81 - * produces both identifiers, they are effectively both effective (i.e.
85 + * produces both identifiers, they are effectively both reactive (i.e.
86 * object creation is not stable)
87 * e.g.
88 * ```javascript
89 * function bar(props) {
90 + * // x and y have overlapping mutableRanges, so they share a ReactiveScope
91 + * // (even though they are not aliased together)
92 + * // technically y has no reactive inputs, but it becomes non-stable due to
93 + * // sharing a ReactiveScopeBlock with x
94 * let x = {};
95 * let y = [];
96 * mutate1(x, props);
@@ -101,8 +109,7 @@ export function inferReactiveIdentifiers(
109 const actuallyReactiveScopes = new Set<ReactiveScope>();
110 let prevScopesSize = -1;
111
104 - // TODO(mofeiZ): avoid fixpoint iteration by keeping a map of identifiers
105 - // read by a ReactiveScope (that are produced outside of it)
112 + // TODO(mofeiZ): avoid fixpoint iteration
113 while (actuallyReactiveScopes.size > prevScopesSize) {
114 prevScopesSize = actuallyReactiveScopes.size;
115 visitReactiveFunction(fn, visitor, reactivityMap);