@samitouri / QOS-React-2 / commits / de6afc2c52

[ssa] Update lvalue based on whether it has a memberPath or not

The semantics of lvalue changes based on whether lvalue.place.memberPath is null or not. If it's null, then lvalue.place acts as the lvalue for the instruction, otherwise it's just a reference to the memberPath specified location. Ideally we'd have an MemberExpression IR that lowers this complex lvalue into a temporary Place, uses this temporary place and stores back to the MemberExpression. Working around for now, will refactor to create a MemberExpression in the future if necessary for other analysis.

Sathya Gunasekaran committed Oct 27, 2022 at 14:11 UTC de6afc2c52c41eb412f4972226a7f2719fdb2344
2 files changed +10 -5
compiler/forget/src/HIR/SSAify.ts
+6 -1
@@ -174,7 +174,12 @@ export default function buildSSA(func: HIRFunction, env: Environment) {
174
175 if (instr.lvalue != null) {
176 const oldPlace = instr.lvalue.place;
177 - const newPlace: Place = builder.definePlace(oldPlace);
177 + let newPlace: Place;
178 + if (oldPlace.memberPath !== null) {
179 + newPlace = builder.getPlace(oldPlace);
180 + } else {
181 + newPlace = builder.definePlace(oldPlace);
182 + }
183 instr.lvalue.place = newPlace;
184 }
185 }
compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md
+4 -4
@@ -17,8 +17,8 @@ function foo() {
17 bb0:
18 Const mutate x$3 = Array []
19 Const mutate y$4 = Object { }
20 - Reassign mutate y$5.x = read x$3
21 - Return freeze y$5
20 + Reassign mutate y$4.x = read x$3
21 + Return freeze y$4
22 ```
23
24 ## Code
@@ -27,8 +27,8 @@ bb0:
27 function foo$0() {
28 const x$3 = [];
29 const y$4 = {};
30 - y$5 = x$3;
31 - return y$5;
30 + y$4 = x$3;
31 + return y$4;
32 }
33
34 ```