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.
This commit is contained in:
Joe Savona
2023-02-14 15:27:52 -08:00
parent b1ee356805
commit 490c204dcf
2 changed files with 6 additions and 15 deletions
@@ -10,7 +10,6 @@ import {
Identifier,
ReactiveFunction,
ReactiveInstruction,
ReactiveScope,
} from "../HIR/HIR";
import { parseHookCall } from "../Inference/InferReferenceEffects";
import {
@@ -118,21 +117,8 @@ export function inferReactiveIdentifiers(
for (const param of fn.params) {
reactivityMap.set(param.identifier, true);
}
const actuallyReactiveScopes = new Set<ReactiveScope>();
visitReactiveFunction(fn, visitor, reactivityMap);
for (const [id, value] of reactivityMap) {
const { scope } = id;
if (value && scope != null) {
actuallyReactiveScopes.add(scope);
}
}
for (const [id, _] of reactivityMap) {
if (id.scope && actuallyReactiveScopes.has(id.scope)) {
reactivityMap.set(id, true);
}
}
const result = new Set<Identifier>();
reactivityMap.forEach((isReactive, id) => {
if (isReactive) result.add(id);
@@ -31,11 +31,16 @@ class Visitor extends ReactiveFunctionVisitor<State> {
scope.scope.dependencies.delete(dep);
}
}
// If a scope now has no dependencies, then its declarations are all non-reactive
if (scope.scope.dependencies.size === 0) {
// If a scope has no dependencies, then its declarations are all non-reactive
for (const [, declaration] of scope.scope.declarations) {
state.delete(declaration);
}
} else {
// otherwise, all the scope's declarations are reactive
for (const [, declaration] of scope.scope.declarations) {
state.add(declaration);
}
}
}
}