Skip to content

Commit 7603b48

Browse files
committed
[compiler] Enable new inference by default
1 parent 3096f19 commit 7603b48

25 files changed

+277
-203
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export const EnvironmentConfigSchema = z.object({
246246
/**
247247
* Enable a new model for mutability and aliasing inference
248248
*/
249-
enableNewMutationAliasingModel: z.boolean().default(false),
249+
enableNewMutationAliasingModel: z.boolean().default(true),
250250

251251
/**
252252
* Enables inference of optional dependency chains. Without this flag

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/aliased-nested-scope-truncated-dep.expect.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,14 @@ import {
175175
* and mutability.
176176
*/
177177
function Component(t0) {
178-
const $ = _c(4);
178+
const $ = _c(2);
179179
const { prop } = t0;
180180
let t1;
181181
if ($[0] !== prop) {
182182
const obj = shallowCopy(prop);
183183
const aliasedObj = identity(obj);
184-
let t2;
185-
if ($[2] !== obj) {
186-
t2 = [obj.id];
187-
$[2] = obj;
188-
$[3] = t2;
189-
} else {
190-
t2 = $[3];
191-
}
192-
const id = t2;
184+
185+
const id = [obj.id];
193186

194187
mutate(aliasedObj);
195188
setPropertyByKey(aliasedObj, "id", prop.id + 1);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-alias-computed-load-2-iife.expect.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ export const FIXTURE_ENTRYPOINT = {
2525
```javascript
2626
import { c as _c } from "react/compiler-runtime";
2727
function bar(a) {
28-
const $ = _c(2);
29-
let y;
28+
const $ = _c(4);
29+
let t0;
3030
if ($[0] !== a) {
31-
const x = [a];
31+
t0 = [a];
32+
$[0] = a;
33+
$[1] = t0;
34+
} else {
35+
t0 = $[1];
36+
}
37+
const x = t0;
38+
let y;
39+
if ($[2] !== x[0][1]) {
3240
y = {};
3341

3442
y = x[0][1];
35-
$[0] = a;
36-
$[1] = y;
43+
$[2] = x[0][1];
44+
$[3] = y;
3745
} else {
38-
y = $[1];
46+
y = $[3];
3947
}
4048
return y;
4149
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-alias-computed-load-3-iife.expect.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,29 @@ export const FIXTURE_ENTRYPOINT = {
2929
```javascript
3030
import { c as _c } from "react/compiler-runtime";
3131
function bar(a, b) {
32-
const $ = _c(3);
33-
let y;
32+
const $ = _c(6);
33+
let t0;
3434
if ($[0] !== a || $[1] !== b) {
35-
const x = [a, b];
35+
t0 = [a, b];
36+
$[0] = a;
37+
$[1] = b;
38+
$[2] = t0;
39+
} else {
40+
t0 = $[2];
41+
}
42+
const x = t0;
43+
let y;
44+
if ($[3] !== x[0][1] || $[4] !== x[1][0]) {
3645
y = {};
3746
let t = {};
3847

3948
y = x[0][1];
4049
t = x[1][0];
41-
$[0] = a;
42-
$[1] = b;
43-
$[2] = y;
50+
$[3] = x[0][1];
51+
$[4] = x[1][0];
52+
$[5] = y;
4453
} else {
45-
y = $[2];
54+
y = $[5];
4655
}
4756
return y;
4857
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-alias-computed-load-4-iife.expect.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ export const FIXTURE_ENTRYPOINT = {
2525
```javascript
2626
import { c as _c } from "react/compiler-runtime";
2727
function bar(a) {
28-
const $ = _c(2);
29-
let y;
28+
const $ = _c(4);
29+
let t0;
3030
if ($[0] !== a) {
31-
const x = [a];
31+
t0 = [a];
32+
$[0] = a;
33+
$[1] = t0;
34+
} else {
35+
t0 = $[1];
36+
}
37+
const x = t0;
38+
let y;
39+
if ($[2] !== x[0].a[1]) {
3240
y = {};
3341

3442
y = x[0].a[1];
35-
$[0] = a;
36-
$[1] = y;
43+
$[2] = x[0].a[1];
44+
$[3] = y;
3745
} else {
38-
y = $[1];
46+
y = $[3];
3947
}
4048
return y;
4149
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-alias-computed-load-iife.expect.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,25 @@ export const FIXTURE_ENTRYPOINT = {
2424
```javascript
2525
import { c as _c } from "react/compiler-runtime";
2626
function bar(a) {
27-
const $ = _c(2);
28-
let y;
27+
const $ = _c(4);
28+
let t0;
2929
if ($[0] !== a) {
30-
const x = [a];
30+
t0 = [a];
31+
$[0] = a;
32+
$[1] = t0;
33+
} else {
34+
t0 = $[1];
35+
}
36+
const x = t0;
37+
let y;
38+
if ($[2] !== x[0]) {
3139
y = {};
3240

3341
y = x[0];
34-
$[0] = a;
35-
$[1] = y;
42+
$[2] = x[0];
43+
$[3] = y;
3644
} else {
37-
y = $[1];
45+
y = $[3];
3846
}
3947
return y;
4048
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-impure-functions-in-render.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Component() {
2020
2 |
2121
3 | function Component() {
2222
> 4 | const date = Date.now();
23-
| ^^^^^^^^ InvalidReact: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent). `Date.now` is an impure function whose results may change on every call (4:4)
23+
| ^^^^^^^^^^ InvalidReact: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent). `Date.now` is an impure function whose results may change on every call (4:4)
2424
2525
InvalidReact: Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent). `performance.now` is an impure function whose results may change on every call (5:5)
2626

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-non-imported-reanimated-shared-value-writes.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function SomeComponent() {
2727
9 | return (
2828
10 | <Button
2929
> 11 | onPress={() => (sharedVal.value = Math.random())}
30-
| ^^^^^^^^^ InvalidReact: Mutating a value returned from a function whose return value should not be mutated. Found mutation of `sharedVal` (11:11)
30+
| ^^^^^^^^^ InvalidReact: This mutates a variable that React considers immutable. Found mutation of `sharedVal` (11:11)
3131
12 | title="Randomize"
3232
13 | />
3333
14 | );

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.mutate-hook-argument.expect.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function useHook(a, b) {
1616
1 | function useHook(a, b) {
1717
> 2 | b.test = 1;
1818
| ^ InvalidReact: Mutating component props or hook arguments is not allowed. Consider using a local variable instead (2:2)
19+
20+
InvalidReact: Mutating component props or hook arguments is not allowed. Consider using a local variable instead (3:3)
1921
3 | a.test = 2;
2022
4 | }
2123
5 |

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.not-useEffect-external-mutate.expect.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function Component(props) {
2121
4 | foo(() => {
2222
> 5 | x.a = 10;
2323
| ^ InvalidReact: Writing to a variable defined outside a component or hook is not allowed. Consider using an effect (5:5)
24+
25+
InvalidReact: Writing to a variable defined outside a component or hook is not allowed. Consider using an effect (6:6)
2426
6 | x.a = 20;
2527
7 | });
2628
8 | }

0 commit comments

Comments
 (0)