Update on "[compiler] Use dependencies from source for useMemo scopes"

Summary: This modified the behavior of the compiler when preserving source-level useMemos as reactive scopes to use the depencies from the source as well. This accounts for the possibility that the useMemo in the source is more general than is required by local code, but is necessary due to rules of react violations.

The most complex bit here has to do with explicit dependencies that are globals. As currently written, there's no LoadGlobal that corresponds to a Global dependency of a useMemo, so whenever we convert a useMemo into StartMemoize/FinishMemoize instructions, if we plan to use the useMemo's dependencies we also have to synthesize a LoadGlobal instruction for any globals in the dependencies. 

With this change, ideally the disableMemoization mode will behave exactly like the uncompiled code.

[ghstack-poisoned]
This commit is contained in:
Mike Vitousek
2024-07-02 00:41:25 -07:00
@@ -845,7 +845,12 @@ export function printManualMemoDependency(
if (val.root.kind === "Global") {
rootStr = val.root.binding.binding.name;
} else if (val.root.kind === "InlinedGlobal") {
rootStr = `G(${val.root.name})`;
const nameStr = nameOnly
? val.root.value.identifier.name != null
? printName(val.root.value.identifier.name)
: String(val.root.value.identifier.id)
: printIdentifier(val.root.value.identifier);
rootStr = `G(${val.root.name}=${nameStr})`;
} else {
CompilerError.invariant(val.root.value.identifier.name?.kind === "named", {
reason: "DepsValidation: expected named local variable in depslist",