[compiler] Drop useMemos in memoization disabled mode, don't bail from source-level memo blocks

[ghstack-poisoned]
This commit is contained in:
Mike Vitousek
2024-06-30 23:51:27 -07:00
parent 25835c3bca
commit f046ce99db
4 changed files with 17 additions and 24 deletions
@@ -154,11 +154,7 @@ function* runWithEnvironment(
validateContextVariableLValues(hir);
validateUseMemo(hir);
if (
env.config.enablePreserveExistingManualUseMemo !== "hook" &&
!env.config.disableMemoizationForDebugging &&
!env.config.enableChangeDetectionForDebugging
) {
if (env.config.enablePreserveExistingManualUseMemo !== "hook") {
dropManualMemoization(hir);
yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
}
@@ -336,7 +336,9 @@ export function dropManualMemoization(func: HIRFunction): void {
const isValidationEnabled =
func.env.config.enablePreserveExistingManualUseMemo === "scope" ||
func.env.config.validatePreserveExistingMemoizationGuarantees ||
func.env.config.enablePreserveExistingMemoizationGuarantees;
func.env.config.enablePreserveExistingMemoizationGuarantees ||
func.env.config.enableChangeDetectionForDebugging ||
func.env.config.disableMemoizationForDebugging;
const sidemap: IdentifierSidemap = {
functions: new Map(),
manualMemos: new Map(),
@@ -622,7 +622,7 @@ function codegenReactiveScope(
);
}
if (cx.env.config.disableMemoizationForDebugging) {
if (cx.env.config.disableMemoizationForDebugging && !scope.source) {
CompilerError.invariant(
cx.env.config.enableChangeDetectionForDebugging == null,
{
@@ -25,31 +25,26 @@ import { c as _c } from "react/compiler-runtime"; // @disableMemoizationForDebug
import { useMemo } from "react";
function Component(t0) {
const $ = _c(5);
const $ = _c(4);
const { a } = t0;
let t1;
if ($[0] !== a || true) {
t1 = () => [a];
$[0] = a;
$[1] = t1;
} else {
t1 = $[1];
}
let t2;
if ($[2] === Symbol.for("react.memo_cache_sentinel") || true) {
t2 = [];
$[2] = t2;
if ($[0] !== a || true) {
t2 = [a];
$[0] = a;
$[1] = t2;
} else {
t2 = $[2];
t2 = $[1];
}
const x = useMemo(t1, t2);
t1 = t2;
const x = t1;
let t3;
if ($[3] !== x || true) {
if ($[2] !== x || true) {
t3 = <div>{x}</div>;
$[3] = x;
$[4] = t3;
$[2] = x;
$[3] = t3;
} else {
t3 = $[4];
t3 = $[3];
}
return t3;
}