Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] remove invariant to account for backedges #32417

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1598,18 +1598,14 @@ function inferBlock(
break;
}
case 'LoadLocal': {
/**
* Due to backedges in the CFG, we may revisit LoadLocal lvalues
* multiple times. Unlike StoreLocal which may reassign to existing
* identifiers, LoadLocal always evaluates to store a new temporary.
* This means that we should always model LoadLocal as a Capture effect
* on the rvalue.
*/
const lvalue = instr.lvalue;
CompilerError.invariant(
!(
state.isDefined(lvalue) &&
state.kind(lvalue).kind === ValueKind.Context
),
{
reason:
'[InferReferenceEffects] Unexpected LoadLocal with context kind',
loc: lvalue.loc,
},
);
state.referenceAndRecordEffects(
freezeActions,
instrValue.place,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

## Input

```javascript
import {Stringify} from 'shared-runtime';

function Foo({userIds}) {
return (
<Stringify
fn={() => {
const arr = [];

for (const selectedUser of userIds) {
arr.push(selectedUser);
}
return arr;
}}
shouldInvokeFns={true}
/>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{userIds: [1, 2, 3]}],
sequentialRenders: [{userIds: [1, 2, 4]}],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";

function Foo(t0) {
const $ = _c(2);
const { userIds } = t0;
let t1;
if ($[0] !== userIds) {
t1 = (
<Stringify
fn={() => {
const arr = [];
for (const selectedUser of userIds) {
arr.push(selectedUser);
}
return arr;
}}
shouldInvokeFns={true}
/>
);
$[0] = userIds;
$[1] = t1;
} else {
t1 = $[1];
}
return t1;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{ userIds: [1, 2, 3] }],
sequentialRenders: [{ userIds: [1, 2, 4] }],
};

```

### Eval output
(kind: ok) <div>{"fn":{"kind":"Function","result":[1,2,4]},"shouldInvokeFns":true}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Stringify} from 'shared-runtime';

function Foo({userIds}) {
return (
<Stringify
fn={() => {
const arr = [];

for (const selectedUser of userIds) {
arr.push(selectedUser);
}
return arr;
}}
shouldInvokeFns={true}
/>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{userIds: [1, 2, 3]}],
sequentialRenders: [{userIds: [1, 2, 4]}],
};
Loading