-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Fix mode for generating scopes for reassignments
We have an experimental mode where we generate scopes for simple phi values, even if they aren't subsequently mutated. This mode was incorrectly generating scope ranges, leaving the start at 0 which is invalid. The fix is to allow non-zero identifier ranges to overwrite the scope start (rather than taking the min) if the scope start is still zero. ghstack-source-id: ecbb04c96ed4de62f781e48cda46309c42aa07e0 Pull Request resolved: #30321
- Loading branch information
1 parent
1f60a41
commit 2683c0a
Showing
3 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ts__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableForest | ||
function Component({ base, start, increment, test }) { | ||
let value = base; | ||
for (let i = start; i < test; i += increment) { | ||
value += i; | ||
} | ||
return <div>{value}</div>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ base: 0, start: 0, test: 10, increment: 1 }], | ||
sequentialRenders: [ | ||
{ base: 0, start: 1, test: 10, increment: 1 }, | ||
{ base: 0, start: 0, test: 10, increment: 2 }, | ||
{ base: 2, start: 0, test: 10, increment: 2 }, | ||
{ base: 0, start: 0, test: 11, increment: 2 }, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enableForest | ||
function Component(t0) { | ||
const $ = _c(5); | ||
const { base, start, increment, test } = t0; | ||
let value; | ||
if ($[0] !== base || $[1] !== start || $[2] !== test || $[3] !== increment) { | ||
value = base; | ||
for (let i = start; i < test; i = i + increment, i) { | ||
value = value + i; | ||
} | ||
$[0] = base; | ||
$[1] = start; | ||
$[2] = test; | ||
$[3] = increment; | ||
$[4] = value; | ||
} else { | ||
value = $[4]; | ||
} | ||
return <div>{value}</div>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ base: 0, start: 0, test: 10, increment: 1 }], | ||
sequentialRenders: [ | ||
{ base: 0, start: 1, test: 10, increment: 1 }, | ||
{ base: 0, start: 0, test: 10, increment: 2 }, | ||
{ base: 2, start: 0, test: 10, increment: 2 }, | ||
{ base: 0, start: 0, test: 11, increment: 2 }, | ||
], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>45</div> | ||
<div>20</div> | ||
<div>22</div> | ||
<div>30</div> |
19 changes: 19 additions & 0 deletions
19
...ompiler/src/__tests__/fixtures/compiler/primitive-reassigned-loop-force-scopes-enabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @enableForest | ||
function Component({ base, start, increment, test }) { | ||
let value = base; | ||
for (let i = start; i < test; i += increment) { | ||
value += i; | ||
} | ||
return <div>{value}</div>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ base: 0, start: 0, test: 10, increment: 1 }], | ||
sequentialRenders: [ | ||
{ base: 0, start: 1, test: 10, increment: 1 }, | ||
{ base: 0, start: 0, test: 10, increment: 2 }, | ||
{ base: 2, start: 0, test: 10, increment: 2 }, | ||
{ base: 0, start: 0, test: 11, increment: 2 }, | ||
], | ||
}; |