@samitouri / QOS-React / commits / 43264a61d0

[compiler][cleanup] Remove unused enableReactiveScopesInHIR flag

Reactive scopes in HIR has been stable for over 3 months now and is the future direction of react compiler, removing this flag to reduce implementation forks. ghstack-source-id: 65cdf63cf76029fa22d40fd85aba0ac976dcfc08 Pull Request resolved: https://github.com/facebook/react/pull/30891

Mofei Zhang committed Sep 5, 2024 at 20:14 UTC 43264a61d06e0f653beb7882aaad1005e0797855
24 files changed +47 -1355
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts
+40 -85
@@ -46,18 +46,13 @@ import {instructionReordering} from '../Optimization/InstructionReordering';
46 import {
47 CodegenFunction,
48 alignObjectMethodScopes,
49 - alignReactiveScopesToBlockScopes,
49 assertScopeInstructionsWithinScopes,
50 assertWellFormedBreakTargets,
52 - buildReactiveBlocks,
51 buildReactiveFunction,
52 codegenFunction,
53 extractScopeDeclarationsFromDestructuring,
56 - flattenReactiveLoops,
57 - flattenScopesWithHooksOrUse,
54 inferReactiveScopeVariables,
55 memoizeFbtAndMacroOperandsInSameScope,
60 - mergeOverlappingReactiveScopes,
56 mergeReactiveScopesThatInvalidateTogether,
57 promoteUsedTemporaries,
58 propagateEarlyReturns,
@@ -300,54 +295,52 @@ function* runWithEnvironment(
295 value: hir,
296 });
297
303 - if (env.config.enableReactiveScopesInHIR) {
304 - pruneUnusedLabelsHIR(hir);
305 - yield log({
306 - kind: 'hir',
307 - name: 'PruneUnusedLabelsHIR',
308 - value: hir,
309 - });
298 + pruneUnusedLabelsHIR(hir);
299 + yield log({
300 + kind: 'hir',
301 + name: 'PruneUnusedLabelsHIR',
302 + value: hir,
303 + });
304
311 - alignReactiveScopesToBlockScopesHIR(hir);
312 - yield log({
313 - kind: 'hir',
314 - name: 'AlignReactiveScopesToBlockScopesHIR',
315 - value: hir,
316 - });
305 + alignReactiveScopesToBlockScopesHIR(hir);
306 + yield log({
307 + kind: 'hir',
308 + name: 'AlignReactiveScopesToBlockScopesHIR',
309 + value: hir,
310 + });
311
318 - mergeOverlappingReactiveScopesHIR(hir);
319 - yield log({
320 - kind: 'hir',
321 - name: 'MergeOverlappingReactiveScopesHIR',
322 - value: hir,
323 - });
324 - assertValidBlockNesting(hir);
312 + mergeOverlappingReactiveScopesHIR(hir);
313 + yield log({
314 + kind: 'hir',
315 + name: 'MergeOverlappingReactiveScopesHIR',
316 + value: hir,
317 + });
318 + assertValidBlockNesting(hir);
319
326 - buildReactiveScopeTerminalsHIR(hir);
327 - yield log({
328 - kind: 'hir',
329 - name: 'BuildReactiveScopeTerminalsHIR',
330 - value: hir,
331 - });
320 + buildReactiveScopeTerminalsHIR(hir);
321 + yield log({
322 + kind: 'hir',
323 + name: 'BuildReactiveScopeTerminalsHIR',
324 + value: hir,
325 + });
326
333 - assertValidBlockNesting(hir);
327 + assertValidBlockNesting(hir);
328
335 - flattenReactiveLoopsHIR(hir);
336 - yield log({
337 - kind: 'hir',
338 - name: 'FlattenReactiveLoopsHIR',
339 - value: hir,
340 - });
329 + flattenReactiveLoopsHIR(hir);
330 + yield log({
331 + kind: 'hir',
332 + name: 'FlattenReactiveLoopsHIR',
333 + value: hir,
334 + });
335
342 - flattenScopesWithHooksOrUseHIR(hir);
343 - yield log({
344 - kind: 'hir',
345 - name: 'FlattenScopesWithHooksOrUseHIR',
346 - value: hir,
347 - });
348 - assertTerminalSuccessorsExist(hir);
349 - assertTerminalPredsExist(hir);
350 - }
336 + flattenScopesWithHooksOrUseHIR(hir);
337 + yield log({
338 + kind: 'hir',
339 + name: 'FlattenScopesWithHooksOrUseHIR',
340 + value: hir,
341 + });
342 + assertTerminalSuccessorsExist(hir);
343 + assertTerminalPredsExist(hir);
344
345 const reactiveFunction = buildReactiveFunction(hir);
346 yield log({
@@ -364,44 +357,6 @@ function* runWithEnvironment(
357 name: 'PruneUnusedLabels',
358 value: reactiveFunction,
359 });
367 -
368 - if (!env.config.enableReactiveScopesInHIR) {
369 - alignReactiveScopesToBlockScopes(reactiveFunction);
370 - yield log({
371 - kind: 'reactive',
372 - name: 'AlignReactiveScopesToBlockScopes',
373 - value: reactiveFunction,
374 - });
375 -
376 - mergeOverlappingReactiveScopes(reactiveFunction);
377 - yield log({
378 - kind: 'reactive',
379 - name: 'MergeOverlappingReactiveScopes',
380 - value: reactiveFunction,
381 - });
382 -
383 - buildReactiveBlocks(reactiveFunction);
384 - yield log({
385 - kind: 'reactive',
386 - name: 'BuildReactiveBlocks',
387 - value: reactiveFunction,
388 - });
389 -
390 - flattenReactiveLoops(reactiveFunction);
391 - yield log({
392 - kind: 'reactive',
393 - name: 'FlattenReactiveLoops',
394 - value: reactiveFunction,
395 - });
396 -
397 - flattenScopesWithHooksOrUse(reactiveFunction);
398 - yield log({
399 - kind: 'reactive',
400 - name: 'FlattenScopesWithHooks',
401 - value: reactiveFunction,
402 - });
403 - }
404 -
360 assertScopeInstructionsWithinScopes(reactiveFunction);
361
362 propagateScopeDependencies(reactiveFunction);
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
-2
@@ -222,8 +222,6 @@ const EnvironmentConfigSchema = z.object({
222 */
223 enableUseTypeAnnotations: z.boolean().default(false),
224
225 - enableReactiveScopesInHIR: z.boolean().default(true),
226 -
225 /**
226 * Enables inference of optional dependency chains. Without this flag
227 * a property chain such as `props?.items?.foo` will infer as a dep on
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.expect.md
+7 -10
@@ -2,8 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableReactiveScopesInHIR:false
6 -
5 import {Stringify, identity, makeArray, mutate} from 'shared-runtime';
6
7 /**
@@ -37,8 +35,7 @@ export const FIXTURE_ENTRYPOINT = {
35 ## Code
36
37 ```javascript
40 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
41 -
38 +import { c as _c } from "react/compiler-runtime";
39 import { Stringify, identity, makeArray, mutate } from "shared-runtime";
40
41 /**
@@ -52,11 +49,12 @@ import { Stringify, identity, makeArray, mutate } from "shared-runtime";
49 * handles this correctly.
50 */
51 function Foo(t0) {
55 - const $ = _c(4);
52 + const $ = _c(3);
53 const { cond1, cond2 } = t0;
57 - const arr = makeArray({ a: 2 }, 2, []);
54 let t1;
59 - if ($[0] !== cond1 || $[1] !== cond2 || $[2] !== arr) {
55 + if ($[0] !== cond1 || $[1] !== cond2) {
56 + const arr = makeArray({ a: 2 }, 2, []);
57 +
58 t1 = cond1 ? (
59 <>
60 <div>{identity("foo")}</div>
@@ -65,10 +63,9 @@ function Foo(t0) {
63 ) : null;
64 $[0] = cond1;
65 $[1] = cond2;
68 - $[2] = arr;
69 - $[3] = t1;
66 + $[2] = t1;
67 } else {
71 - t1 = $[3];
68 + t1 = $[2];
69 }
70 return t1;
71 }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.tsx
-2
@@ -1,5 +1,3 @@
1 -// @enableReactiveScopesInHIR:false
2 -
1 import {Stringify, identity, makeArray, mutate} from 'shared-runtime';
2
3 /**
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/allocating-logical-expression-instruction-scope.expect.md deleted
-61
@@ -1,61 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -
7 -/**
8 - * This is a weird case as data has type `BuiltInMixedReadonly`.
9 - * The only scoped value we currently infer in this program is the
10 - * PropertyLoad `data?.toString`.
11 - */
12 -import {useFragment} from 'shared-runtime';
13 -
14 -function Foo() {
15 - const data = useFragment();
16 - return [data?.toString() || ''];
17 -}
18 -
19 -export const FIXTURE_ENTRYPOINT = {
20 - fn: Foo,
21 - params: [],
22 -};
23 -
24 -```
25 -
26 -## Code
27 -
28 -```javascript
29 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
30 -
31 -/**
32 - * This is a weird case as data has type `BuiltInMixedReadonly`.
33 - * The only scoped value we currently infer in this program is the
34 - * PropertyLoad `data?.toString`.
35 - */
36 -import { useFragment } from "shared-runtime";
37 -
38 -function Foo() {
39 - const $ = _c(2);
40 - const data = useFragment();
41 - const t0 = data?.toString() || "";
42 - let t1;
43 - if ($[0] !== t0) {
44 - t1 = [t0];
45 - $[0] = t0;
46 - $[1] = t1;
47 - } else {
48 - t1 = $[1];
49 - }
50 - return t1;
51 -}
52 -
53 -export const FIXTURE_ENTRYPOINT = {
54 - fn: Foo,
55 - params: [],
56 -};
57 -
58 -```
59 -
60 -### Eval output
61 -(kind: ok) ["[object Object]"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/allocating-logical-expression-instruction-scope.ts deleted
-18
@@ -1,18 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -
3 -/**
4 - * This is a weird case as data has type `BuiltInMixedReadonly`.
5 - * The only scoped value we currently infer in this program is the
6 - * PropertyLoad `data?.toString`.
7 - */
8 -import {useFragment} from 'shared-runtime';
9 -
10 -function Foo() {
11 - const data = useFragment();
12 - return [data?.toString() || ''];
13 -}
14 -
15 -export const FIXTURE_ENTRYPOINT = {
16 - fn: Foo,
17 - params: [],
18 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/bug-hoisted-declaration-with-scope.expect.md deleted
-96
@@ -1,96 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {StaticText1, Stringify, identity, useHook} from 'shared-runtime';
7 -/**
8 - * `button` and `dispatcher` must end up in the same memo block. It would be
9 - * invalid for `button` to take a dependency on `dispatcher` as dispatcher
10 - * is created later.
11 - *
12 - * Sprout error:
13 - * Found differences in evaluator results
14 - * Non-forget (expected):
15 - * (kind: ok) "[[ function params=1 ]]"
16 - * Forget:
17 - * (kind: exception) Cannot access 'dispatcher' before initialization
18 - */
19 -function useFoo({onClose}) {
20 - const button = StaticText1 ?? (
21 - <Stringify
22 - primary={{
23 - label: identity('label'),
24 - onPress: onClose,
25 - }}
26 - secondary={{
27 - onPress: () => {
28 - dispatcher.go('route2');
29 - },
30 - }}
31 - />
32 - );
33 -
34 - const dispatcher = useHook();
35 -
36 - return button;
37 -}
38 -
39 -export const FIXTURE_ENTRYPOINT = {
40 - fn: useFoo,
41 - params: [{onClose: identity()}],
42 -};
43 -
44 -```
45 -
46 -## Code
47 -
48 -```javascript
49 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
50 -import { StaticText1, Stringify, identity, useHook } from "shared-runtime";
51 -/**
52 - * `button` and `dispatcher` must end up in the same memo block. It would be
53 - * invalid for `button` to take a dependency on `dispatcher` as dispatcher
54 - * is created later.
55 - *
56 - * Sprout error:
57 - * Found differences in evaluator results
58 - * Non-forget (expected):
59 - * (kind: ok) "[[ function params=1 ]]"
60 - * Forget:
61 - * (kind: exception) Cannot access 'dispatcher' before initialization
62 - */
63 -function useFoo(t0) {
64 - const $ = _c(3);
65 - const { onClose } = t0;
66 - let t1;
67 - if ($[0] !== onClose || $[1] !== dispatcher) {
68 - t1 = StaticText1 ?? (
69 - <Stringify
70 - primary={{ label: identity("label"), onPress: onClose }}
71 - secondary={{
72 - onPress: () => {
73 - dispatcher.go("route2");
74 - },
75 - }}
76 - />
77 - );
78 - $[0] = onClose;
79 - $[1] = dispatcher;
80 - $[2] = t1;
81 - } else {
82 - t1 = $[2];
83 - }
84 - const button = t1;
85 -
86 - const dispatcher = useHook();
87 - return button;
88 -}
89 -
90 -export const FIXTURE_ENTRYPOINT = {
91 - fn: useFoo,
92 - params: [{ onClose: identity() }],
93 -};
94 -
95 -```
96 -
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/bug-hoisted-declaration-with-scope.tsx deleted
-38
@@ -1,38 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {StaticText1, Stringify, identity, useHook} from 'shared-runtime';
3 -/**
4 - * `button` and `dispatcher` must end up in the same memo block. It would be
5 - * invalid for `button` to take a dependency on `dispatcher` as dispatcher
6 - * is created later.
7 - *
8 - * Sprout error:
9 - * Found differences in evaluator results
10 - * Non-forget (expected):
11 - * (kind: ok) "[[ function params=1 ]]"
12 - * Forget:
13 - * (kind: exception) Cannot access 'dispatcher' before initialization
14 - */
15 -function useFoo({onClose}) {
16 - const button = StaticText1 ?? (
17 - <Stringify
18 - primary={{
19 - label: identity('label'),
20 - onPress: onClose,
21 - }}
22 - secondary={{
23 - onPress: () => {
24 - dispatcher.go('route2');
25 - },
26 - }}
27 - />
28 - );
29 -
30 - const dispatcher = useHook();
31 -
32 - return button;
33 -}
34 -
35 -export const FIXTURE_ENTRYPOINT = {
36 - fn: useFoo,
37 - params: [{onClose: identity()}],
38 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block.expect.md deleted
-137
@@ -1,137 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {identity, mutate} from 'shared-runtime';
7 -
8 -/**
9 - * The root cause of this bug is in `InferReactiveScopeVariables`. Currently,
10 - * InferReactiveScopeVariables do not ensure that maybe-aliased values get
11 - * assigned the same reactive scope. This is safe only when an already-
12 - * constructed value is captured, e.g.
13 - * ```js
14 - * const x = makeObj(); ⌝ mutable range of x
15 - * mutate(x); ⌟
16 - * <-- after this point, we can produce a canonical version
17 - * of x for all following aliases
18 - * const y = [];
19 - * y.push(x); <-- y captures x
20 - * ```
21 - *
22 - * However, if a value is captured/aliased during its mutable range and the
23 - * capturing container is separately memoized, it becomes difficult to guarantee
24 - * that all aliases refer to the same value.
25 - *
26 - * Sprout error:
27 - * Found differences in evaluator results
28 - * Non-forget (expected):
29 - * (kind: ok) [{"wat0":"joe"},3]
30 - * [{"wat0":"joe"},3]
31 - * Forget:
32 - * (kind: ok) [{"wat0":"joe"},3]
33 - * [[ (exception in render) Error: oh no! ]]
34 - *
35 - */
36 -function useFoo({a, b}) {
37 - const x = {a};
38 - const y = {};
39 - mutate(x);
40 - const z = [identity(y), b];
41 - mutate(y);
42 -
43 - if (z[0] !== y) {
44 - throw new Error('oh no!');
45 - }
46 - return z;
47 -}
48 -
49 -export const FIXTURE_ENTRYPOINT = {
50 - fn: useFoo,
51 - params: [{a: 2, b: 3}],
52 - sequentialRenders: [
53 - {a: 2, b: 3},
54 - {a: 4, b: 3},
55 - ],
56 -};
57 -
58 -```
59 -
60 -## Code
61 -
62 -```javascript
63 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
64 -import { identity, mutate } from "shared-runtime";
65 -
66 -/**
67 - * The root cause of this bug is in `InferReactiveScopeVariables`. Currently,
68 - * InferReactiveScopeVariables do not ensure that maybe-aliased values get
69 - * assigned the same reactive scope. This is safe only when an already-
70 - * constructed value is captured, e.g.
71 - * ```js
72 - * const x = makeObj(); ⌝ mutable range of x
73 - * mutate(x); ⌟
74 - * <-- after this point, we can produce a canonical version
75 - * of x for all following aliases
76 - * const y = [];
77 - * y.push(x); <-- y captures x
78 - * ```
79 - *
80 - * However, if a value is captured/aliased during its mutable range and the
81 - * capturing container is separately memoized, it becomes difficult to guarantee
82 - * that all aliases refer to the same value.
83 - *
84 - * Sprout error:
85 - * Found differences in evaluator results
86 - * Non-forget (expected):
87 - * (kind: ok) [{"wat0":"joe"},3]
88 - * [{"wat0":"joe"},3]
89 - * Forget:
90 - * (kind: ok) [{"wat0":"joe"},3]
91 - * [[ (exception in render) Error: oh no! ]]
92 - *
93 - */
94 -function useFoo(t0) {
95 - const $ = _c(6);
96 - const { a, b } = t0;
97 - let z;
98 - let y;
99 - if ($[0] !== a || $[1] !== b) {
100 - const x = { a };
101 - y = {};
102 - mutate(x);
103 - let t1;
104 - if ($[4] !== b) {
105 - t1 = [identity(y), b];
106 - $[4] = b;
107 - $[5] = t1;
108 - } else {
109 - t1 = $[5];
110 - }
111 - z = t1;
112 - mutate(y);
113 - $[0] = a;
114 - $[1] = b;
115 - $[2] = z;
116 - $[3] = y;
117 - } else {
118 - z = $[2];
119 - y = $[3];
120 - }
121 - if (z[0] !== y) {
122 - throw new Error("oh no!");
123 - }
124 - return z;
125 -}
126 -
127 -export const FIXTURE_ENTRYPOINT = {
128 - fn: useFoo,
129 - params: [{ a: 2, b: 3 }],
130 - sequentialRenders: [
131 - { a: 2, b: 3 },
132 - { a: 4, b: 3 },
133 - ],
134 -};
135 -
136 -```
137 -
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block.ts deleted
-52
@@ -1,52 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {identity, mutate} from 'shared-runtime';
3 -
4 -/**
5 - * The root cause of this bug is in `InferReactiveScopeVariables`. Currently,
6 - * InferReactiveScopeVariables do not ensure that maybe-aliased values get
7 - * assigned the same reactive scope. This is safe only when an already-
8 - * constructed value is captured, e.g.
9 - * ```js
10 - * const x = makeObj(); ⌝ mutable range of x
11 - * mutate(x); ⌟
12 - * <-- after this point, we can produce a canonical version
13 - * of x for all following aliases
14 - * const y = [];
15 - * y.push(x); <-- y captures x
16 - * ```
17 - *
18 - * However, if a value is captured/aliased during its mutable range and the
19 - * capturing container is separately memoized, it becomes difficult to guarantee
20 - * that all aliases refer to the same value.
21 - *
22 - * Sprout error:
23 - * Found differences in evaluator results
24 - * Non-forget (expected):
25 - * (kind: ok) [{"wat0":"joe"},3]
26 - * [{"wat0":"joe"},3]
27 - * Forget:
28 - * (kind: ok) [{"wat0":"joe"},3]
29 - * [[ (exception in render) Error: oh no! ]]
30 - *
31 - */
32 -function useFoo({a, b}) {
33 - const x = {a};
34 - const y = {};
35 - mutate(x);
36 - const z = [identity(y), b];
37 - mutate(y);
38 -
39 - if (z[0] !== y) {
40 - throw new Error('oh no!');
41 - }
42 - return z;
43 -}
44 -
45 -export const FIXTURE_ENTRYPOINT = {
46 - fn: useFoo,
47 - params: [{a: 2, b: 3}],
48 - sequentialRenders: [
49 - {a: 2, b: 3},
50 - {a: 4, b: 3},
51 - ],
52 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/error.capture-ref-for-later-mutation.expect.md deleted
-51
@@ -1,51 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {useRef} from 'react';
7 -import {addOne} from 'shared-runtime';
8 -
9 -function useKeyCommand() {
10 - const currentPosition = useRef(0);
11 - const handleKey = direction => () => {
12 - const position = currentPosition.current;
13 - const nextPosition = direction === 'left' ? addOne(position) : position;
14 - currentPosition.current = nextPosition;
15 - };
16 - const moveLeft = {
17 - handler: handleKey('left'),
18 - };
19 - const moveRight = {
20 - handler: handleKey('right'),
21 - };
22 - return [moveLeft, moveRight];
23 -}
24 -
25 -export const FIXTURE_ENTRYPOINT = {
26 - fn: useKeyCommand,
27 - params: [],
28 -};
29 -
30 -```
31 -
32 -
33 -## Error
34 -
35 -```
36 - 11 | };
37 - 12 | const moveLeft = {
38 -> 13 | handler: handleKey('left'),
39 - | ^^^^^^^^^ InvalidReact: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (13:13)
40 -
41 -InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (13:13)
42 -
43 -InvalidReact: This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef) (16:16)
44 -
45 -InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (16:16)
46 - 14 | };
47 - 15 | const moveRight = {
48 - 16 | handler: handleKey('right'),
49 -```
50 -
51 -
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/error.capture-ref-for-later-mutation.tsx deleted
-24
@@ -1,24 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {useRef} from 'react';
3 -import {addOne} from 'shared-runtime';
4 -
5 -function useKeyCommand() {
6 - const currentPosition = useRef(0);
7 - const handleKey = direction => () => {
8 - const position = currentPosition.current;
9 - const nextPosition = direction === 'left' ? addOne(position) : position;
10 - currentPosition.current = nextPosition;
11 - };
12 - const moveLeft = {
13 - handler: handleKey('left'),
14 - };
15 - const moveRight = {
16 - handler: handleKey('right'),
17 - };
18 - return [moveLeft, moveRight];
19 -}
20 -
21 -export const FIXTURE_ENTRYPOINT = {
22 - fn: useKeyCommand,
23 - params: [],
24 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/invalid-align-scopes-within-nested-valueblock-in-array.expect.md deleted
-84
@@ -1,84 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -
7 -import {Stringify, identity, makeArray, mutate} from 'shared-runtime';
8 -
9 -/**
10 - * Here, identity('foo') is an immutable allocating instruction.
11 - * `arr` is a mutable value whose mutable range ends at `arr.map`.
12 - *
13 - * The previous (reactive function) version of alignScopesToBlocks set the range of
14 - * both scopes to end at value blocks within the <></> expression.
15 - * However, both scope ranges should be aligned to the outer value block
16 - * (e.g. `cond1 ? <>: null`). The HIR version of alignScopesToBlocks
17 - * handles this correctly.
18 - */
19 -function Foo({cond1, cond2}) {
20 - const arr = makeArray<any>({a: 2}, 2, []);
21 -
22 - return cond1 ? (
23 - <>
24 - <div>{identity('foo')}</div>
25 - <Stringify value={cond2 ? arr.map(mutate) : null} />
26 - </>
27 - ) : null;
28 -}
29 -
30 -export const FIXTURE_ENTRYPOINT = {
31 - fn: Foo,
32 - params: [{cond1: true, cond2: true}],
33 -};
34 -
35 -```
36 -
37 -## Code
38 -
39 -```javascript
40 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
41 -
42 -import { Stringify, identity, makeArray, mutate } from "shared-runtime";
43 -
44 -/**
45 - * Here, identity('foo') is an immutable allocating instruction.
46 - * `arr` is a mutable value whose mutable range ends at `arr.map`.
47 - *
48 - * The previous (reactive function) version of alignScopesToBlocks set the range of
49 - * both scopes to end at value blocks within the <></> expression.
50 - * However, both scope ranges should be aligned to the outer value block
51 - * (e.g. `cond1 ? <>: null`). The HIR version of alignScopesToBlocks
52 - * handles this correctly.
53 - */
54 -function Foo(t0) {
55 - const $ = _c(4);
56 - const { cond1, cond2 } = t0;
57 - const arr = makeArray({ a: 2 }, 2, []);
58 - let t1;
59 - if ($[0] !== cond1 || $[1] !== cond2 || $[2] !== arr) {
60 - t1 = cond1 ? (
61 - <>
62 - <div>{identity("foo")}</div>
63 - <Stringify value={cond2 ? arr.map(mutate) : null} />
64 - </>
65 - ) : null;
66 - $[0] = cond1;
67 - $[1] = cond2;
68 - $[2] = arr;
69 - $[3] = t1;
70 - } else {
71 - t1 = $[3];
72 - }
73 - return t1;
74 -}
75 -
76 -export const FIXTURE_ENTRYPOINT = {
77 - fn: Foo,
78 - params: [{ cond1: true, cond2: true }],
79 -};
80 -
81 -```
82 -
83 -### Eval output
84 -(kind: ok) <div>foo</div><div>{"value":[null,null,null]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/invalid-align-scopes-within-nested-valueblock-in-array.tsx deleted
-29
@@ -1,29 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -
3 -import {Stringify, identity, makeArray, mutate} from 'shared-runtime';
4 -
5 -/**
6 - * Here, identity('foo') is an immutable allocating instruction.
7 - * `arr` is a mutable value whose mutable range ends at `arr.map`.
8 - *
9 - * The previous (reactive function) version of alignScopesToBlocks set the range of
10 - * both scopes to end at value blocks within the <></> expression.
11 - * However, both scope ranges should be aligned to the outer value block
12 - * (e.g. `cond1 ? <>: null`). The HIR version of alignScopesToBlocks
13 - * handles this correctly.
14 - */
15 -function Foo({cond1, cond2}) {
16 - const arr = makeArray<any>({a: 2}, 2, []);
17 -
18 - return cond1 ? (
19 - <>
20 - <div>{identity('foo')}</div>
21 - <Stringify value={cond2 ? arr.map(mutate) : null} />
22 - </>
23 - ) : null;
24 -}
25 -
26 -export const FIXTURE_ENTRYPOINT = {
27 - fn: Foo,
28 - params: [{cond1: true, cond2: true}],
29 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutate-outer-scope-within-value-block.expect.md deleted
-101
@@ -1,101 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
7 -
8 -/**
9 - * There are three values with their own scopes in this fixture.
10 - * - arr, whose mutable range extends to the `mutate(...)` call
11 - * - cond, which has a mutable range of exactly 1 (e.g. created but not
12 - * mutated)
13 - * - { val: CONST_TRUE }, which is also not mutated after creation. However,
14 - * its scope range becomes extended to the value block.
15 - *
16 - * After AlignScopesToBlockScopes, our scopes look roughly like this
17 - * ```js
18 - * [1] arr = shallowCopy() ⌝@0
19 - * [2] cond = identity() <- @1 |
20 - * [3] $0 = Ternary test=cond ⌝@2 |
21 - * [4] {val : CONST_TRUE} | |
22 - * [5] mutate(arr) | |
23 - * [6] return $0 ⌟ ⌟
24 - * ```
25 - *
26 - * Observe that instruction 5 mutates scope 0, which means that scopes 0 and 2
27 - * should be merged.
28 - */
29 -function useFoo({input}) {
30 - const arr = shallowCopy(input);
31 -
32 - const cond = identity(false);
33 - return cond ? {val: CONST_TRUE} : mutate(arr);
34 -}
35 -
36 -export const FIXTURE_ENTRYPOINT = {
37 - fn: useFoo,
38 - params: [{input: 3}],
39 -};
40 -
41 -```
42 -
43 -## Code
44 -
45 -```javascript
46 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
47 -import { CONST_TRUE, identity, shallowCopy } from "shared-runtime";
48 -
49 -/**
50 - * There are three values with their own scopes in this fixture.
51 - * - arr, whose mutable range extends to the `mutate(...)` call
52 - * - cond, which has a mutable range of exactly 1 (e.g. created but not
53 - * mutated)
54 - * - { val: CONST_TRUE }, which is also not mutated after creation. However,
55 - * its scope range becomes extended to the value block.
56 - *
57 - * After AlignScopesToBlockScopes, our scopes look roughly like this
58 - * ```js
59 - * [1] arr = shallowCopy() ⌝@0
60 - * [2] cond = identity() <- @1 |
61 - * [3] $0 = Ternary test=cond ⌝@2 |
62 - * [4] {val : CONST_TRUE} | |
63 - * [5] mutate(arr) | |
64 - * [6] return $0 ⌟ ⌟
65 - * ```
66 - *
67 - * Observe that instruction 5 mutates scope 0, which means that scopes 0 and 2
68 - * should be merged.
69 - */
70 -function useFoo(t0) {
71 - const $ = _c(3);
72 - const { input } = t0;
73 - const arr = shallowCopy(input);
74 - let t1;
75 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
76 - t1 = identity(false);
77 - $[0] = t1;
78 - } else {
79 - t1 = $[0];
80 - }
81 - const cond = t1;
82 - let t2;
83 - if ($[1] !== arr) {
84 - t2 = cond ? { val: CONST_TRUE } : mutate(arr);
85 - $[1] = arr;
86 - $[2] = t2;
87 - } else {
88 - t2 = $[2];
89 - }
90 - return t2;
91 -}
92 -
93 -export const FIXTURE_ENTRYPOINT = {
94 - fn: useFoo,
95 - params: [{ input: 3 }],
96 -};
97 -
98 -```
99 -
100 -### Eval output
101 -(kind: exception) mutate is not defined
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutate-outer-scope-within-value-block.ts deleted
-35
@@ -1,35 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
3 -
4 -/**
5 - * There are three values with their own scopes in this fixture.
6 - * - arr, whose mutable range extends to the `mutate(...)` call
7 - * - cond, which has a mutable range of exactly 1 (e.g. created but not
8 - * mutated)
9 - * - { val: CONST_TRUE }, which is also not mutated after creation. However,
10 - * its scope range becomes extended to the value block.
11 - *
12 - * After AlignScopesToBlockScopes, our scopes look roughly like this
13 - * ```js
14 - * [1] arr = shallowCopy() ⌝@0
15 - * [2] cond = identity() <- @1 |
16 - * [3] $0 = Ternary test=cond ⌝@2 |
17 - * [4] {val : CONST_TRUE} | |
18 - * [5] mutate(arr) | |
19 - * [6] return $0 ⌟ ⌟
20 - * ```
21 - *
22 - * Observe that instruction 5 mutates scope 0, which means that scopes 0 and 2
23 - * should be merged.
24 - */
25 -function useFoo({input}) {
26 - const arr = shallowCopy(input);
27 -
28 - const cond = identity(false);
29 - return cond ? {val: CONST_TRUE} : mutate(arr);
30 -}
31 -
32 -export const FIXTURE_ENTRYPOINT = {
33 - fn: useFoo,
34 - params: [{input: 3}],
35 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.expect.md deleted
-92
@@ -1,92 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {mutate} from 'shared-runtime';
7 -
8 -/**
9 - * This test fixture is similar to mutation-within-jsx. The only difference
10 - * is that there is no `freeze` effect here, which means that `z` may be
11 - * mutated after its memo block through mutating `y`.
12 - *
13 - * While this is technically correct (as `z` is a nested memo block), it
14 - * is an edge case as we believe that values are not mutated after their
15 - * memo blocks (which may lead to 'tearing', i.e. mutating one render's
16 - * values in a subsequent render.
17 - */
18 -function useFoo({a, b}) {
19 - // x and y's scopes start here
20 - const x = {a};
21 - const y = [b];
22 - mutate(x);
23 - // z captures the result of `mutate(y)`, which may be aliased to `y`.
24 - const z = [mutate(y)];
25 - // the following line may also mutate z
26 - mutate(y);
27 - // and end here
28 - return z;
29 -}
30 -
31 -export const FIXTURE_ENTRYPOINT = {
32 - fn: useFoo,
33 - params: [{a: 2, b: 3}],
34 -};
35 -
36 -```
37 -
38 -## Code
39 -
40 -```javascript
41 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
42 -import { mutate } from "shared-runtime";
43 -
44 -/**
45 - * This test fixture is similar to mutation-within-jsx. The only difference
46 - * is that there is no `freeze` effect here, which means that `z` may be
47 - * mutated after its memo block through mutating `y`.
48 - *
49 - * While this is technically correct (as `z` is a nested memo block), it
50 - * is an edge case as we believe that values are not mutated after their
51 - * memo blocks (which may lead to 'tearing', i.e. mutating one render's
52 - * values in a subsequent render.
53 - */
54 -function useFoo(t0) {
55 - const $ = _c(5);
56 - const { a, b } = t0;
57 - let z;
58 - if ($[0] !== a || $[1] !== b) {
59 - const x = { a };
60 - const y = [b];
61 - mutate(x);
62 -
63 - const t1 = mutate(y);
64 - let t2;
65 - if ($[3] !== t1) {
66 - t2 = [t1];
67 - $[3] = t1;
68 - $[4] = t2;
69 - } else {
70 - t2 = $[4];
71 - }
72 - z = t2;
73 -
74 - mutate(y);
75 - $[0] = a;
76 - $[1] = b;
77 - $[2] = z;
78 - } else {
79 - z = $[2];
80 - }
81 - return z;
82 -}
83 -
84 -export const FIXTURE_ENTRYPOINT = {
85 - fn: useFoo,
86 - params: [{ a: 2, b: 3 }],
87 -};
88 -
89 -```
90 -
91 -### Eval output
92 -(kind: ok) [null]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.tsx deleted
-30
@@ -1,30 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {mutate} from 'shared-runtime';
3 -
4 -/**
5 - * This test fixture is similar to mutation-within-jsx. The only difference
6 - * is that there is no `freeze` effect here, which means that `z` may be
7 - * mutated after its memo block through mutating `y`.
8 - *
9 - * While this is technically correct (as `z` is a nested memo block), it
10 - * is an edge case as we believe that values are not mutated after their
11 - * memo blocks (which may lead to 'tearing', i.e. mutating one render's
12 - * values in a subsequent render.
13 - */
14 -function useFoo({a, b}) {
15 - // x and y's scopes start here
16 - const x = {a};
17 - const y = [b];
18 - mutate(x);
19 - // z captures the result of `mutate(y)`, which may be aliased to `y`.
20 - const z = [mutate(y)];
21 - // the following line may also mutate z
22 - mutate(y);
23 - // and end here
24 - return z;
25 -}
26 -
27 -export const FIXTURE_ENTRYPOINT = {
28 - fn: useFoo,
29 - params: [{a: 2, b: 3}],
30 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-jsx-and-break.expect.md deleted
-99
@@ -1,99 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {
7 - Stringify,
8 - makeObject_Primitives,
9 - mutate,
10 - mutateAndReturn,
11 -} from 'shared-runtime';
12 -
13 -function useFoo({data}) {
14 - let obj = null;
15 - let myDiv = null;
16 - label: {
17 - if (data.cond) {
18 - obj = makeObject_Primitives();
19 - if (data.cond1) {
20 - myDiv = <Stringify value={mutateAndReturn(obj)} />;
21 - break label;
22 - }
23 - mutate(obj);
24 - }
25 - }
26 -
27 - return myDiv;
28 -}
29 -
30 -export const FIXTURE_ENTRYPOINT = {
31 - fn: useFoo,
32 - params: [{data: {cond: true, cond1: true}}],
33 - sequentialRenders: [
34 - {data: {cond: true, cond1: true}},
35 - {data: {cond: true, cond1: true}},
36 - ],
37 -};
38 -
39 -```
40 -
41 -## Code
42 -
43 -```javascript
44 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
45 -import {
46 - Stringify,
47 - makeObject_Primitives,
48 - mutate,
49 - mutateAndReturn,
50 -} from "shared-runtime";
51 -
52 -function useFoo(t0) {
53 - const $ = _c(5);
54 - const { data } = t0;
55 - let obj;
56 - let myDiv = null;
57 - bb0: if (data.cond) {
58 - if ($[0] !== data.cond1) {
59 - obj = makeObject_Primitives();
60 - if (data.cond1) {
61 - const t1 = mutateAndReturn(obj);
62 - let t2;
63 - if ($[3] !== t1) {
64 - t2 = <Stringify value={t1} />;
65 - $[3] = t1;
66 - $[4] = t2;
67 - } else {
68 - t2 = $[4];
69 - }
70 - myDiv = t2;
71 - break bb0;
72 - }
73 -
74 - mutate(obj);
75 - $[0] = data.cond1;
76 - $[1] = obj;
77 - $[2] = myDiv;
78 - } else {
79 - obj = $[1];
80 - myDiv = $[2];
81 - }
82 - }
83 - return myDiv;
84 -}
85 -
86 -export const FIXTURE_ENTRYPOINT = {
87 - fn: useFoo,
88 - params: [{ data: { cond: true, cond1: true } }],
89 - sequentialRenders: [
90 - { data: { cond: true, cond1: true } },
91 - { data: { cond: true, cond1: true } },
92 - ],
93 -};
94 -
95 -```
96 -
97 -### Eval output
98 -(kind: ok) <div>{"value":{"a":0,"b":"value1","c":true,"wat0":"joe"}}</div>
99 -<div>{"value":{"a":0,"b":"value1","c":true,"wat0":"joe"}}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-jsx-and-break.tsx deleted
-33
@@ -1,33 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {
3 - Stringify,
4 - makeObject_Primitives,
5 - mutate,
6 - mutateAndReturn,
7 -} from 'shared-runtime';
8 -
9 -function useFoo({data}) {
10 - let obj = null;
11 - let myDiv = null;
12 - label: {
13 - if (data.cond) {
14 - obj = makeObject_Primitives();
15 - if (data.cond1) {
16 - myDiv = <Stringify value={mutateAndReturn(obj)} />;
17 - break label;
18 - }
19 - mutate(obj);
20 - }
21 - }
22 -
23 - return myDiv;
24 -}
25 -
26 -export const FIXTURE_ENTRYPOINT = {
27 - fn: useFoo,
28 - params: [{data: {cond: true, cond1: true}}],
29 - sequentialRenders: [
30 - {data: {cond: true, cond1: true}},
31 - {data: {cond: true, cond1: true}},
32 - ],
33 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-jsx.expect.md deleted
-141
@@ -1,141 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {
7 - Stringify,
8 - makeObject_Primitives,
9 - mutateAndReturn,
10 -} from 'shared-runtime';
11 -
12 -/**
13 - * In this example, the `<Stringify ... />` JSX block mutates then captures obj.
14 - * As JSX expressions freeze their values, we know that `obj` and `myDiv` cannot
15 - * be mutated past this.
16 - * This set of mutable range + scopes is an edge case because the JSX expression
17 - * references values in two scopes.
18 - * - (freeze) the result of `mutateAndReturn`
19 - * this is a mutable value with a mutable range starting at `makeObject()`
20 - * - (mutate) the lvalue storing the result of `<Stringify .../>`
21 - * this is a immutable value and so gets assigned a different scope
22 - *
23 - * obj@0 = makeObj(); ⌝ scope@0
24 - * if (cond) { |
25 - * $1@0 = mutate(obj@0); |
26 - * myDiv@1 = JSX $1@0 <- scope@1 |
27 - * } ⌟
28 - *
29 - * Coincidentally, the range of `obj` is extended by alignScopesToBlocks to *past*
30 - * the end of the JSX instruction. As we currently alias identifier mutableRanges to
31 - * scope ranges, this `freeze` reference is perceived as occurring during the mutable
32 - * range of `obj` (even though it is after the last mutating reference).
33 - *
34 - * This case is technically safe as `myDiv` correctly takes `obj` as a dependency. As
35 - * a result, developers can never observe myDiv can aliasing a different value generation
36 - * than `obj` (e.g. the invariant `myDiv.props.value === obj` always holds).
37 - */
38 -function useFoo({data}) {
39 - let obj = null;
40 - let myDiv = null;
41 - if (data.cond) {
42 - obj = makeObject_Primitives();
43 - if (data.cond1) {
44 - myDiv = <Stringify value={mutateAndReturn(obj)} />;
45 - }
46 - }
47 - return myDiv;
48 -}
49 -
50 -export const FIXTURE_ENTRYPOINT = {
51 - fn: useFoo,
52 - params: [{data: {cond: true, cond1: true}}],
53 - sequentialRenders: [
54 - {data: {cond: true, cond1: true}},
55 - {data: {cond: true, cond1: true}},
56 - ],
57 -};
58 -
59 -```
60 -
61 -## Code
62 -
63 -```javascript
64 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
65 -import {
66 - Stringify,
67 - makeObject_Primitives,
68 - mutateAndReturn,
69 -} from "shared-runtime";
70 -
71 -/**
72 - * In this example, the `<Stringify ... />` JSX block mutates then captures obj.
73 - * As JSX expressions freeze their values, we know that `obj` and `myDiv` cannot
74 - * be mutated past this.
75 - * This set of mutable range + scopes is an edge case because the JSX expression
76 - * references values in two scopes.
77 - * - (freeze) the result of `mutateAndReturn`
78 - * this is a mutable value with a mutable range starting at `makeObject()`
79 - * - (mutate) the lvalue storing the result of `<Stringify .../>`
80 - * this is a immutable value and so gets assigned a different scope
81 - *
82 - * obj@0 = makeObj(); ⌝ scope@0
83 - * if (cond) { |
84 - * $1@0 = mutate(obj@0); |
85 - * myDiv@1 = JSX $1@0 <- scope@1 |
86 - * } ⌟
87 - *
88 - * Coincidentally, the range of `obj` is extended by alignScopesToBlocks to *past*
89 - * the end of the JSX instruction. As we currently alias identifier mutableRanges to
90 - * scope ranges, this `freeze` reference is perceived as occurring during the mutable
91 - * range of `obj` (even though it is after the last mutating reference).
92 - *
93 - * This case is technically safe as `myDiv` correctly takes `obj` as a dependency. As
94 - * a result, developers can never observe myDiv can aliasing a different value generation
95 - * than `obj` (e.g. the invariant `myDiv.props.value === obj` always holds).
96 - */
97 -function useFoo(t0) {
98 - const $ = _c(5);
99 - const { data } = t0;
100 - let obj;
101 - let myDiv = null;
102 - if (data.cond) {
103 - if ($[0] !== data.cond1) {
104 - obj = makeObject_Primitives();
105 - if (data.cond1) {
106 - const t1 = mutateAndReturn(obj);
107 - let t2;
108 - if ($[3] !== t1) {
109 - t2 = <Stringify value={t1} />;
110 - $[3] = t1;
111 - $[4] = t2;
112 - } else {
113 - t2 = $[4];
114 - }
115 - myDiv = t2;
116 - }
117 - $[0] = data.cond1;
118 - $[1] = obj;
119 - $[2] = myDiv;
120 - } else {
121 - obj = $[1];
122 - myDiv = $[2];
123 - }
124 - }
125 - return myDiv;
126 -}
127 -
128 -export const FIXTURE_ENTRYPOINT = {
129 - fn: useFoo,
130 - params: [{ data: { cond: true, cond1: true } }],
131 - sequentialRenders: [
132 - { data: { cond: true, cond1: true } },
133 - { data: { cond: true, cond1: true } },
134 - ],
135 -};
136 -
137 -```
138 -
139 -### Eval output
140 -(kind: ok) <div>{"value":{"a":0,"b":"value1","c":true,"wat0":"joe"}}</div>
141 -<div>{"value":{"a":0,"b":"value1","c":true,"wat0":"joe"}}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-jsx.tsx deleted
-53
@@ -1,53 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {
3 - Stringify,
4 - makeObject_Primitives,
5 - mutateAndReturn,
6 -} from 'shared-runtime';
7 -
8 -/**
9 - * In this example, the `<Stringify ... />` JSX block mutates then captures obj.
10 - * As JSX expressions freeze their values, we know that `obj` and `myDiv` cannot
11 - * be mutated past this.
12 - * This set of mutable range + scopes is an edge case because the JSX expression
13 - * references values in two scopes.
14 - * - (freeze) the result of `mutateAndReturn`
15 - * this is a mutable value with a mutable range starting at `makeObject()`
16 - * - (mutate) the lvalue storing the result of `<Stringify .../>`
17 - * this is a immutable value and so gets assigned a different scope
18 - *
19 - * obj@0 = makeObj(); ⌝ scope@0
20 - * if (cond) { |
21 - * $1@0 = mutate(obj@0); |
22 - * myDiv@1 = JSX $1@0 <- scope@1 |
23 - * } ⌟
24 - *
25 - * Coincidentally, the range of `obj` is extended by alignScopesToBlocks to *past*
26 - * the end of the JSX instruction. As we currently alias identifier mutableRanges to
27 - * scope ranges, this `freeze` reference is perceived as occurring during the mutable
28 - * range of `obj` (even though it is after the last mutating reference).
29 - *
30 - * This case is technically safe as `myDiv` correctly takes `obj` as a dependency. As
31 - * a result, developers can never observe myDiv can aliasing a different value generation
32 - * than `obj` (e.g. the invariant `myDiv.props.value === obj` always holds).
33 - */
34 -function useFoo({data}) {
35 - let obj = null;
36 - let myDiv = null;
37 - if (data.cond) {
38 - obj = makeObject_Primitives();
39 - if (data.cond1) {
40 - myDiv = <Stringify value={mutateAndReturn(obj)} />;
41 - }
42 - }
43 - return myDiv;
44 -}
45 -
46 -export const FIXTURE_ENTRYPOINT = {
47 - fn: useFoo,
48 - params: [{data: {cond: true, cond1: true}}],
49 - sequentialRenders: [
50 - {data: {cond: true, cond1: true}},
51 - {data: {cond: true, cond1: true}},
52 - ],
53 -};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/repro-allocating-ternary-test-instruction-scope.expect.md deleted
-61
@@ -1,61 +0,0 @@
1 -
2 -## Input
3 -
4 -```javascript
5 -// @enableReactiveScopesInHIR:false
6 -import {identity, makeObject_Primitives} from 'shared-runtime';
7 -
8 -function useTest({cond}) {
9 - const val = makeObject_Primitives();
10 -
11 - useHook();
12 - /**
13 - * We don't technically need a reactive scope for this ternary as
14 - * it cannot produce newly allocated values.
15 - * While identity(...) may allocate, we can teach the compiler that
16 - * its result is only used as as a test condition
17 - */
18 - const result = identity(cond) ? val : null;
19 - return result;
20 -}
21 -
22 -export const FIXTURE_ENTRYPOINT = {
23 - fn: useTest,
24 - params: [{cond: true}],
25 -};
26 -
27 -```
28 -
29 -## Code
30 -
31 -```javascript
32 -import { c as _c } from "react/compiler-runtime"; // @enableReactiveScopesInHIR:false
33 -import { identity, makeObject_Primitives } from "shared-runtime";
34 -
35 -function useTest(t0) {
36 - const $ = _c(1);
37 - const { cond } = t0;
38 - let t1;
39 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
40 - t1 = makeObject_Primitives();
41 - $[0] = t1;
42 - } else {
43 - t1 = $[0];
44 - }
45 - const val = t1;
46 -
47 - useHook();
48 -
49 - const result = identity(cond) ? val : null;
50 - return result;
51 -}
52 -
53 -export const FIXTURE_ENTRYPOINT = {
54 - fn: useTest,
55 - params: [{ cond: true }],
56 -};
57 -
58 -```
59 -
60 -### Eval output
61 -(kind: exception) useHook is not defined
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/repro-allocating-ternary-test-instruction-scope.ts deleted
-21
@@ -1,21 +0,0 @@
1 -// @enableReactiveScopesInHIR:false
2 -import {identity, makeObject_Primitives} from 'shared-runtime';
3 -
4 -function useTest({cond}) {
5 - const val = makeObject_Primitives();
6 -
7 - useHook();
8 - /**
9 - * We don't technically need a reactive scope for this ternary as
10 - * it cannot produce newly allocated values.
11 - * While identity(...) may allocate, we can teach the compiler that
12 - * its result is only used as as a test condition
13 - */
14 - const result = identity(cond) ? val : null;
15 - return result;
16 -}
17 -
18 -export const FIXTURE_ENTRYPOINT = {
19 - fn: useTest,
20 - params: [{cond: true}],
21 -};