@samitouri / QOS-React / commits / ecc730c587

[FeatureFlag] Toggle enableTreatHooksAsFunctions default to true

--- Toggle default to true, since this should be a no-op refactor. Tests: - test fixtures - ran on Store + - and saw no difference in compiled output - [diff](P744101621) with `enableTreatHooksAsFunctions=false` - [diff](P744105565) with `enableTreatHooksAsFunctions=true`

Mofei Zhang committed May 23, 2023 at 16:11 UTC ecc730c58713695143f825b3d2c4ec2ea93fc435
5 files changed +26 -14
compiler/forget/packages/snap/src/compiler-worker.ts
+3 -3
@@ -94,7 +94,7 @@ export async function compile(
94 let panicOnBailout = true;
95 let memoizeJsxElements = true;
96 let enableAssumeHooksFollowRulesOfReact = false;
97 - let enableTreatHooksAsFunctions = false;
97 + let enableTreatHooksAsFunctions = true;
98 if (firstLine.indexOf("@forgetDirective") !== -1) {
99 enableOnlyOnUseForgetDirective = true;
100 }
@@ -125,8 +125,8 @@ export async function compile(
125 if (firstLine.indexOf("@enableAssumeHooksFollowRulesOfReact true") !== -1) {
126 enableAssumeHooksFollowRulesOfReact = true;
127 }
128 - if (firstLine.indexOf("@enableTreatHooksAsFunctions true") !== -1) {
129 - enableTreatHooksAsFunctions = true;
128 + if (firstLine.indexOf("@enableTreatHooksAsFunctions false") !== -1) {
129 + enableTreatHooksAsFunctions = false;
130 }
131
132 const language = parseLanguage(firstLine);
compiler/forget/src/HIR/Environment.ts
+2 -2
@@ -99,7 +99,7 @@ export type EnvironmentConfig = Partial<{
99 * Enabling this may change inference to have a higher confidence level
100 * and create more bailouts (e.g. for mutable effects to immutable values).
101 *
102 - * Defaults to false
102 + * Defaults to true
103 */
104 enableTreatHooksAsFunctions: boolean;
105 }>;
@@ -149,7 +149,7 @@ export class Environment {
149 this.enableAssumeHooksFollowRulesOfReact =
150 config?.enableAssumeHooksFollowRulesOfReact ?? false;
151 this.enableTreatHooksAsFunctions =
152 - config?.enableTreatHooksAsFunctions ?? false;
152 + config?.enableTreatHooksAsFunctions ?? true;
153 this.#contextIdentifiers = contextIdentifiers;
154 }
155
compiler/forget/src/__tests__/fixtures/compiler/unknown-hooks-do-not-assert.expect.md
+12 -4
@@ -2,8 +2,12 @@
2 ## Input
3
4 ```javascript
5 -// @enableTreatHooksAsFunctions true
6 -// (enableAssumeHooksFollowRulesOfReact=false)
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
11 function Component(props) {
12 const x = useUnknownHook1(props);
13 const y = useUnknownHook2(x);
@@ -15,8 +19,12 @@ function Component(props) {
19 ## Code
20
21 ```javascript
18 -// @enableTreatHooksAsFunctions true
19 -// (enableAssumeHooksFollowRulesOfReact=false)
22 +// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
23 +// to an immutable value. This should not apply to unknown / untyped hooks.
24 +
25 +// Default feature flags:
26 +// enableAssumeHooksFollowRulesOfReact=false
27 +// enableTreatHooksAsFunctions=true
28 function Component(props) {
29 const x = useUnknownHook1(props);
30 const y = useUnknownHook2(x);
compiler/forget/src/__tests__/fixtures/compiler/unknown-hooks-do-not-assert.js
+6 -2
@@ -1,5 +1,9 @@
1 -// @enableTreatHooksAsFunctions true
2 -// (enableAssumeHooksFollowRulesOfReact=false)
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
7 function Component(props) {
8 const x = useUnknownHook1(props);
9 const y = useUnknownHook2(x);
compiler/forget/src/__tests__/test-utils/generateTestsFromFixtures.ts
+3 -3
@@ -103,7 +103,7 @@ export default function generateTestsFromFixtures(
103 let panicOnBailout = true;
104 let memoizeJsxElements = true;
105 let enableAssumeHooksFollowRulesOfReact = false;
106 - let enableTreatHooksAsFunctions = false;
106 + let enableTreatHooksAsFunctions = true;
107
108 if (inputFile != null) {
109 input = fs.readFileSync(inputFile, "utf8");
@@ -153,8 +153,8 @@ export default function generateTestsFromFixtures(
153 ) {
154 enableAssumeHooksFollowRulesOfReact = true;
155 }
156 - if (lines[0]!.indexOf("@enableTreatHooksAsFunctions true") !== -1) {
157 - enableTreatHooksAsFunctions = true;
156 + if (lines[0]!.indexOf("@enableTreatHooksAsFunctions false") !== -1) {
157 + enableTreatHooksAsFunctions = false;
158 }
159 }
160