@samitouri / QOS-React / commits / 15104ab21b

[ssa] Infer arguments of a function

Sathya Gunasekaran committed Oct 27, 2022 at 15:16 UTC 15104ab21bcc4848fdb5be5c1773ced5ecabf41f
5 files changed +51 -46
compiler/forget/src/HIR/SSAify.ts
+5
@@ -173,6 +173,11 @@ export default function buildSSA(func: HIRFunction, env: Environment) {
173 builder.visitedBlocks.add(block);
174
175 builder.startBlock(block);
176 +
177 + if (func.body.entry === blockId) {
178 + func.params = func.params.map((p) => builder.definePlace(p));
179 + }
180 +
181 for (const instr of block.instructions) {
182 rewriteUses(instr, builder);
183
compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md
+9 -9
@@ -15,20 +15,20 @@ function Component(props) {
15
16 ```
17 bb0:
18 - Const mutate a$5 = 1
19 - Const mutate b$6 = 2
20 - Const mutate x$7 = Array [read a$5, read b$6]
21 - Return freeze x$7
18 + Const mutate a$6 = 1
19 + Const mutate b$7 = 2
20 + Const mutate x$8 = Array [read a$6, read b$7]
21 + Return freeze x$8
22 ```
23
24 ## Code
25
26 ```javascript
27 -function Component$0(props$1) {
28 - const a$5 = 1;
29 - const b$6 = 2;
30 - const x$7 = [a$5, b$6];
31 - return x$7;
27 +function Component$0(props$5) {
28 + const a$6 = 1;
29 + const b$7 = 2;
30 + const x$8 = [a$6, b$7];
31 + return x$8;
32 }
33
34 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md
+17 -17
@@ -34,28 +34,28 @@ function foo$0() {
34
35 ```
36 bb0:
37 - Const mutate a$9 = Array []
38 - Const mutate b$10 = Object { }
39 - Call mutate foo$4(mutate a$9, mutate b$10)
40 - Const mutate $11 = "div"
41 - Let mutate _$12 = JSX <read $11 a={freeze a$9} ></read $11>
42 - Call mutate foo$4(mutate b$10)
43 - Const mutate $13 = "div"
44 - Const mutate $14 = JSX <read $13 a={read a$9} b={freeze b$10} ></read $13>
45 - Return read $14
37 + Const mutate a$10 = Array []
38 + Const mutate b$11 = Object { }
39 + Call mutate foo$4(mutate a$10, mutate b$11)
40 + Const mutate $12 = "div"
41 + Let mutate _$13 = JSX <read $12 a={freeze a$10} ></read $12>
42 + Call mutate foo$4(mutate b$11)
43 + Const mutate $14 = "div"
44 + Const mutate $15 = JSX <read $14 a={read a$10} b={freeze b$11} ></read $14>
45 + Return read $15
46 ```
47
48 ## Code
49
50 ```javascript
51 -function Component$0(props$1) {
52 - const a$9 = [];
53 - const b$10 = {};
54 - foo$4(a$9, b$10);
55 - let _$12 = <div a={a$9}></div>;
56 -
57 - foo$4(b$10);
58 - return <div a={a$9} b={b$10}></div>;
51 +function Component$0(props$9) {
52 + const a$10 = [];
53 + const b$11 = {};
54 + foo$4(a$10, b$11);
55 + let _$13 = <div a={a$10}></div>;
56 +
57 + foo$4(b$11);
58 + return <div a={a$10} b={b$11}></div>;
59 }
60
61 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md
+9 -9
@@ -32,20 +32,20 @@ function Foo$0() {
32
33 ```
34 bb0:
35 - Const mutate a$6 = Array []
36 - Const mutate b$7 = Object { }
37 - Let mutate c$8 = New mutate Foo$5(mutate a$6, mutate b$7)
38 - Return freeze c$8
35 + Const mutate a$7 = Array []
36 + Const mutate b$8 = Object { }
37 + Let mutate c$9 = New mutate Foo$5(mutate a$7, mutate b$8)
38 + Return freeze c$9
39 ```
40
41 ## Code
42
43 ```javascript
44 -function Component$0(props$1) {
45 - const a$6 = [];
46 - const b$7 = {};
47 - let c$8 = new Foo$5(a$6, b$7);
48 - return c$8;
44 +function Component$0(props$6) {
45 + const a$7 = [];
46 + const b$8 = {};
47 + let c$9 = new Foo$5(a$7, b$8);
48 + return c$9;
49 }
50
51 ```
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md
+11 -11
@@ -15,23 +15,23 @@ function Component(props) {
15
16 ```
17 bb0:
18 - Const mutate a$5 = 1
19 - Const mutate b$6 = 2
20 - Const mutate x$7 = Object { a: read a$5, b: read b$6 }
21 - Return freeze x$7
18 + Const mutate a$6 = 1
19 + Const mutate b$7 = 2
20 + Const mutate x$8 = Object { a: read a$6, b: read b$7 }
21 + Return freeze x$8
22 ```
23
24 ## Code
25
26 ```javascript
27 -function Component$0(props$1) {
28 - const a$5 = 1;
29 - const b$6 = 2;
30 - const x$7 = {
31 - a: a$5,
32 - b: b$6,
27 +function Component$0(props$5) {
28 + const a$6 = 1;
29 + const b$7 = 2;
30 + const x$8 = {
31 + a: a$6,
32 + b: b$7,
33 };
34 - return x$7;
34 + return x$8;
35 }
36
37 ```