Skip to content

Commit

Permalink
[compiler][ez] Add entrypoints to ssa fixtures
Browse files Browse the repository at this point in the history
Adds evaluator support for a few compiler test fixtures

ghstack-source-id: 202654992a9876cea59885b54a338c908e369ddb
Pull Request resolved: #30948
  • Loading branch information
mofeiZ committed Sep 12, 2024
1 parent dff5082 commit f6dcce5
Show file tree
Hide file tree
Showing 27 changed files with 413 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export const FIXTURE_ENTRYPOINT = {
```
### Eval output
(kind: ok) [[{"a":0,"b":"value1","c":true}],"[[ cyclic ref *2 ]]"]
(kind: ok) [[{"a":0,"b":"value1","c":true},"joe"],"[[ cyclic ref *2 ]]"]
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export const FIXTURE_ENTRYPOINT = {
```
### Eval output
(kind: ok) [2]
[2]
[3]
(kind: ok) [2,"joe"]
[2,"joe"]
[3,"joe"]
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ function Component(props) {

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
params: [{a: 0, b: 1, c: true, d: true}],
sequentialRenders: [
{a: 0, b: 1, c: true, d: true},
{a: 4, b: 1, c: true, d: true},
{a: 4, b: 1, c: false, d: true},
{a: 4, b: 1, c: false, d: false},
],
};

```
Expand Down Expand Up @@ -61,9 +66,19 @@ function Component(props) {

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: ["TodoAdd"],
isComponent: "TodoAdd",
params: [{ a: 0, b: 1, c: true, d: true }],
sequentialRenders: [
{ a: 0, b: 1, c: true, d: true },
{ a: 4, b: 1, c: true, d: true },
{ a: 4, b: 1, c: false, d: true },
{ a: 4, b: 1, c: false, d: false },
],
};

```
### Eval output
(kind: ok) [1,1,2]
[4,1,2]
[4,0,2]
[4,0,0]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function Component(props) {

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
params: [{a: 0, b: 1, c: true, d: true}],
sequentialRenders: [
{a: 0, b: 1, c: true, d: true},
{a: 4, b: 1, c: true, d: true},
{a: 4, b: 1, c: false, d: true},
{a: 4, b: 1, c: false, d: false},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
## Input

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

function Component(props) {
let x = [];
let y;
Expand All @@ -10,19 +12,32 @@ function Component(props) {
y = x;
}
return (
<Component>
<Stringify>
{x}
{y}
</Component>
</Stringify>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{p0: false, p1: 2}],
sequentialRenders: [
{p0: false, p1: 2},
{p0: false, p1: 2},
{p0: true, p1: 2},
{p0: true, p1: 3},
],
};

```

## Code

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

function Component(props) {
const $ = _c(2);
let t0;
Expand All @@ -35,10 +50,10 @@ function Component(props) {
}

t0 = (
<Component>
<Stringify>
{x}
{y}
</Component>
</Stringify>
);
$[0] = props;
$[1] = t0;
Expand All @@ -48,5 +63,21 @@ function Component(props) {
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ p0: false, p1: 2 }],
sequentialRenders: [
{ p0: false, p1: 2 },
{ p0: false, p1: 2 },
{ p0: true, p1: 2 },
{ p0: true, p1: 3 },
],
};

```
### Eval output
(kind: ok) <div>{"children":[[],null]}</div>
<div>{"children":[[],null]}</div>
<div>{"children":[[2],"[[ cyclic ref *2 ]]"]}</div>
<div>{"children":[[3],"[[ cyclic ref *2 ]]"]}</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Stringify} from 'shared-runtime';

function Component(props) {
let x = [];
let y;
Expand All @@ -6,9 +8,20 @@ function Component(props) {
y = x;
}
return (
<Component>
<Stringify>
{x}
{y}
</Component>
</Stringify>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{p0: false, p1: 2}],
sequentialRenders: [
{p0: false, p1: 2},
{p0: false, p1: 2},
{p0: true, p1: 2},
{p0: true, p1: 3},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
## Input

```javascript
function foo(props) {
import {mutate} from 'shared-runtime';

function useFoo(props) {
let x = [];
x.push(props.bar);
props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
mut(x);
mutate(x);
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{cond: false, foo: 2, bar: 55}],
sequentialRenders: [
{cond: false, foo: 2, bar: 55},
{cond: false, foo: 3, bar: 55},
{cond: true, foo: 3, bar: 55},
],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function foo(props) {
import { mutate } from "shared-runtime";

function useFoo(props) {
const $ = _c(2);
let x;
if ($[0] !== props) {
x = [];
x.push(props.bar);
props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
mut(x);
mutate(x);
$[0] = props;
$[1] = x;
} else {
Expand All @@ -32,5 +46,19 @@ function foo(props) {
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{ cond: false, foo: 2, bar: 55 }],
sequentialRenders: [
{ cond: false, foo: 2, bar: 55 },
{ cond: false, foo: 3, bar: 55 },
{ cond: true, foo: 3, bar: 55 },
],
};

```
### Eval output
(kind: ok) [55,"joe"]
[55,"joe"]
[3,"joe"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
function foo(props) {
import {mutate} from 'shared-runtime';

function useFoo(props) {
let x = [];
x.push(props.bar);
props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
mut(x);
mutate(x);
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [{cond: false, foo: 2, bar: 55}],
sequentialRenders: [
{cond: false, foo: 2, bar: 55},
{cond: false, foo: 3, bar: 55},
{cond: true, foo: 3, bar: 55},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
## Input

```javascript
function foo(props) {
function useFoo(props) {
let x = [];
x.push(props.bar);
props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
fn: useFoo,
params: [{cond: false, foo: 2, bar: 55}],
sequentialRenders: [
{cond: false, foo: 2, bar: 55},
{cond: false, foo: 3, bar: 55},
{cond: true, foo: 3, bar: 55},
],
};

```
Expand All @@ -21,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = {

```javascript
import { c as _c } from "react/compiler-runtime";
function foo(props) {
function useFoo(props) {
const $ = _c(4);
let x;
if ($[0] !== props.bar) {
Expand All @@ -43,10 +47,18 @@ function foo(props) {
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: ["TodoAdd"],
isComponent: "TodoAdd",
fn: useFoo,
params: [{ cond: false, foo: 2, bar: 55 }],
sequentialRenders: [
{ cond: false, foo: 2, bar: 55 },
{ cond: false, foo: 3, bar: 55 },
{ cond: true, foo: 3, bar: 55 },
],
};

```
### Eval output
(kind: ok) [55]
[55]
[3]
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
function foo(props) {
function useFoo(props) {
let x = [];
x.push(props.bar);
props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: foo,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
fn: useFoo,
params: [{cond: false, foo: 2, bar: 55}],
sequentialRenders: [
{cond: false, foo: 2, bar: 55},
{cond: false, foo: 3, bar: 55},
{cond: true, foo: 3, bar: 55},
],
};
Loading

0 comments on commit f6dcce5

Please sign in to comment.