Move logic for making reactive scope decls all reactive
InferReactiveIdentifiers has some extra logic to find identifiers declared in the same scope, and promote non-reactive identifiers to reactive if they appear inside a reactive scope (reactive scope == scope with one or more (reactive) dependencies). Even though the identifier alone might not be technically reactive (have no reactive inputs), it can get re-recreated if the scope re-evaluates. We can now do this during PruneNonReactiveDependencies as we exit out of each scope.
Joe Savona committed
Feb 14, 2023 at 15:27 UTC
490c204dcf8b648994977e87cd3cc8c995ac8a32
2 files changed
+6
-15
compiler/forget/src/ReactiveScopes/InferReactiveIdentifiers.ts
-14
@@ -10,7 +10,6 @@ import {
10
Identifier,
11
ReactiveFunction,
12
ReactiveInstruction,
13
- ReactiveScope,
13
} from "../HIR/HIR";
14
import { parseHookCall } from "../Inference/InferReferenceEffects";
15
import {
@@ -118,21 +117,8 @@ export function inferReactiveIdentifiers(
117
for (const param of fn.params) {
118
reactivityMap.set(param.identifier, true);
119
}
121
- const actuallyReactiveScopes = new Set<ReactiveScope>();
122
-
120
visitReactiveFunction(fn, visitor, reactivityMap);
121
125
- for (const [id, value] of reactivityMap) {
126
- const { scope } = id;
127
- if (value && scope != null) {
128
- actuallyReactiveScopes.add(scope);
129
- }
130
- }
131
- for (const [id, _] of reactivityMap) {
132
- if (id.scope && actuallyReactiveScopes.has(id.scope)) {
133
- reactivityMap.set(id, true);
134
- }
135
- }
122
const result = new Set<Identifier>();
123
reactivityMap.forEach((isReactive, id) => {
124
if (isReactive) result.add(id);
compiler/forget/src/ReactiveScopes/PruneNonReactiveDependencies.ts
+6
-1
@@ -31,11 +31,16 @@ class Visitor extends ReactiveFunctionVisitor<State> {
31
scope.scope.dependencies.delete(dep);
32
}
33
}
34
- // If a scope now has no dependencies, then its declarations are all non-reactive
34
if (scope.scope.dependencies.size === 0) {
35
+ // If a scope has no dependencies, then its declarations are all non-reactive
36
for (const [, declaration] of scope.scope.declarations) {
37
state.delete(declaration);
38
}
39
+ } else {
40
+ // otherwise, all the scope's declarations are reactive
41
+ for (const [, declaration] of scope.scope.declarations) {
42
+ state.add(declaration);
43
+ }
44
}
45
}
46
}