Skip to content

Commit b7386dd

Browse files
committed
[compiler] Visit nested scopes in pruned scopes in PromoteUsedTemporaries
While debugging #30536 I happened to notice that the bug only reproduced when there was interleaving scopes, and observed that an unpruned scope nested inside of a pruned one was not being visited by CollectPromotableTemporaries, which keeps track of which identifiers should be promoted later. Therefore when actually promoting temporaries we were skipping over the identifiers in children of pruned scopes ghstack-source-id: d805f62 Pull Request resolved: #30537
1 parent edfaa99 commit b7386dd

File tree

5 files changed

+104
-137
lines changed

5 files changed

+104
-137
lines changed

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class CollectPromotableTemporaries extends ReactiveFunctionVisitor<State> {
138138
usedOutsideScope: false,
139139
});
140140
}
141+
this.visitBlock(scopeBlock.instructions, state);
141142
}
142143

143144
override visitScope(scopeBlock: ReactiveScopeBlock, state: State): void {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-renaming-jsx-tag-lowercase.expect.md

Lines changed: 0 additions & 107 deletions
This file was deleted.

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-renaming-jsx-tag-lowercase.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
## Input
3+
4+
```javascript
5+
import {Stringify, identity, useIdentity} from 'shared-runtime';
6+
7+
function Foo({}) {
8+
const x = {};
9+
const y = {};
10+
useIdentity(0);
11+
return (
12+
<>
13+
<Stringify value={identity(y)} />
14+
<Stringify value={identity(x)} />
15+
</>
16+
);
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";
30+
import { Stringify, identity, useIdentity } from "shared-runtime";
31+
32+
function Foo(t0) {
33+
const $ = _c(9);
34+
const x = {};
35+
const y = {};
36+
useIdentity(0);
37+
38+
const T0 = Stringify;
39+
const t1 = identity(y);
40+
let t2;
41+
if ($[0] !== T0 || $[1] !== t1) {
42+
t2 = <T0 value={t1} />;
43+
$[0] = T0;
44+
$[1] = t1;
45+
$[2] = t2;
46+
} else {
47+
t2 = $[2];
48+
}
49+
const T1 = Stringify;
50+
const t3 = identity(x);
51+
let t4;
52+
if ($[3] !== T1 || $[4] !== t3) {
53+
t4 = <T1 value={t3} />;
54+
$[3] = T1;
55+
$[4] = t3;
56+
$[5] = t4;
57+
} else {
58+
t4 = $[5];
59+
}
60+
let t5;
61+
if ($[6] !== t2 || $[7] !== t4) {
62+
t5 = (
63+
<>
64+
{t2}
65+
{t4}
66+
</>
67+
);
68+
$[6] = t2;
69+
$[7] = t4;
70+
$[8] = t5;
71+
} else {
72+
t5 = $[8];
73+
}
74+
return t5;
75+
}
76+
77+
export const FIXTURE_ENTRYPOINT = {
78+
fn: Foo,
79+
params: [{}],
80+
};
81+
82+
```
83+
84+
### Eval output
85+
(kind: ok) <div>{"value":{}}</div><div>{"value":{}}</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {Stringify, identity, useIdentity} from 'shared-runtime';
2+
3+
function Foo({}) {
4+
const x = {};
5+
const y = {};
6+
useIdentity(0);
7+
return (
8+
<>
9+
<Stringify value={identity(y)} />
10+
<Stringify value={identity(x)} />
11+
</>
12+
);
13+
}
14+
15+
export const FIXTURE_ENTRYPOINT = {
16+
fn: Foo,
17+
params: [{}],
18+
};

0 commit comments

Comments
 (0)