Promote enableTreatHooksAsFunctions to stable (remove flag)
Per title, this feature flag is enabled everywhere and is clearly stable, let's promote to stable and remove the flag to simplify.
Joe Savona committed
Oct 5, 2023 at 09:20 UTC
0b0f8994bab67691c3105fd283ba8041952d846a
7 files changed
+3
-45
compiler/apps/playground/components/Editor/index.tsx
-5
@@ -111,7 +111,6 @@ const COMMON_HOOKS: Array<[string, Hook]> = [
111
function parsePragma(pragma: string) {
112
let memoizeJsxElements = true;
113
let enableAssumeHooksFollowRulesOfReact = false;
114
- let enableTreatHooksAsFunctions = true;
114
let disableAllMemoization = false;
115
let validateRefAccessDuringRender = true;
116
let enableEmitFreeze = null;
@@ -127,9 +126,6 @@ function parsePragma(pragma: string) {
126
if (pragma.includes("@enableAssumeHooksFollowRulesOfReact true")) {
127
enableAssumeHooksFollowRulesOfReact = true;
128
}
130
- if (pragma.includes("@enableTreatHooksAsFunctions false")) {
131
- enableTreatHooksAsFunctions = false;
132
- }
129
if (pragma.includes("@disableAllMemoization true")) {
130
disableAllMemoization = true;
131
}
@@ -162,7 +158,6 @@ function parsePragma(pragma: string) {
158
enableAssumeHooksFollowRulesOfReact,
159
enableFunctionCallSignatureOptimizations,
160
disableAllMemoization,
165
- enableTreatHooksAsFunctions,
161
inlineUseMemo,
162
memoizeJsxElements,
163
validateHooksUsage,
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
-11
@@ -167,16 +167,6 @@ export type EnvironmentConfig = {
167
*/
168
enableAssumeHooksFollowRulesOfReact: boolean;
169
170
- /**
171
- * When enabled, the compiler treats hooks as normal typed functions for
172
- * type and effect inference.
173
- * Enabling this may change inference to have a higher confidence level
174
- * and create more bailouts (e.g. for mutable effects to immutable values).
175
- *
176
- * Defaults to true
177
- */
178
- enableTreatHooksAsFunctions: boolean;
179
-
170
/**
171
* When enabled, removes *all* memoization from the function: this includes
172
* removing manually added useMemo/useCallback as well as not adding Forget's
@@ -249,7 +239,6 @@ export type EnvironmentConfig = {
239
const DEFAULT_ENVIRONMENT_CONFIG: Readonly<EnvironmentConfig> = {
240
customHooks: null,
241
252
- enableTreatHooksAsFunctions: true,
242
memoizeJsxElements: true,
243
enableFunctionCallSignatureOptimizations: true,
244
inlineUseMemo: true,
compiler/packages/babel-plugin-react-forget/src/HIR/Globals.ts
+3
-2
@@ -232,8 +232,9 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
232
// TODO: rest of Global objects
233
];
234
235
-// TODO(mofeiZ): We currently only store rest param effects for hooks
236
-// until FeatureFlag `enableTreatHooksAsFunctions` is removed
235
+// TODO(mofeiZ): We currently only store rest param effects for hooks.
236
+// now that FeatureFlag `enableTreatHooksAsFunctions` is removed we can
237
+// use positional params too (?)
238
const BUILTIN_HOOKS: Array<[string, BuiltInType]> = [
239
[
240
"useContext",
compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
-10
@@ -752,16 +752,6 @@ function inferBlock(
752
? signature
753
: null;
754
755
- if (
756
- signature &&
757
- signature.hookKind != null &&
758
- !env.config.enableTreatHooksAsFunctions
759
- ) {
760
- effectKind = signature.restParam;
761
- valueKind = signature.returnValueKind;
762
- break;
763
- }
764
-
755
const effects =
756
signature !== null ? getFunctionEffects(instrValue, signature) : null;
757
const returnValueKind =
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/unknown-hooks-do-not-assert.expect.md
-8
@@ -4,10 +4,6 @@
4
```javascript
5
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
6
// to an immutable value. This should not apply to unknown / untyped hooks.
7
-
8
-// Default feature flags:
9
-// enableAssumeHooksFollowRulesOfReact=false
10
-// enableTreatHooksAsFunctions=true
7
function Component(props) {
8
const x = useUnknownHook1(props);
9
const y = useUnknownHook2(x);
@@ -21,10 +17,6 @@ function Component(props) {
17
```javascript
18
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
19
// to an immutable value. This should not apply to unknown / untyped hooks.
24
-
25
-// Default feature flags:
26
-// enableAssumeHooksFollowRulesOfReact=false
27
-// enableTreatHooksAsFunctions=true
20
function Component(props) {
21
const x = useUnknownHook1(props);
22
const y = useUnknownHook2(x);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/unknown-hooks-do-not-assert.js
-4
@@ -1,9 +1,5 @@
1
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
2
// to an immutable value. This should not apply to unknown / untyped hooks.
3
-
4
-// Default feature flags:
5
-// enableAssumeHooksFollowRulesOfReact=false
6
-// enableTreatHooksAsFunctions=true
3
function Component(props) {
4
const x = useUnknownHook1(props);
5
const y = useUnknownHook2(x);
compiler/packages/fixture-test-utils/src/compiler-utils.ts
-5
@@ -21,7 +21,6 @@ export function transformFixtureInput(
21
let instrumentForget = null;
22
let memoizeJsxElements = true;
23
let enableAssumeHooksFollowRulesOfReact = false;
24
- let enableTreatHooksAsFunctions = true;
24
let disableAllMemoization = false;
25
let validateRefAccessDuringRender = true;
26
let validateNoSetStateInRender = true;
@@ -64,9 +63,6 @@ export function transformFixtureInput(
63
if (firstLine.includes("@enableAssumeHooksFollowRulesOfReact true")) {
64
enableAssumeHooksFollowRulesOfReact = true;
65
}
67
- if (firstLine.includes("@enableTreatHooksAsFunctions false")) {
68
- enableTreatHooksAsFunctions = false;
69
- }
66
if (firstLine.includes("@disableAllMemoization true")) {
67
disableAllMemoization = true;
68
}
@@ -130,7 +126,6 @@ export function transformFixtureInput(
126
]),
127
enableAssumeHooksFollowRulesOfReact,
128
disableAllMemoization,
133
- enableTreatHooksAsFunctions,
129
memoizeJsxElements,
130
validateRefAccessDuringRender,
131
validateFrozenLambdas: true,