From 15336c5b0811795bd90a247cf35d1c4840f17334 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Mon, 23 Sep 2024 17:36:15 -0400 Subject: [PATCH] Update [ghstack-poisoned] --- .../src/HIR/CollectHoistablePropertyLoads.ts | 2 +- ...-try-catch-maybe-null-dependency.expect.md | 57 +++++++++++++++ .../bug-try-catch-maybe-null-dependency.ts | 18 +++++ .../try-catch-maybe-null-dependency.expect.md | 71 +++++++++++++++++++ .../try-catch-maybe-null-dependency.ts | 19 +++++ ...value-modified-in-catch-escaping.expect.md | 63 ---------------- ...ch-try-value-modified-in-catch-escaping.js | 20 ------ ...atch-try-value-modified-in-catch.expect.md | 69 ------------------ .../try-catch-try-value-modified-in-catch.js | 19 ----- .../packages/snap/src/SproutTodoFilter.ts | 1 + 10 files changed, 167 insertions(+), 172 deletions(-) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.ts create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts index 941c60dea9d4f..b6e9624c33158 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts @@ -258,7 +258,7 @@ function collectPropertyLoadsInBlocks( temporaries, ); const propertyNode = tree.getPropertyLoadNode(property); - const object = instr.value.object.identifier; + const object = propertyNode.fullPath.identifier; /** * Since this runs *after* buildReactiveScopeTerminals, identifier mutable ranges * are not valid with respect to current instruction id numbering. diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.expect.md new file mode 100644 index 0000000000000..ed2c4d7d3d293 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.expect.md @@ -0,0 +1,57 @@ + +## Input + +```javascript +import {identity} from 'shared-runtime'; + +function useFoo(maybeNullObject: {value: {inner: number}} | null) { + const y = []; + try { + y.push(identity(maybeNullObject.value.inner)); + } catch { + y.push('null'); + } + + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, {value: 2}, {value: 3}, null], +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; +import { identity } from "shared-runtime"; + +function useFoo(maybeNullObject) { + const $ = _c(2); + let y; + if ($[0] !== maybeNullObject.value.inner) { + y = []; + try { + y.push(identity(maybeNullObject.value.inner)); + } catch { + y.push("null"); + } + $[0] = maybeNullObject.value.inner; + $[1] = y; + } else { + y = $[1]; + } + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, { value: 2 }, { value: 3 }, null], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.ts b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.ts new file mode 100644 index 0000000000000..de7e2626f57b4 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-try-catch-maybe-null-dependency.ts @@ -0,0 +1,18 @@ +import {identity} from 'shared-runtime'; + +function useFoo(maybeNullObject: {value: {inner: number}} | null) { + const y = []; + try { + y.push(identity(maybeNullObject.value.inner)); + } catch { + y.push('null'); + } + + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, {value: 2}, {value: 3}, null], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md new file mode 100644 index 0000000000000..8674de709c3b0 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.expect.md @@ -0,0 +1,71 @@ + +## Input + +```javascript +// @enablePropagateDepsInHIR +import {identity} from 'shared-runtime'; + +function useFoo(maybeNullObject: {value: {inner: number}} | null) { + const y = []; + try { + y.push(identity(maybeNullObject.value.inner)); + } catch { + y.push('null'); + } + + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, {value: 2}, {value: 3}, null], +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR +import { identity } from "shared-runtime"; + +function useFoo(maybeNullObject) { + const $ = _c(4); + let y; + if ($[0] !== maybeNullObject) { + y = []; + try { + let t0; + if ($[2] !== maybeNullObject.value.inner) { + t0 = identity(maybeNullObject.value.inner); + $[2] = maybeNullObject.value.inner; + $[3] = t0; + } else { + t0 = $[3]; + } + y.push(t0); + } catch { + y.push("null"); + } + $[0] = maybeNullObject; + $[1] = y; + } else { + y = $[1]; + } + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, { value: 2 }, { value: 3 }, null], +}; + +``` + +### Eval output +(kind: ok) ["null"] +[null] +[null] +["null"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts new file mode 100644 index 0000000000000..58bf5943d5b1b --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-maybe-null-dependency.ts @@ -0,0 +1,19 @@ +// @enablePropagateDepsInHIR +import {identity} from 'shared-runtime'; + +function useFoo(maybeNullObject: {value: {inner: number}} | null) { + const y = []; + try { + y.push(identity(maybeNullObject.value.inner)); + } catch { + y.push('null'); + } + + return y; +} + +export const FIXTURE_ENTRYPOINT = { + fn: useFoo, + params: [null], + sequentialRenders: [null, {value: 2}, {value: 3}, null], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md deleted file mode 100644 index 914001f3737bd..0000000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md +++ /dev/null @@ -1,63 +0,0 @@ - -## Input - -```javascript -// @enablePropagateDepsInHIR -const {throwInput} = require('shared-runtime'); - -function Component(props) { - let x; - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (e) { - e.push(props.e); - x = e; - } - return x; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{y: 'foo', e: 'bar'}], -}; - -``` - -## Code - -```javascript -import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR -const { throwInput } = require("shared-runtime"); - -function Component(props) { - const $ = _c(2); - let x; - if ($[0] !== props) { - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (t0) { - const e = t0; - e.push(props.e); - x = e; - } - $[0] = props; - $[1] = x; - } else { - x = $[1]; - } - return x; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{ y: "foo", e: "bar" }], -}; - -``` - -### Eval output -(kind: ok) ["foo","bar"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js deleted file mode 100644 index 5a0864118ba8f..0000000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js +++ /dev/null @@ -1,20 +0,0 @@ -// @enablePropagateDepsInHIR -const {throwInput} = require('shared-runtime'); - -function Component(props) { - let x; - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (e) { - e.push(props.e); - x = e; - } - return x; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{y: 'foo', e: 'bar'}], -}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md deleted file mode 100644 index 30ecdf6d59e9d..0000000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md +++ /dev/null @@ -1,69 +0,0 @@ - -## Input - -```javascript -// @enablePropagateDepsInHIR -const {throwInput} = require('shared-runtime'); - -function Component(props) { - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (e) { - e.push(props.e); - return e; - } - return null; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{y: 'foo', e: 'bar'}], -}; - -``` - -## Code - -```javascript -import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR -const { throwInput } = require("shared-runtime"); - -function Component(props) { - const $ = _c(2); - let t0; - if ($[0] !== props) { - t0 = Symbol.for("react.early_return_sentinel"); - bb0: { - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (t1) { - const e = t1; - e.push(props.e); - t0 = e; - break bb0; - } - } - $[0] = props; - $[1] = t0; - } else { - t0 = $[1]; - } - if (t0 !== Symbol.for("react.early_return_sentinel")) { - return t0; - } - return null; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{ y: "foo", e: "bar" }], -}; - -``` - -### Eval output -(kind: ok) ["foo","bar"] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js deleted file mode 100644 index 97d650453c175..0000000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js +++ /dev/null @@ -1,19 +0,0 @@ -// @enablePropagateDepsInHIR -const {throwInput} = require('shared-runtime'); - -function Component(props) { - try { - const y = []; - y.push(props.y); - throwInput(y); - } catch (e) { - e.push(props.e); - return e; - } - return null; -} - -export const FIXTURE_ENTRYPOINT = { - fn: Component, - params: [{y: 'foo', e: 'bar'}], -}; diff --git a/compiler/packages/snap/src/SproutTodoFilter.ts b/compiler/packages/snap/src/SproutTodoFilter.ts index 7140cad2f74bc..823bac7efd8d2 100644 --- a/compiler/packages/snap/src/SproutTodoFilter.ts +++ b/compiler/packages/snap/src/SproutTodoFilter.ts @@ -478,6 +478,7 @@ const skipFilter = new Set([ 'fbt/bug-fbt-plural-multiple-function-calls', 'fbt/bug-fbt-plural-multiple-mixed-call-tag', 'bug-invalid-hoisting-functionexpr', + 'bug-try-catch-maybe-null-dependency', 'original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block', 'original-reactive-scopes-fork/bug-hoisted-declaration-with-scope', 'bug-codegen-inline-iife',