From f6dcce5199a3b9480a47d9feda8e00d8d9a0905d Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Thu, 12 Sep 2024 16:59:39 -0400 Subject: [PATCH] [compiler][ez] Add entrypoints to ssa fixtures Adds evaluator support for a few compiler test fixtures ghstack-source-id: 202654992a9876cea59885b54a338c908e369ddb Pull Request resolved: https://github.com/facebook/react/pull/30948 --- ...re-in-method-receiver-and-mutate.expect.md | 2 +- ...opes-reactive-scope-overlaps-try.expect.md | 6 +-- .../ssa-cascading-eliminated-phis.expect.md | 25 ++++++++--- .../compiler/ssa-cascading-eliminated-phis.js | 9 +++- .../compiler/ssa-leave-case.expect.md | 41 ++++++++++++++++--- .../fixtures/compiler/ssa-leave-case.js | 17 +++++++- ...ernary-destruction-with-mutation.expect.md | 38 ++++++++++++++--- ...aming-ternary-destruction-with-mutation.js | 16 +++++++- ...ssa-renaming-ternary-destruction.expect.md | 30 ++++++++++---- .../ssa-renaming-ternary-destruction.js | 12 ++++-- ...a-renaming-ternary-with-mutation.expect.md | 38 ++++++++++++++--- .../ssa-renaming-ternary-with-mutation.js | 16 +++++++- .../compiler/ssa-renaming-ternary.expect.md | 30 ++++++++++---- .../fixtures/compiler/ssa-renaming-ternary.js | 12 ++++-- ...onditional-ternary-with-mutation.expect.md | 8 ++-- ...ing-unconditional-ternary-with-mutation.js | 4 +- ...a-renaming-unconditional-ternary.expect.md | 30 ++++++++++---- .../ssa-renaming-unconditional-ternary.js | 12 ++++-- ...ming-unconditional-with-mutation.expect.md | 38 ++++++++++++++--- ...sa-renaming-unconditional-with-mutation.js | 16 +++++++- ...-via-destructuring-with-mutation.expect.md | 38 ++++++++++++++--- ...enaming-via-destructuring-with-mutation.js | 16 +++++++- .../ssa-renaming-with-mutation.expect.md | 38 ++++++++++++++--- .../compiler/ssa-renaming-with-mutation.js | 16 +++++++- ...pendency-is-pruned-as-dependency.expect.md | 2 +- .../packages/snap/src/SproutTodoFilter.ts | 10 ----- .../snap/src/sprout/shared-runtime.ts | 2 + 27 files changed, 413 insertions(+), 109 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md index ee8e4f0d3670a..0b03ac9978951 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md @@ -57,4 +57,4 @@ export const FIXTURE_ENTRYPOINT = { ``` ### Eval output -(kind: ok) [[{"a":0,"b":"value1","c":true}],"[[ cyclic ref *2 ]]"] \ No newline at end of file +(kind: ok) [[{"a":0,"b":"value1","c":true},"joe"],"[[ cyclic ref *2 ]]"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-try.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-try.expect.md index 6d55ba736486a..1bc6b9b51ebf6 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-try.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-try.expect.md @@ -60,6 +60,6 @@ export const FIXTURE_ENTRYPOINT = { ``` ### Eval output -(kind: ok) [2] -[2] -[3] \ No newline at end of file +(kind: ok) [2,"joe"] +[2,"joe"] +[3,"joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md index cd123dbdba56e..6af0cf0af7bca 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md @@ -20,8 +20,13 @@ function Component(props) { export const FIXTURE_ENTRYPOINT = { fn: Component, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + params: [{a: 0, b: 1, c: true, d: true}], + sequentialRenders: [ + {a: 0, b: 1, c: true, d: true}, + {a: 4, b: 1, c: true, d: true}, + {a: 4, b: 1, c: false, d: true}, + {a: 4, b: 1, c: false, d: false}, + ], }; ``` @@ -61,9 +66,19 @@ function Component(props) { export const FIXTURE_ENTRYPOINT = { fn: Component, - params: ["TodoAdd"], - isComponent: "TodoAdd", + params: [{ a: 0, b: 1, c: true, d: true }], + sequentialRenders: [ + { a: 0, b: 1, c: true, d: true }, + { a: 4, b: 1, c: true, d: true }, + { a: 4, b: 1, c: false, d: true }, + { a: 4, b: 1, c: false, d: false }, + ], }; ``` - \ No newline at end of file + +### Eval output +(kind: ok) [1,1,2] +[4,1,2] +[4,0,2] +[4,0,0] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.js index 53f30fa7aae93..8d5a4e2ee91e1 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.js @@ -16,6 +16,11 @@ function Component(props) { export const FIXTURE_ENTRYPOINT = { fn: Component, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + params: [{a: 0, b: 1, c: true, d: true}], + sequentialRenders: [ + {a: 0, b: 1, c: true, d: true}, + {a: 4, b: 1, c: true, d: true}, + {a: 4, b: 1, c: false, d: true}, + {a: 4, b: 1, c: false, d: false}, + ], }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.expect.md index a7389041bb12d..a10ad5fae4108 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.expect.md @@ -2,6 +2,8 @@ ## Input ```javascript +import {Stringify} from 'shared-runtime'; + function Component(props) { let x = []; let y; @@ -10,19 +12,32 @@ function Component(props) { y = x; } return ( - + {x} {y} - + ); } +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{p0: false, p1: 2}], + sequentialRenders: [ + {p0: false, p1: 2}, + {p0: false, p1: 2}, + {p0: true, p1: 2}, + {p0: true, p1: 3}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; +import { Stringify } from "shared-runtime"; + function Component(props) { const $ = _c(2); let t0; @@ -35,10 +50,10 @@ function Component(props) { } t0 = ( - + {x} {y} - + ); $[0] = props; $[1] = t0; @@ -48,5 +63,21 @@ function Component(props) { return t0; } +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ p0: false, p1: 2 }], + sequentialRenders: [ + { p0: false, p1: 2 }, + { p0: false, p1: 2 }, + { p0: true, p1: 2 }, + { p0: true, p1: 3 }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
{"children":[[],null]}
+
{"children":[[],null]}
+
{"children":[[2],"[[ cyclic ref *2 ]]"]}
+
{"children":[[3],"[[ cyclic ref *2 ]]"]}
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.js index fce3a15209d6e..54d489225797d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.js @@ -1,3 +1,5 @@ +import {Stringify} from 'shared-runtime'; + function Component(props) { let x = []; let y; @@ -6,9 +8,20 @@ function Component(props) { y = x; } return ( - + {x} {y} - + ); } + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{p0: false, p1: 2}], + sequentialRenders: [ + {p0: false, p1: 2}, + {p0: false, p1: 2}, + {p0: true, p1: 2}, + {p0: true, p1: 3}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md index 9ce43a45b4c22..3e7fd4bf5f859 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md @@ -2,28 +2,42 @@ ## Input ```javascript -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null; - mut(x); + mutate(x); return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +import { mutate } from "shared-runtime"; + +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { x = []; x.push(props.bar); props.cond ? (([x] = [[]]), x.push(props.foo)) : null; - mut(x); + mutate(x); $[0] = props; $[1] = x; } else { @@ -32,5 +46,19 @@ function foo(props) { return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{ cond: false, foo: 2, bar: 55 }], + sequentialRenders: [ + { cond: false, foo: 2, bar: 55 }, + { cond: false, foo: 3, bar: 55 }, + { cond: true, foo: 3, bar: 55 }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok) [55,"joe"] +[55,"joe"] +[3,"joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js index 4d4f4381ca6f0..4f7e4163e3962 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js @@ -1,7 +1,19 @@ -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null; - mut(x); + mutate(x); return x; } + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md index e20dc2606fa37..9b3aad524ce14 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md @@ -2,7 +2,7 @@ ## Input ```javascript -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null; @@ -10,9 +10,13 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; ``` @@ -21,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +function useFoo(props) { const $ = _c(4); let x; if ($[0] !== props.bar) { @@ -43,10 +47,18 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ["TodoAdd"], - isComponent: "TodoAdd", + fn: useFoo, + params: [{ cond: false, foo: 2, bar: 55 }], + sequentialRenders: [ + { cond: false, foo: 2, bar: 55 }, + { cond: false, foo: 3, bar: 55 }, + { cond: true, foo: 3, bar: 55 }, + ], }; ``` - \ No newline at end of file + +### Eval output +(kind: ok) [55] +[55] +[3] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js index ce21e08292d70..3d2f7f86e48dc 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js @@ -1,4 +1,4 @@ -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null; @@ -6,7 +6,11 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md index 3ec90ca8879bc..de9466c4daa9d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md @@ -2,28 +2,42 @@ ## Input ```javascript -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - mut(x); + mutate(x); return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +import { mutate } from "shared-runtime"; + +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { x = []; x.push(props.bar); props.cond ? ((x = []), x.push(props.foo)) : null; - mut(x); + mutate(x); $[0] = props; $[1] = x; } else { @@ -32,5 +46,19 @@ function foo(props) { return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{ cond: false, foo: 2, bar: 55 }], + sequentialRenders: [ + { cond: false, foo: 2, bar: 55 }, + { cond: false, foo: 3, bar: 55 }, + { cond: true, foo: 3, bar: 55 }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok) [55,"joe"] +[55,"joe"] +[3,"joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js index 5dde2fea8c0df..7016a5bf07ebd 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js @@ -1,7 +1,19 @@ -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - mut(x); + mutate(x); return x; } + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md index 1b9453341153b..e199863257bfe 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md @@ -2,7 +2,7 @@ ## Input ```javascript -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; @@ -10,9 +10,13 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; ``` @@ -21,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +function useFoo(props) { const $ = _c(4); let x; if ($[0] !== props.bar) { @@ -43,10 +47,18 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ["TodoAdd"], - isComponent: "TodoAdd", + fn: useFoo, + params: [{ cond: false, foo: 2, bar: 55 }], + sequentialRenders: [ + { cond: false, foo: 2, bar: 55 }, + { cond: false, foo: 3, bar: 55 }, + { cond: true, foo: 3, bar: 55 }, + ], }; ``` - \ No newline at end of file + +### Eval output +(kind: ok) [55] +[55] +[3] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js index 407efdbcc0e3d..6057fcbb35c6f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js @@ -1,4 +1,4 @@ -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; @@ -6,7 +6,11 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md index bd77cc9c173a0..16981f69cda90 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md @@ -3,7 +3,7 @@ ```javascript import {arrayPush} from 'shared-runtime'; -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond @@ -14,7 +14,7 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, + fn: useFoo, params: [{cond: false, foo: 2, bar: 55}], sequentialRenders: [ {cond: false, foo: 2, bar: 55}, @@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; import { arrayPush } from "shared-runtime"; -function foo(props) { +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { @@ -47,7 +47,7 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, + fn: useFoo, params: [{ cond: false, foo: 2, bar: 55 }], sequentialRenders: [ { cond: false, foo: 2, bar: 55 }, diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js index d37e4736a5189..c2829b33e6e26 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js @@ -1,5 +1,5 @@ import {arrayPush} from 'shared-runtime'; -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond @@ -10,7 +10,7 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, + fn: useFoo, params: [{cond: false, foo: 2, bar: 55}], sequentialRenders: [ {cond: false, foo: 2, bar: 55}, diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md index b518df5ab8e8f..99b50ac231342 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md @@ -2,7 +2,7 @@ ## Input ```javascript -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond @@ -12,9 +12,13 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; ``` @@ -23,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +function useFoo(props) { const $ = _c(4); let x; if ($[0] !== props.bar) { @@ -45,10 +49,18 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ["TodoAdd"], - isComponent: "TodoAdd", + fn: useFoo, + params: [{ cond: false, foo: 2, bar: 55 }], + sequentialRenders: [ + { cond: false, foo: 2, bar: 55 }, + { cond: false, foo: 3, bar: 55 }, + { cond: true, foo: 3, bar: 55 }, + ], }; ``` - \ No newline at end of file + +### Eval output +(kind: ok) [55] +[55] +[3] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js index 3cf63f389d3be..7e34aa5683f5c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js @@ -1,4 +1,4 @@ -function foo(props) { +function useFoo(props) { let x = []; x.push(props.bar); props.cond @@ -8,7 +8,11 @@ function foo(props) { } export const FIXTURE_ENTRYPOINT = { - fn: foo, - params: ['TodoAdd'], - isComponent: 'TodoAdd', + fn: useFoo, + params: [{cond: false, foo: 2, bar: 55}], + sequentialRenders: [ + {cond: false, foo: 2, bar: 55}, + {cond: false, foo: 3, bar: 55}, + {cond: true, foo: 3, bar: 55}, + ], }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md index e27e00db70f05..f4689e5795552 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md @@ -2,7 +2,9 @@ ## Input ```javascript -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); if (props.cond) { @@ -14,17 +16,29 @@ function foo(props) { x = []; x.push(props.bar); } - mut(x); + mutate(x); return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +import { mutate } from "shared-runtime"; + +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { @@ -38,7 +52,7 @@ function foo(props) { x.push(props.bar); } - mut(x); + mutate(x); $[0] = props; $[1] = x; } else { @@ -47,5 +61,19 @@ function foo(props) { return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{ bar: "bar", foo: "foo", cond: true }], + sequentialRenders: [ + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: false }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok) ["foo","joe"] +["foo","joe"] +["bar","joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.js index f5d09dbf30d10..3e7078cfc7999 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.js @@ -1,4 +1,6 @@ -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); if (props.cond) { @@ -10,6 +12,16 @@ function foo(props) { x = []; x.push(props.bar); } - mut(x); + mutate(x); return x; } + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md index 7ad946b2f494f..ed1056c47c0f8 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md @@ -2,7 +2,9 @@ ## Input ```javascript -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let {x} = {x: []}; x.push(props.bar); if (props.cond) { @@ -10,17 +12,29 @@ function foo(props) { ({x} = {x: []}); x.push(props.foo); } - mut(x); + mutate(x); return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +import { mutate } from "shared-runtime"; + +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { @@ -31,7 +45,7 @@ function foo(props) { x.push(props.foo); } - mut(x); + mutate(x); $[0] = props; $[1] = x; } else { @@ -40,5 +54,19 @@ function foo(props) { return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{ bar: "bar", foo: "foo", cond: true }], + sequentialRenders: [ + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: false }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok) ["foo","joe"] +["foo","joe"] +["bar","joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.js index 303a9f92743c8..a72e15eebaf18 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.js @@ -1,4 +1,6 @@ -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let {x} = {x: []}; x.push(props.bar); if (props.cond) { @@ -6,6 +8,16 @@ function foo(props) { ({x} = {x: []}); x.push(props.foo); } - mut(x); + mutate(x); return x; } + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md index 76ccbae06a937..26cd73a82b53f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md @@ -2,7 +2,9 @@ ## Input ```javascript -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); if (props.cond) { @@ -10,17 +12,29 @@ function foo(props) { x = []; x.push(props.foo); } - mut(x); + mutate(x); return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; + ``` ## Code ```javascript import { c as _c } from "react/compiler-runtime"; -function foo(props) { +import { mutate } from "shared-runtime"; + +function useFoo(props) { const $ = _c(2); let x; if ($[0] !== props) { @@ -31,7 +45,7 @@ function foo(props) { x.push(props.foo); } - mut(x); + mutate(x); $[0] = props; $[1] = x; } else { @@ -40,5 +54,19 @@ function foo(props) { return x; } +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{ bar: "bar", foo: "foo", cond: true }], + sequentialRenders: [ + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: true }, + { bar: "bar", foo: "foo", cond: false }, + ], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok) ["foo","joe"] +["foo","joe"] +["bar","joe"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.js index 30f71933538ef..a4d22684f2440 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.js @@ -1,4 +1,6 @@ -function foo(props) { +import {mutate} from 'shared-runtime'; + +function useFoo(props) { let x = []; x.push(props.bar); if (props.cond) { @@ -6,6 +8,16 @@ function foo(props) { x = []; x.push(props.foo); } - mut(x); + mutate(x); return x; } + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [{bar: 'bar', foo: 'foo', cond: true}], + sequentialRenders: [ + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: true}, + {bar: 'bar', foo: 'foo', cond: false}, + ], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md index 05b86335272e5..72b0eeda8480f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md @@ -42,4 +42,4 @@ export const FIXTURE_ENTRYPOINT = { ``` ### Eval output -(kind: ok)
\ No newline at end of file +(kind: ok)
joe
\ No newline at end of file diff --git a/compiler/packages/snap/src/SproutTodoFilter.ts b/compiler/packages/snap/src/SproutTodoFilter.ts index 2d875430263c2..7d7476dc74739 100644 --- a/compiler/packages/snap/src/SproutTodoFilter.ts +++ b/compiler/packages/snap/src/SproutTodoFilter.ts @@ -134,7 +134,6 @@ const skipFilter = new Set([ 'same-variable-as-dep-and-redeclare', 'simple-scope', 'ssa-arrayexpression', - 'ssa-cascading-eliminated-phis', 'ssa-for-of', 'ssa-multiple-phis', 'ssa-nested-loops-no-reassign', @@ -144,9 +143,6 @@ const skipFilter = new Set([ 'ssa-objectexpression', 'ssa-property-alias-if', 'ssa-reassign', - 'ssa-renaming-ternary-destruction', - 'ssa-renaming-ternary', - 'ssa-renaming-unconditional-ternary', 'ssa-renaming-via-destructuring', 'ssa-renaming', 'ssa-sibling-phis', @@ -325,15 +321,9 @@ const skipFilter = new Set([ 'repro-scope-missing-mutable-range', 'repro', 'simple', - 'ssa-leave-case', 'ssa-property-alias-alias-mutate-if', 'ssa-property-alias-mutate-if', 'ssa-property-alias-mutate-inside-if', - 'ssa-renaming-ternary-destruction-with-mutation', - 'ssa-renaming-ternary-with-mutation', - 'ssa-renaming-unconditional-with-mutation', - 'ssa-renaming-via-destructuring-with-mutation', - 'ssa-renaming-with-mutation', 'switch-global-propertyload-case-test', 'switch-non-final-default', 'switch', diff --git a/compiler/packages/snap/src/sprout/shared-runtime.ts b/compiler/packages/snap/src/sprout/shared-runtime.ts index bb1c65a6574ac..4426982ec78f9 100644 --- a/compiler/packages/snap/src/sprout/shared-runtime.ts +++ b/compiler/packages/snap/src/sprout/shared-runtime.ts @@ -54,6 +54,8 @@ export function mutate(arg: any): void { // don't mutate primitive if (arg == null || typeof arg !== 'object') { return; + } else if (Array.isArray(arg)) { + arg.push('joe'); } let count: number = 0;