-
Notifications
You must be signed in to change notification settings - Fork 46.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Fix assignment within for update expression
When converting value blocks from HIR to ReactiveFunction, we have to drop StoreLocal assignments that represent the assignment of the phi, since ReactiveFunction supports compound expressions. These StoreLocals are only present to represent the conditional assignment of the value itself - but it's also possible for the expression to have contained an assignment expression. Before, in trying to strip the first category of StoreLocal we also accidentally stripped the second category. Now we check that the assignment is for a temporary, and don't strip otherwise. ghstack-source-id: cdb81880f29d5be3313086bd9e3fcfef9db0f85e Pull Request resolved: #30067
- Loading branch information
1 parent
c21bcd6
commit 48b0da7
Showing
3 changed files
with
77 additions
and
10 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
49 changes: 49 additions & 0 deletions
49
...ompiler/src/__tests__/fixtures/compiler/for-with-assignment-as-update.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,49 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component(props) { | ||
let x = props.init; | ||
for (let i = 0; i < 100; i = i + 1) { | ||
x += i; | ||
} | ||
return [x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ init: 0 }], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component(props) { | ||
const $ = _c(2); | ||
let x = props.init; | ||
for (let i = 0; i < 100; i = i + 1) { | ||
x = x + i; | ||
} | ||
let t0; | ||
if ($[0] !== x) { | ||
t0 = [x]; | ||
$[0] = x; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ init: 0 }], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [4950] |
12 changes: 12 additions & 0 deletions
12
...el-plugin-react-compiler/src/__tests__/fixtures/compiler/for-with-assignment-as-update.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,12 @@ | ||
function Component(props) { | ||
let x = props.init; | ||
for (let i = 0; i < 100; i = i + 1) { | ||
x += i; | ||
} | ||
return [x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ init: 0 }], | ||
}; |