Update on "[compiler] Add wrapper functions to wrap change-detection storage and loading from the memo cache"

Summary: We may wish to perform some additional computation on values when they enter or exit the memo cache in change detection mode (e.g. make a deep copy, restore the original value). This builds support for doing so.

In addition, it drops the "ForDebugging" part of the flag name and makes it compatible with "disableMemoization": if memoization is disabled, we implement that by not restoring the old version of the value unless we're in a source-level memo block.

[ghstack-poisoned]
This commit is contained in:
Mike Vitousek
2024-07-26 15:16:27 -07:00
@@ -706,7 +706,7 @@ function codegenReactiveScope(
const loadNameStr = cx.synthesizeName(`old$${nameStr}`);
let storedValue, restoredValue;
let storedValue, restoredValue, restoredRecomputed;
if (cx.env.config.enableChangeDetection.wrappers != null) {
storedValue = t.callExpression(
t.identifier(cx.env.config.enableChangeDetection.wrappers.store),
@@ -716,9 +716,14 @@ function codegenReactiveScope(
t.identifier(cx.env.config.enableChangeDetection.wrappers.restore),
[t.identifier(loadNameStr)]
);
restoredRecomputed = t.callExpression(
t.identifier(cx.env.config.enableChangeDetection.wrappers.restore),
[genSlot()]
);
} else {
storedValue = value;
restoredValue = t.identifier(loadNameStr);
restoredRecomputed = genSlot();
}
cacheStoreStatements.push(
@@ -764,7 +769,7 @@ function codegenReactiveScope(
);
idempotenceDetectionStatements.push(
t.expressionStatement(
t.assignmentExpression("=", t.identifier(nameStr), genSlot())
t.assignmentExpression("=", t.identifier(nameStr), restoredRecomputed)
)
);
}