Skip to content

[compiler] Fix <ValidateMemoization> #33547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
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 @@ -23,14 +23,9 @@ function Component({a, b, c}: {a: number; b: number; c: number}) {

return (
<>
<ValidateMemoization inputs={[a, b, c]} output={x} alwaysCheck={true} />;
<ValidateMemoization inputs={[a, b, c]} output={x} />;
{/* TODO: should only depend on c */}
<ValidateMemoization
inputs={[a, b, c]}
output={x[0]}
alwaysCheck={true}
/>
;
<ValidateMemoization inputs={[a, b, c]} output={x[0]} />;
</>
);
}
Expand Down Expand Up @@ -98,7 +93,7 @@ function Component(t0) {
}
let t3;
if ($[9] !== t2 || $[10] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} alwaysCheck={true} />;
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[9] = t2;
$[10] = x;
$[11] = t3;
Expand All @@ -117,7 +112,7 @@ function Component(t0) {
}
let t5;
if ($[16] !== t4 || $[17] !== x[0]) {
t5 = <ValidateMemoization inputs={t4} output={x[0]} alwaysCheck={true} />;
t5 = <ValidateMemoization inputs={t4} output={x[0]} />;
$[16] = t4;
$[17] = x[0];
$[18] = t5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ function Component({a, b, c}: {a: number; b: number; c: number}) {

return (
<>
<ValidateMemoization inputs={[a, b, c]} output={x} alwaysCheck={true} />;
<ValidateMemoization inputs={[a, b, c]} output={x} />;
{/* TODO: should only depend on c */}
<ValidateMemoization
inputs={[a, b, c]}
output={x[0]}
alwaysCheck={true}
/>
;
<ValidateMemoization inputs={[a, b, c]} output={x[0]} />;
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Component({a, b}) {
typedMutate(z, b);

// TODO: this *should* only depend on `a`
return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down Expand Up @@ -86,7 +86,7 @@ function Component(t0) {
}
let t3;
if ($[7] !== t2 || $[8] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} alwaysCheck={true} />;
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[7] = t2;
$[8] = x;
$[9] = t3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Component({a, b}) {
typedMutate(z, b);

// TODO: this *should* only depend on `a`
return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function Component({a, b}) {

return (
<>
<ValidateMemoization inputs={[a]} output={o} alwaysCheck={true} />;
<ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
<ValidateMemoization inputs={[a]} output={o} />;
<ValidateMemoization inputs={[a, b]} output={x} />;
</>
);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ function Component(t0) {
}
let t5;
if ($[8] !== o || $[9] !== t4) {
t5 = <ValidateMemoization inputs={t4} output={o} alwaysCheck={true} />;
t5 = <ValidateMemoization inputs={t4} output={o} />;
$[8] = o;
$[9] = t4;
$[10] = t5;
Expand All @@ -110,7 +110,7 @@ function Component(t0) {
}
let t7;
if ($[14] !== t6 || $[15] !== x) {
t7 = <ValidateMemoization inputs={t6} output={x} alwaysCheck={true} />;
t7 = <ValidateMemoization inputs={t6} output={x} />;
$[14] = t6;
$[15] = x;
$[16] = t7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function Component({a, b}) {

return (
<>
<ValidateMemoization inputs={[a]} output={o} alwaysCheck={true} />;
<ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
<ValidateMemoization inputs={[a]} output={o} />;
<ValidateMemoization inputs={[a, b]} output={x} />;
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Component({a, b}: {a: number; b: number}) {
// mutates x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down Expand Up @@ -85,7 +85,7 @@ function Component(t0) {
}
let t3;
if ($[7] !== t2 || $[8] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} alwaysCheck={true} />;
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[7] = t2;
$[8] = x;
$[9] = t3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Component({a, b}: {a: number; b: number}) {
// mutates x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Component({a, b}: {a: number; b: number}) {
// mutates x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down Expand Up @@ -76,7 +76,7 @@ function Component(t0) {
}
let t3;
if ($[7] !== t2 || $[8] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} alwaysCheck={true} />;
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[7] = t2;
$[8] = x;
$[9] = t3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Component({a, b}: {a: number; b: number}) {
// mutates x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Component({a, b}) {
// does not mutate x, so x should not depend on b
typedMutate(z, b);

return <ValidateMemoization inputs={[a]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down Expand Up @@ -73,7 +73,7 @@ function Component(t0) {
}
let t4;
if ($[4] !== t3 || $[5] !== x) {
t4 = <ValidateMemoization inputs={t3} output={x} alwaysCheck={true} />;
t4 = <ValidateMemoization inputs={t3} output={x} />;
$[4] = t3;
$[5] = x;
$[6] = t4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Component({a, b}) {
// does not mutate x, so x should not depend on b
typedMutate(z, b);

return <ValidateMemoization inputs={[a]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Component({a, b}) {
// could mutate x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down Expand Up @@ -92,7 +92,7 @@ function Component(t0) {
}
let t4;
if ($[9] !== t3 || $[10] !== x) {
t4 = <ValidateMemoization inputs={t3} output={x} alwaysCheck={true} />;
t4 = <ValidateMemoization inputs={t3} output={x} />;
$[9] = t3;
$[10] = x;
$[11] = t4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Component({a, b}) {
// could mutate x
typedMutate(z, b);

return <ValidateMemoization inputs={[a, b]} output={x} alwaysCheck={true} />;
return <ValidateMemoization inputs={[a, b]} output={x} />;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
```javascript
// @enableNewMutationAliasingModel

import {useMemo} from 'react';
import {
identity,
makeObject_Primitives,
Expand All @@ -14,7 +15,7 @@ import {

function Component({a, b}) {
// create a mutable value with input `a`
const x = makeObject_Primitives(a);
const x = useMemo(() => makeObject_Primitives(a), [a]);

// freeze the value
useIdentity(x);
Expand Down Expand Up @@ -49,6 +50,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel

import { useMemo } from "react";
import {
identity,
makeObject_Primitives,
Expand All @@ -61,38 +63,40 @@ function Component(t0) {
const $ = _c(7);
const { a, b } = t0;
let t1;
let t2;
if ($[0] !== a) {
t1 = makeObject_Primitives(a);
t2 = makeObject_Primitives(a);
$[0] = a;
$[1] = t1;
$[1] = t2;
} else {
t1 = $[1];
t2 = $[1];
}
t1 = t2;
const x = t1;

useIdentity(x);

const x2 = typedIdentity(x);

identity(x2, b);
let t2;
let t3;
if ($[2] !== a) {
t2 = [a];
t3 = [a];
$[2] = a;
$[3] = t2;
$[3] = t3;
} else {
t2 = $[3];
t3 = $[3];
}
let t3;
if ($[4] !== t2 || $[5] !== x) {
t3 = <ValidateMemoization inputs={t2} output={x} />;
$[4] = t2;
let t4;
if ($[4] !== t3 || $[5] !== x) {
t4 = <ValidateMemoization inputs={t3} output={x} />;
$[4] = t3;
$[5] = x;
$[6] = t3;
$[6] = t4;
} else {
t3 = $[6];
t4 = $[6];
}
return t3;
return t4;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @enableNewMutationAliasingModel

import {useMemo} from 'react';
import {
identity,
makeObject_Primitives,
Expand All @@ -10,7 +11,7 @@ import {

function Component({a, b}) {
// create a mutable value with input `a`
const x = makeObject_Primitives(a);
const x = useMemo(() => makeObject_Primitives(a), [a]);

// freeze the value
useIdentity(x);
Expand Down
Loading
Loading