@samitouri / QOS-React-2 / commits / 44a6a602a7

[be] Update feature defaults to reflect usage

Updates feature flag default values to match the flags we have turned on internally for some time w/o issues.

Joe Savona committed Oct 3, 2023 at 14:49 UTC 44a6a602a7e5f21184d44f8b16f6abfa61a960d4
22 files changed +128 -195
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+4 -4
@@ -251,6 +251,10 @@ const DEFAULT_ENVIRONMENT_CONFIG: CompleteEnvironmentConfig = {
251
252 enableTreatHooksAsFunctions: true,
253 memoizeJsxElements: true,
254 + enableFunctionCallSignatureOptimizations: true,
255 + inlineUseMemo: true,
256 + validateHooksUsage: true,
257 + enableNoAliasOptimizations: true,
258
259 assertValidMutableRanges: false,
260 bailoutOnHoleyArrays: false,
@@ -258,13 +262,9 @@ const DEFAULT_ENVIRONMENT_CONFIG: CompleteEnvironmentConfig = {
262 enableAssumeHooksFollowRulesOfReact: false,
263 enableEmitFreeze: null,
264 enableForest: false,
261 - enableFunctionCallSignatureOptimizations: false,
265 enableMergeConsecutiveScopes: false,
263 - enableNoAliasOptimizations: false,
264 - inlineUseMemo: false,
266
267 validateFrozenLambdas: false,
267 - validateHooksUsage: false,
268 validateNoSetStateInRender: false,
269 validateRefAccessDuringRender: false,
270 };
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-captures-receiver-noAlias.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 // This item is part of the receiver, should be memoized
7 const item = { a: props.a };
@@ -22,7 +21,7 @@ export const FIXTURE_ENTRYPOINT = {
21 ## Code
22
23 ```javascript
25 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
24 +import { unstable_useMemoCache as useMemoCache } from "react";
25 function Component(props) {
26 const $ = useMemoCache(2);
27 const c_0 = $[0] !== props.a;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-captures-receiver-noAlias.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 // This item is part of the receiver, should be memoized
3 const item = { a: props.a };
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-frozen-array-noAlias.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 const x = [];
7 <dif>{x}</dif>;
@@ -21,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
20 ## Code
21
22 ```javascript
24 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
23 +import { unstable_useMemoCache as useMemoCache } from "react";
24 function Component(props) {
25 const $ = useMemoCache(3);
26 let t0;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-frozen-array-noAlias.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 const x = [];
3 <dif>{x}</dif>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-frozen-array.expect.md
+12 -19
@@ -22,7 +22,7 @@ export const FIXTURE_ENTRYPOINT = {
22 ```javascript
23 import { unstable_useMemoCache as useMemoCache } from "react";
24 function Component(props) {
25 - const $ = useMemoCache(4);
25 + const $ = useMemoCache(3);
26 let t0;
27 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 t0 = [];
@@ -31,29 +31,22 @@ function Component(props) {
31 t0 = $[0];
32 }
33 const x = t0;
34 - let t2;
34 + let t1;
35 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
36 - let t1;
37 - if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
38 - t1 = (item) => item;
39 - $[2] = t1;
40 - } else {
41 - t1 = $[2];
42 - }
43 - t2 = x.map(t1);
44 - $[1] = t2;
36 + t1 = x.map((item) => item);
37 + $[1] = t1;
38 } else {
46 - t2 = $[1];
39 + t1 = $[1];
40 }
48 - const y = t2;
49 - let t3;
50 - if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
51 - t3 = [x, y];
52 - $[3] = t3;
41 + const y = t1;
42 + let t2;
43 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
44 + t2 = [x, y];
45 + $[2] = t2;
46 } else {
54 - t3 = $[3];
47 + t2 = $[2];
48 }
56 - return t3;
49 + return t2;
50 }
51
52 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-mutable-array-mutating-lambda-noAlias.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 const x = [];
7 const y = x.map((item) => {
@@ -23,7 +22,7 @@ export const FIXTURE_ENTRYPOINT = {
22 ## Code
23
24 ```javascript
26 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
25 +import { unstable_useMemoCache as useMemoCache } from "react";
26 function Component(props) {
27 const $ = useMemoCache(3);
28 let t0;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-mutable-array-mutating-lambda-noAlias.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 const x = [];
3 const y = x.map((item) => {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-mutable-array-mutating-lambda.expect.md
+15 -22
@@ -24,37 +24,30 @@ export const FIXTURE_ENTRYPOINT = {
24 ```javascript
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function Component(props) {
27 - const $ = useMemoCache(4);
28 - let t1;
27 + const $ = useMemoCache(3);
28 + let t0;
29 let x;
30 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31 x = [];
32 - let t0;
33 - if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
34 - t0 = (item) => {
35 - item.updated = true;
36 - return item;
37 - };
38 - $[2] = t0;
39 - } else {
40 - t0 = $[2];
41 - }
42 - t1 = x.map(t0);
43 - $[0] = t1;
32 + t0 = x.map((item) => {
33 + item.updated = true;
34 + return item;
35 + });
36 + $[0] = t0;
37 $[1] = x;
38 } else {
46 - t1 = $[0];
39 + t0 = $[0];
40 x = $[1];
41 }
49 - const y = t1;
50 - let t2;
51 - if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
52 - t2 = [x, y];
53 - $[3] = t2;
42 + const y = t0;
43 + let t1;
44 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
45 + t1 = [x, y];
46 + $[2] = t1;
47 } else {
55 - t2 = $[3];
48 + t1 = $[2];
49 }
57 - return t2;
50 + return t1;
51 }
52
53 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-noAlias-escaping-function.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 const f = (item) => item;
7 const x = [...props.items].map(f); // `f` doesn't escape here...
@@ -20,7 +19,7 @@ export const FIXTURE_ENTRYPOINT = {
19 ## Code
20
21 ```javascript
23 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
22 +import { unstable_useMemoCache as useMemoCache } from "react";
23 function Component(props) {
24 const $ = useMemoCache(5);
25 let t0;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-map-noAlias-escaping-function.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 const f = (item) => item;
3 const x = [...props.items].map(f); // `f` doesn't escape here...
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
+53 -60
@@ -56,94 +56,87 @@ function useFragment(_arg1, _arg2) {
56 }
57
58 function Component(props) {
59 - const $ = useMemoCache(17);
60 - let t0;
61 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
62 - t0 = graphql`...`;
63 - $[0] = t0;
64 - } else {
65 - t0 = $[0];
66 - }
67 - const post = useFragment(t0, props.post);
68 - const c_1 = $[1] !== post;
59 + const $ = useMemoCache(16);
60 + const post = useFragment(graphql`...`, props.post);
61 + const c_0 = $[0] !== post;
62 let media;
63 let allUrls;
64 let onClick;
72 - if (c_1) {
65 + if (c_0) {
66 allUrls = [];
67
75 - const { media: t1, comments: t3, urls: t5 } = post;
76 - const c_5 = $[5] !== t1;
77 - let t2;
78 - if (c_5) {
79 - t2 = t1 === undefined ? null : t1;
68 + const { media: t0, comments: t2, urls: t4 } = post;
69 + const c_4 = $[4] !== t0;
70 + let t1;
71 + if (c_4) {
72 + t1 = t0 === undefined ? null : t0;
73 + $[4] = t0;
74 $[5] = t1;
81 - $[6] = t2;
75 } else {
83 - t2 = $[6];
76 + t1 = $[5];
77 }
85 - media = t2;
86 - const c_7 = $[7] !== t3;
87 - let t4;
88 - if (c_7) {
89 - t4 = t3 === undefined ? [] : t3;
78 + media = t1;
79 + const c_6 = $[6] !== t2;
80 + let t3;
81 + if (c_6) {
82 + t3 = t2 === undefined ? [] : t2;
83 + $[6] = t2;
84 $[7] = t3;
91 - $[8] = t4;
85 } else {
93 - t4 = $[8];
86 + t3 = $[7];
87 }
95 - const comments = t4;
96 - const c_9 = $[9] !== t5;
97 - let t6;
98 - if (c_9) {
99 - t6 = t5 === undefined ? [] : t5;
88 + const comments = t3;
89 + const c_8 = $[8] !== t4;
90 + let t5;
91 + if (c_8) {
92 + t5 = t4 === undefined ? [] : t4;
93 + $[8] = t4;
94 $[9] = t5;
101 - $[10] = t6;
95 } else {
103 - t6 = $[10];
96 + t5 = $[9];
97 }
105 - const urls = t6;
106 - const c_11 = $[11] !== comments.length;
107 - let t7;
108 - if (c_11) {
109 - t7 = (e) => {
98 + const urls = t5;
99 + const c_10 = $[10] !== comments.length;
100 + let t6;
101 + if (c_10) {
102 + t6 = (e) => {
103 if (!comments.length) {
104 return;
105 }
106
107 console.log(comments.length);
108 };
116 - $[11] = comments.length;
117 - $[12] = t7;
109 + $[10] = comments.length;
110 + $[11] = t6;
111 } else {
119 - t7 = $[12];
112 + t6 = $[11];
113 }
121 - onClick = t7;
114 + onClick = t6;
115
116 allUrls.push(...urls);
124 - $[1] = post;
125 - $[2] = media;
126 - $[3] = allUrls;
127 - $[4] = onClick;
117 + $[0] = post;
118 + $[1] = media;
119 + $[2] = allUrls;
120 + $[3] = onClick;
121 } else {
129 - media = $[2];
130 - allUrls = $[3];
131 - onClick = $[4];
122 + media = $[1];
123 + allUrls = $[2];
124 + onClick = $[3];
125 }
133 - const c_13 = $[13] !== media;
134 - const c_14 = $[14] !== allUrls;
135 - const c_15 = $[15] !== onClick;
136 - let t8;
137 - if (c_13 || c_14 || c_15) {
138 - t8 = <Stringify media={media} allUrls={allUrls} onClick={onClick} />;
139 - $[13] = media;
140 - $[14] = allUrls;
141 - $[15] = onClick;
142 - $[16] = t8;
126 + const c_12 = $[12] !== media;
127 + const c_13 = $[13] !== allUrls;
128 + const c_14 = $[14] !== onClick;
129 + let t7;
130 + if (c_12 || c_13 || c_14) {
131 + t7 = <Stringify media={media} allUrls={allUrls} onClick={onClick} />;
132 + $[12] = media;
133 + $[13] = allUrls;
134 + $[14] = onClick;
135 + $[15] = t7;
136 } else {
144 - t8 = $[16];
137 + t7 = $[15];
138 }
146 - return t8;
139 + return t7;
140 }
141
142 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
+27 -34
@@ -30,60 +30,53 @@ function Component(props) {
30 ```javascript
31 import { unstable_useMemoCache as useMemoCache } from "react";
32 function Component(props) {
33 - const $ = useMemoCache(9);
34 - let t0;
35 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 - t0 = graphql`...`;
37 - $[0] = t0;
38 - } else {
39 - t0 = $[0];
40 - }
41 - const post = useFragment(t0, props.post);
42 - const c_1 = $[1] !== post;
33 + const $ = useMemoCache(8);
34 + const post = useFragment(graphql`...`, props.post);
35 + const c_0 = $[0] !== post;
36 let media;
37 let onClick;
45 - if (c_1) {
38 + if (c_0) {
39 const allUrls = [];
40
41 const { media: t83, comments, urls } = post;
42 media = t83;
50 - const c_4 = $[4] !== comments.length;
51 - let t1;
52 - if (c_4) {
53 - t1 = (e) => {
43 + const c_3 = $[3] !== comments.length;
44 + let t0;
45 + if (c_3) {
46 + t0 = (e) => {
47 if (!comments.length) {
48 return;
49 }
50
51 console.log(comments.length);
52 };
60 - $[4] = comments.length;
61 - $[5] = t1;
53 + $[3] = comments.length;
54 + $[4] = t0;
55 } else {
63 - t1 = $[5];
56 + t0 = $[4];
57 }
65 - onClick = t1;
58 + onClick = t0;
59
60 allUrls.push(...urls);
68 - $[1] = post;
69 - $[2] = media;
70 - $[3] = onClick;
61 + $[0] = post;
62 + $[1] = media;
63 + $[2] = onClick;
64 } else {
72 - media = $[2];
73 - onClick = $[3];
65 + media = $[1];
66 + onClick = $[2];
67 }
75 - const c_6 = $[6] !== media;
76 - const c_7 = $[7] !== onClick;
77 - let t2;
78 - if (c_6 || c_7) {
79 - t2 = <Media media={media} onClick={onClick} />;
80 - $[6] = media;
81 - $[7] = onClick;
82 - $[8] = t2;
68 + const c_5 = $[5] !== media;
69 + const c_6 = $[6] !== onClick;
70 + let t1;
71 + if (c_5 || c_6) {
72 + t1 = <Media media={media} onClick={onClick} />;
73 + $[5] = media;
74 + $[6] = onClick;
75 + $[7] = t1;
76 } else {
84 - t2 = $[8];
77 + t1 = $[7];
78 }
86 - return t2;
79 + return t1;
80 }
81
82 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hook-noAlias.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 import { useNoAlias } from "shared-runtime";
6
7 function Component(props) {
@@ -28,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27 ## Code
28
29 ```javascript
31 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
30 +import { unstable_useMemoCache as useMemoCache } from "react";
31 import { useNoAlias } from "shared-runtime";
32
33 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hook-noAlias.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 import { useNoAlias } from "shared-runtime";
2
3 function Component(props) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/optional-call-logical.expect.md
+9 -16
@@ -14,25 +14,18 @@ function Component(props) {
14 ```javascript
15 import { unstable_useMemoCache as useMemoCache } from "react";
16 function Component(props) {
17 - const $ = useMemoCache(3);
17 + const $ = useMemoCache(2);
18 + const item = useFragment(graphql`...`, props.item);
19 + const c_0 = $[0] !== item.items;
20 let t0;
19 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20 - t0 = graphql`...`;
21 - $[0] = t0;
22 - } else {
23 - t0 = $[0];
24 - }
25 - const item = useFragment(t0, props.item);
26 - const c_1 = $[1] !== item.items;
27 - let t1;
28 - if (c_1) {
29 - t1 = item.items?.map((item_0) => renderItem(item_0)) ?? [];
30 - $[1] = item.items;
31 - $[2] = t1;
21 + if (c_0) {
22 + t0 = item.items?.map((item_0) => renderItem(item_0)) ?? [];
23 + $[0] = item.items;
24 + $[1] = t0;
25 } else {
33 - t1 = $[2];
26 + t0 = $[1];
27 }
35 - return t1;
28 + return t0;
29 }
30
31 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 const x = makeObject();
7 const user = useFragment(
@@ -24,7 +23,7 @@ function Component(props) {
23 ## Code
24
25 ```javascript
27 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
26 +import { unstable_useMemoCache as useMemoCache } from "react";
27 function Component(props) {
28 const $ = useMemoCache(3);
29 const x = makeObject();
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 const x = makeObject();
3 const user = useFragment(
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableNoAliasOptimizations
5 function Component(props) {
6 const user = useFragment(
7 graphql`fragment Component_user on User { ... }`,
@@ -22,7 +21,7 @@ function Component(props) {
21 ## Code
22
23 ```javascript
25 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
24 +import { unstable_useMemoCache as useMemoCache } from "react";
25 function Component(props) {
26 const $ = useMemoCache(5);
27 const user = useFragment(
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/readonly-object-method-calls.js
-1
@@ -1,4 +1,3 @@
1 -// @enableNoAliasOptimizations
1 function Component(props) {
2 const user = useFragment(
3 graphql`fragment Component_user on User { ... }`,
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/tagged-template-in-hook.expect.md
+1 -10
@@ -12,17 +12,8 @@ function Component(props) {
12 ## Code
13
14 ```javascript
15 -import { unstable_useMemoCache as useMemoCache } from "react";
15 function Component(props) {
17 - const $ = useMemoCache(1);
18 - let t0;
19 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20 - t0 = graphql`fragment on User { name }`;
21 - $[0] = t0;
22 - } else {
23 - t0 = $[0];
24 - }
25 - const user = useFragment(t0, props.user);
16 + const user = useFragment(graphql`fragment on User { name }`, props.user);
17 return user.name;
18 }
19
compiler/packages/fixture-test-utils/src/compiler-utils.ts
-9
@@ -28,7 +28,6 @@ export function transformFixtureInput(
28 let enableEmitFreeze = null;
29 let compilationMode: CompilationMode = "all";
30 let enableForest = false;
31 - let enableNoAliasOptimizations = false;
31 let enableMergeConsecutiveScopes = false;
32 let bailoutOnHoleyArrays = false;
33
@@ -86,10 +85,6 @@ export function transformFixtureInput(
85 if (firstLine.includes("@enableForest true")) {
86 enableForest = true;
87 }
89 - if (firstLine.includes("@enableNoAliasOptimizations")) {
90 - enableNoAliasOptimizations = true;
91 - }
92 -
88 if (firstLine.includes("@bailoutOnHoleyArrays")) {
89 bailoutOnHoleyArrays = true;
90 }
@@ -134,13 +129,9 @@ export function transformFixtureInput(
129 ],
130 ]),
131 enableAssumeHooksFollowRulesOfReact,
137 - enableFunctionCallSignatureOptimizations: true,
138 - enableNoAliasOptimizations,
132 disableAllMemoization,
133 enableTreatHooksAsFunctions,
141 - inlineUseMemo: true,
134 memoizeJsxElements,
143 - validateHooksUsage: true,
135 validateRefAccessDuringRender,
136 validateFrozenLambdas: true,
137 validateNoSetStateInRender,