From bf859705b55a8ccaedbed8546cd4d9c6c003bf62 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 20 Dec 2023 13:52:43 -0800 Subject: [PATCH] Enable early return support by default This PR enables the new feature flag by default, but keeps the flag around so that we can quickly turn it off if there are issues. --- .../babel-plugin-react-forget/src/HIR/Environment.ts | 4 ++-- .../fixtures/compiler/conditional-early-return.expect.md | 5 +---- .../__tests__/fixtures/compiler/conditional-early-return.js | 2 -- ...eturn-nested-early-return-within-reactive-scope.expect.md | 3 +-- ...early-return-nested-early-return-within-reactive-scope.js | 1 - ...turn-no-declarations-reassignments-dependencies.expect.md | 3 +-- ...arly-return-no-declarations-reassignments-dependencies.js | 1 - .../compiler/early-return-within-reactive-scope.expect.md | 3 +-- .../fixtures/compiler/early-return-within-reactive-scope.js | 1 - ...arly-return--early-return-within-reactive-scope.expect.md | 3 ++- ....todo-early-return--early-return-within-reactive-scope.js | 1 + .../partial-early-return-within-reactive-scope.expect.md | 3 +-- .../compiler/partial-early-return-within-reactive-scope.js | 1 - .../compiler/try-catch-try-value-modified-in-catch.expect.md | 3 +-- .../compiler/try-catch-try-value-modified-in-catch.js | 1 - .../fixtures/compiler/try-catch-with-catch-param.expect.md | 3 +-- .../fixtures/compiler/try-catch-with-catch-param.js | 1 - .../fixtures/compiler/try-catch-with-return.expect.md | 3 +-- .../src/__tests__/fixtures/compiler/try-catch-with-return.js | 1 - 19 files changed, 13 insertions(+), 30 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts index b3c2d25001..05a0688836 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts @@ -280,10 +280,10 @@ const EnvironmentConfigSchema = z.object({ * This is relatively infrequent, as reactive scopes generally span * up to but excluding return statements. * - * When disabled (default), the compiler will skip any functions which + * When disabled, the compiler will error (bailout) on any functions which * would create a reactive scope that contains a return statement. */ - enableEarlyReturnInReactiveScopes: z.boolean().default(false), + enableEarlyReturnInReactiveScopes: z.boolean().default(true), // Enable validation of mutable ranges assertValidMutableRanges: z.boolean().default(false), diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md index 6a8f8f4bdf..29074d3508 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.expect.md @@ -2,8 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes - /** * props.b does *not* influence `a` */ @@ -68,8 +66,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes - +import { unstable_useMemoCache as useMemoCache } from "react"; /** * props.b does *not* influence `a` */ diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js index 9e258845f1..d0b335bb38 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/conditional-early-return.js @@ -1,5 +1,3 @@ -// @enableEarlyReturnInReactiveScopes - /** * props.b does *not* influence `a` */ diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md index 9e4990bcea..5a6ced61b7 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes function Component(props) { let x = []; if (props.cond) { @@ -30,7 +29,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; function Component(props) { const $ = useMemoCache(5); let t53; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js index 4cd7798482..9f5b357bf9 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-nested-early-return-within-reactive-scope.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes function Component(props) { let x = []; if (props.cond) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.expect.md index a607f36850..605eef8484 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes import { makeArray } from "shared-runtime"; /** @@ -51,7 +50,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; import { makeArray } from "shared-runtime"; /** diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.js index 891dc27e7b..f0a4b49f6a 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-no-declarations-reassignments-dependencies.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes import { makeArray } from "shared-runtime"; /** diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md index e0ac96cab5..1996b38494 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes import { makeArray } from "shared-runtime"; function Component(props) { @@ -42,7 +41,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; import { makeArray } from "shared-runtime"; function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js index 3d9a6d6bd0..4a9d1ab909 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/early-return-within-reactive-scope.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes import { makeArray } from "shared-runtime"; function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md index b38723ae01..feba5c887f 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.expect.md @@ -2,6 +2,7 @@ ## Input ```javascript +// @enableEarlyReturnInReactiveScopes:false function Component(props) { let x = []; if (props.cond) { @@ -24,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = { ## Error ``` -[ReactForget] Todo: Support early return within a reactive scope (6:6) +[ReactForget] Todo: Support early return within a reactive scope (7:7) ``` \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js index 36d690edbb..df07294a59 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-early-return--early-return-within-reactive-scope.js @@ -1,3 +1,4 @@ +// @enableEarlyReturnInReactiveScopes:false function Component(props) { let x = []; if (props.cond) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md index 7d6898430e..c4f26fe8f7 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes function Component(props) { let x = []; let y = null; @@ -29,7 +28,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; function Component(props) { const $ = useMemoCache(4); let y; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js index 28f09a4e28..9739a2a8de 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/partial-early-return-within-reactive-scope.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes function Component(props) { let x = []; let y = null; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md index 37ff7f4cfd..022605becd 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes const { throwInput } = require("shared-runtime"); function Component(props) { @@ -27,7 +26,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; const { throwInput } = require("shared-runtime"); function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js index a4cc0bcc95..578b9a0897 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-try-value-modified-in-catch.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes const { throwInput } = require("shared-runtime"); function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md index 59fb64afec..a067460741 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes const { throwInput } = require("shared-runtime"); function Component(props) { @@ -28,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; const { throwInput } = require("shared-runtime"); function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js index b6b9ac523a..9508694f96 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-catch-param.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes const { throwInput } = require("shared-runtime"); function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md index 07bbbf1363..e27d9fe584 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.expect.md @@ -2,7 +2,6 @@ ## Input ```javascript -// @enableEarlyReturnInReactiveScopes const { shallowCopy, throwInput } = require("shared-runtime"); function Component(props) { @@ -29,7 +28,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableEarlyReturnInReactiveScopes +import { unstable_useMemoCache as useMemoCache } from "react"; const { shallowCopy, throwInput } = require("shared-runtime"); function Component(props) { diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js index 3943af6cbc..640cb1ba1f 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/try-catch-with-return.js @@ -1,4 +1,3 @@ -// @enableEarlyReturnInReactiveScopes const { shallowCopy, throwInput } = require("shared-runtime"); function Component(props) {