Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isUseRefType,
makeInstructionId,
Place,
PrunedReactiveScopeBlock,
ReactiveFunction,
ReactiveInstruction,
ReactiveScope,
Expand Down Expand Up @@ -687,6 +688,16 @@ class PropagationVisitor extends ReactiveFunctionVisitor<Context> {
scope.scope.dependencies = scopeDependencies;
}

override visitPrunedScope(
scopeBlock: PrunedReactiveScopeBlock,
context: Context
): void {
const scopeDependencies = context.enter(scopeBlock.scope, () => {
this.visitBlock(scopeBlock.instructions, context);
});
scopeBlock.scope.dependencies = scopeDependencies;
}

override visitInstruction(
instruction: ReactiveInstruction,
context: Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import {
IdentifierId,
PrunedReactiveScopeBlock,
ReactiveFunction,
ReactiveInstruction,
ReactiveScope,
ReactiveScopeBlock,
isSetStateType,
} from "../HIR";
Expand Down Expand Up @@ -95,23 +97,34 @@ class Visitor extends ReactiveFunctionVisitor<ReactiveIdentifiers> {
state: ReactiveIdentifiers
): void {
this.traverseScope(scopeBlock, state);
for (const dep of scopeBlock.scope.dependencies) {
this.visitScopeImpl(scopeBlock.scope, state);
}

override visitPrunedScope(
scopeBlock: PrunedReactiveScopeBlock,
state: ReactiveIdentifiers
): void {
this.traversePrunedScope(scopeBlock, state);
}

visitScopeImpl(scope: ReactiveScope, state: ReactiveIdentifiers): void {
for (const dep of scope.dependencies) {
const isReactive = state.has(dep.identifier.id);
if (!isReactive) {
scopeBlock.scope.dependencies.delete(dep);
scope.dependencies.delete(dep);
}
}
if (scopeBlock.scope.dependencies.size !== 0) {
if (scope.dependencies.size !== 0) {
/**
* If any of a scope's dependencies are reactive, then all of its
* outputs will re-evaluate whenever those dependencies change.
* Mark all of the outputs as reactive to reflect the fact that
* they may change in practice based on a reactive input.
*/
for (const [, declaration] of scopeBlock.scope.declarations) {
for (const [, declaration] of scope.declarations) {
state.add(declaration.identifier.id);
}
for (const reassignment of scopeBlock.scope.reassignments) {
for (const reassignment of scope.reassignments) {
state.add(reassignment.id);
}
}
Expand Down