[ssa] Fix lookup of global values
Currently, HIR doesn't load global idenfifiers into a temporary Place which means our SSA transform breaks when it tries to lookup this global identifier. Instead of throwing, let's log and return the old place. This works for now but will probably break when we start mutating globals, but at that point our HIR builder will need fixes.
Sathya Gunasekaran committed
Oct 24, 2022 at 16:04 UTC
34e02dab326cad40c3d2850e7e7de429f1dec973
5 files changed
+139
-1
compiler/forget/src/HIR/SSAify.ts
+5
-1
@@ -12,6 +12,7 @@ import {
12
Place,
13
} from "./HIR";
14
import { Environment } from "./HIRBuilder";
15
+import { printPlace } from "./PrintHIR";
16
17
type IncompletePhi = {
18
old: Place;
@@ -94,7 +95,10 @@ class SSABuilder {
95
96
if (block.preds.size == 0) {
97
// We're at the entry block and haven't found our defintion yet.
97
- throw new Error(`Unable to find \$${oldPlace.identifier.id}`);
98
+ console.log(
99
+ `Unable to find "${printPlace(oldPlace)}", assuming it's a global`
100
+ );
101
+ //return oldPlace;
102
}
103
104
if (unsealedPreds.get(block)! > 0) {
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md
new
+63
@@ -0,0 +1,63 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function foo() {}
6
+
7
+function Component(props) {
8
+ const a = [];
9
+ const b = {};
10
+ foo(a, b);
11
+ let _ = <div a={a} />;
12
+ foo(b);
13
+ return <div a={a} b={b} />;
14
+}
15
+
16
+```
17
+
18
+## HIR
19
+
20
+```
21
+bb0:
22
+ Return
23
+```
24
+
25
+## Code
26
+
27
+```javascript
28
+function foo$0() {
29
+ return;
30
+}
31
+
32
+```
33
+## HIR
34
+
35
+```
36
+bb0:
37
+ Const mutate foo$11: phi()
38
+ Const mutate a$9 = Array []
39
+ Const mutate b$10 = Object { }
40
+ Call mutate foo$11(mutate a$9, mutate b$10)
41
+ Const mutate $12 = "div"
42
+ Let mutate _$13 = JSX <mutate $12 a={mutate a$9} ></mutate $12>
43
+ Call mutate foo$11(mutate b$10)
44
+ Const mutate $14 = "div"
45
+ Const mutate $15 = JSX <mutate $14 a={mutate a$9} b={mutate b$10} ></mutate $14>
46
+ Return mutate $15
47
+```
48
+
49
+## Code
50
+
51
+```javascript
52
+function Component$0(props$1) {
53
+ const a$9 = [];
54
+ const b$10 = {};
55
+ foo$11(a$9, b$10);
56
+ let _$13 = <div a={a$9}></div>;
57
+
58
+ foo$11(b$10);
59
+ return <div a={a$9} b={b$10}></div>;
60
+}
61
+
62
+```
63
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.js
new
+10
@@ -0,0 +1,10 @@
1
+function foo() {}
2
+
3
+function Component(props) {
4
+ const a = [];
5
+ const b = {};
6
+ foo(a, b);
7
+ let _ = <div a={a} />;
8
+ foo(b);
9
+ return <div a={a} b={b} />;
10
+}
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md
new
+53
@@ -0,0 +1,53 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Foo() {}
6
+
7
+function Component(props) {
8
+ const a = [];
9
+ const b = {};
10
+ let c = new Foo(a, b);
11
+ return c;
12
+}
13
+
14
+```
15
+
16
+## HIR
17
+
18
+```
19
+bb0:
20
+ Return
21
+```
22
+
23
+## Code
24
+
25
+```javascript
26
+function Foo$0() {
27
+ return;
28
+}
29
+
30
+```
31
+## HIR
32
+
33
+```
34
+bb0:
35
+ Const mutate Foo$8: phi()
36
+ Const mutate a$6 = Array []
37
+ Const mutate b$7 = Object { }
38
+ Let mutate c$9 = New mutate Foo$8(mutate a$6, mutate b$7)
39
+ Return mutate c$9
40
+```
41
+
42
+## Code
43
+
44
+```javascript
45
+function Component$0(props$1) {
46
+ const a$6 = [];
47
+ const b$7 = {};
48
+ let c$9 = new Foo$8(a$6, b$7);
49
+ return c$9;
50
+}
51
+
52
+```
53
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.js
new
+8
@@ -0,0 +1,8 @@
1
+function Foo() {}
2
+
3
+function Component(props) {
4
+ const a = [];
5
+ const b = {};
6
+ let c = new Foo(a, b);
7
+ return c;
8
+}