diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index 4f0db335aa..15441ed018 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -522,3 +522,7 @@ function objectTypeEquals(tA: Type, tB: Type): boolean { function funcTypeEquals(tA: Type, tB: Type): boolean { return tA.kind === "Function" && tB.kind === "Function"; } + +export function isObjectType(id: Identifier): boolean { + return id.type.kind === "Object"; +} diff --git a/compiler/forget/src/HIR/InferReferenceEffects.ts b/compiler/forget/src/HIR/InferReferenceEffects.ts index 82f83a23e9..d055726331 100644 --- a/compiler/forget/src/HIR/InferReferenceEffects.ts +++ b/compiler/forget/src/HIR/InferReferenceEffects.ts @@ -14,6 +14,7 @@ import { HIRFunction, IdentifierId, InstructionValue, + isObjectType, Phi, Place, ValueKind, @@ -585,12 +586,14 @@ function inferBlock(env: Environment, block: BasicBlock) { // redefine lvalue: `a = b.c.d` env.initialize(instrValue, env.kind(instrValue)); env.define(lvalue.place, instrValue); - } else if (instrValue.memberPath === null) { - // no-op: `a.b.c = d` - env.reference(lvalue.place, Effect.Store); } else { + // no-op: `a.b.c = d` + // or // no-op: `a.b.c = d.e.f` - env.reference(lvalue.place, Effect.Store); + const effect = isObjectType(lvalue.place.identifier) + ? Effect.Store + : Effect.Mutate; + env.reference(lvalue.place, effect); } } continue; diff --git a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md index 93a6fce6ee..a65ad7961e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md @@ -63,8 +63,8 @@ function f$0() { ``` bb0: [1] Const mutate $6:TPrimitive = 1 - [2] Const mutate $7_@0:TPrimitive[0:6] = Binary read a$5_@0.b.c + read $6:TPrimitive - [3] Reassign store a$5_@0.b.c[0:6] = read $7_@0:TPrimitive + [2] Const mutate $7:TPrimitive = Binary read a$5_@0.b.c + read $6:TPrimitive + [3] Reassign read a$5_@0.b.c[0:6] = read $7:TPrimitive [4] Const mutate $8:TPrimitive = 2 [5] Reassign mutate a$5_@0.b.c[0:6] = Binary read a$5_@0.b.c * read $8:TPrimitive [6] Return @@ -77,8 +77,8 @@ function g( a, ) { [1] Const mutate $6:TPrimitive = 1 - [2] Const mutate $7_@0:TPrimitive[0:6] = Binary read a$5_@0.b.c + read $6:TPrimitive - [3] Reassign store a$5_@0.b.c[0:6] = read $7_@0:TPrimitive + [2] Const mutate $7:TPrimitive = Binary read a$5_@0.b.c + read $6:TPrimitive + [3] Reassign read a$5_@0.b.c[0:6] = read $7:TPrimitive [4] Const mutate $8:TPrimitive = 2 [5] Reassign mutate a$5_@0.b.c[0:6] = Binary read a$5_@0.b.c * read $8:TPrimitive return