From de6afc2c52c41eb412f4972226a7f2719fdb2344 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 27 Oct 2022 14:11:23 +0100 Subject: [PATCH] [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. --- compiler/forget/src/HIR/SSAify.ts | 7 ++++++- .../src/__tests__/fixtures/hir/ssa-property.expect.md | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compiler/forget/src/HIR/SSAify.ts b/compiler/forget/src/HIR/SSAify.ts index a3965d55c0..94828557e0 100644 --- a/compiler/forget/src/HIR/SSAify.ts +++ b/compiler/forget/src/HIR/SSAify.ts @@ -174,7 +174,12 @@ export default function buildSSA(func: HIRFunction, env: Environment) { if (instr.lvalue != null) { const oldPlace = instr.lvalue.place; - const newPlace: Place = builder.definePlace(oldPlace); + let newPlace: Place; + if (oldPlace.memberPath !== null) { + newPlace = builder.getPlace(oldPlace); + } else { + newPlace = builder.definePlace(oldPlace); + } instr.lvalue.place = newPlace; } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md index 3626057353..d3cc631513 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md @@ -17,8 +17,8 @@ function foo() { bb0: Const mutate x$3 = Array [] Const mutate y$4 = Object { } - Reassign mutate y$5.x = read x$3 - Return freeze y$5 + Reassign mutate y$4.x = read x$3 + Return freeze y$4 ``` ## Code @@ -27,8 +27,8 @@ bb0: function foo$0() { const x$3 = []; const y$4 = {}; - y$5 = x$3; - return y$5; + y$4 = x$3; + return y$4; } ```