From a37f242f593c685f0a71a8ff35d9f0ebd4e8391a Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Wed, 27 Mar 2024 20:26:13 -0400 Subject: [PATCH] [be][DeriveMinimalDeps] Check current assumptions for conditional control flow --- .../DeriveMinimalDependencies.ts | 18 +++++++++++++++++- .../PropagateScopeDependencies.ts | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/DeriveMinimalDependencies.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/DeriveMinimalDependencies.ts index 2b1a9b9c3c..cd40e8eae0 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/DeriveMinimalDependencies.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/DeriveMinimalDependencies.ts @@ -6,7 +6,7 @@ */ import { CompilerError } from "../CompilerError"; -import { Identifier, ReactiveScopeDependency } from "../HIR"; +import { GeneratedSource, Identifier, ReactiveScopeDependency } from "../HIR"; import { printIdentifier } from "../HIR/PrintHIR"; import { assertExhaustive } from "../Utils/utils"; @@ -490,6 +490,22 @@ function addSubtreeIntersection( suggestions: null, }); + CompilerError.invariant( + otherProperties.every((otherNode) => { + for (const [_, node] of otherNode) { + if (!isUnconditional(node.accessType)) { + return false; + } + } + return true; + }), + { + reason: + "[DeriveMinimalDependencies] Expected otherProperties to only hold unconditional nodes", + loc: GeneratedSource, + } + ); + /* * otherProperties here may contain unconditional nodes as the result of * recursively merging exhaustively conditional children with unconditionally diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts index 81815d8da8..f86146e0e0 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts @@ -446,7 +446,7 @@ class Context { } if (this.#checkValidDependency(maybeDependency)) { - this.#depsInCurrentConditional.add(maybeDependency, true); + this.#depsInCurrentConditional.add(maybeDependency, false); /* * Add info about this dependency to the existing tree * We do not try to join/reduce dependencies here due to missing info