From 5f1bebbeaeff4985b27173f6807c77aedc60b40e Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 22 Mar 2023 14:36:48 -0700 Subject: [PATCH] ComputedCall modeled as ComputedLoad + Call for order-of-evaluation semantics This is the version of @mofeiZ's change for PropertyLoad, but made to work on ComputedCall. We force the method to be evaluated in the same scope as the call in InferReactiveScopeVariables. --- compiler/forget/src/HIR/BuildHIR.ts | 16 +++++----- .../ReactiveScopes/CodegenReactiveFunction.ts | 20 ++++++++++--- .../InferReactiveScopeVariables.ts | 14 +++++++++ ...g.computed-call-evaluation-order.expect.md | 2 +- .../compiler/constant-computed.expect.md | 2 +- .../fixtures/hir/array-at-closure.expect.md | 6 ++-- .../fixtures/hir/array-at-effect.expect.md | 12 ++++---- .../hir/array-property-call.expect.md | 14 ++++----- .../fixtures/hir/array-push-effect.expect.md | 14 ++++----- ...ernary-destruction-with-mutation.expect.md | 22 +++++++------- ...ssa-renaming-ternary-destruction.expect.md | 22 +++++++------- ...a-renaming-ternary-with-mutation.expect.md | 22 +++++++------- .../hir/ssa-renaming-ternary.expect.md | 22 +++++++------- ...onditional-ternary-with-mutation.expect.md | 30 +++++++++---------- ...a-renaming-unconditional-ternary.expect.md | 30 +++++++++---------- ...ming-unconditional-with-mutation.expect.md | 24 +++++++-------- 16 files changed, 149 insertions(+), 123 deletions(-) diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index a7adc007b1..1817f1ef7e 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -927,15 +927,15 @@ function lowerExpression( } if (calleePath.isMemberExpression()) { const memberExpr = lowerMemberExpression(builder, calleePath); + const propertyPlace = buildTemporaryPlace(builder, GeneratedSource); + builder.push({ + id: makeInstructionId(0), + lvalue: { ...propertyPlace }, + value: memberExpr.value, + loc: GeneratedSource, + }); const args = lowerArguments(builder, expr.get("arguments")); if (typeof memberExpr.property === "string") { - const propertyPlace = buildTemporaryPlace(builder, GeneratedSource); - builder.push({ - id: makeInstructionId(0), - lvalue: { ...propertyPlace }, - value: memberExpr.value, - loc: GeneratedSource, - }); return { kind: "PropertyCall", receiver: memberExpr.object, @@ -947,7 +947,7 @@ function lowerExpression( return { kind: "ComputedCall", receiver: memberExpr.object, - property: memberExpr.property, + property: { ...propertyPlace }, args, loc: exprLoc, }; diff --git a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts index 5354b1ced3..d1f0782efe 100644 --- a/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -613,11 +613,23 @@ function codegenInstructionValue( break; } case "ComputedCall": { - const receiver = codegenPlace(cx, instrValue.receiver); - const property = codegenPlace(cx, instrValue.property); - const callee = t.memberExpression(receiver, property, true); + const memberExpr = codegenPlace(cx, instrValue.property); + invariant( + t.isMemberExpression(memberExpr) || + t.isOptionalMemberExpression(memberExpr), + "[Codegen] Internal error: ComputedCall::property must be an unpromoted + unmemoized MemberExpression, was %s.", + memberExpr.type + ); + invariant( + t.isNodesEquivalent( + memberExpr.object, + codegenPlace(cx, instrValue.receiver) + ), + "[Codegen] Internal error: Forget should always generate ComputedCall::property " + + "as a MemberExpression of ComputedCall::receiver" + ); const args = instrValue.args.map((arg) => codegenArgument(cx, arg)); - value = createCallExpression(instrValue.loc, callee, args); + value = createCallExpression(instrValue.loc, memberExpr, args); break; } case "NewExpression": { diff --git a/compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts b/compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts index a218b0a12d..82d98ed86b 100644 --- a/compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts +++ b/compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts @@ -134,6 +134,20 @@ export function inferReactiveScopeVariables(fn: HIRFunction): void { ) { operands.push(instr.value.value.identifier); } + } else if (instr.value.kind === "ComputedCall") { + for (const operand of eachInstructionOperand(instr)) { + if ( + isMutable(instr, operand) && + // exclude global variables from being added to scopes, we can't recreate them! + // TODO: improve handling of module-scoped variables and globals + operand.identifier.mutableRange.start > 0 + ) { + operands.push(operand.identifier); + } + } + // Ensure that the ComputedLoad to resolve the method is in the same scope as the + // call itself + operands.push(instr.value.property.identifier); } else { for (const operand of eachInstructionOperand(instr)) { if ( diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md index b57f25aa94..178d7de69e 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md @@ -38,7 +38,7 @@ function Component() { console.log("B"); changeF(x); console.log("arg"); - x["f"](1); + x.f(1); $[0] = x; } else { x = $[0]; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/constant-computed.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/constant-computed.expect.md index c239691451..3ab3c2f61e 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/constant-computed.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/constant-computed.expect.md @@ -22,7 +22,7 @@ function Component(props) { if (c_0) { x = {}; x.foo = x.foo + x.bar; - x["foo"](props.foo); + x.foo(props.foo); $[0] = props.foo; $[1] = x; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/array-at-closure.expect.md b/compiler/forget/src/__tests__/fixtures/hir/array-at-closure.expect.md index 77f0a86519..26e4a16676 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/array-at-closure.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/array-at-closure.expect.md @@ -33,9 +33,9 @@ bb0 (block): [4] store $52:TObject = Array [...capture $51] [5] store $54:TObject = StoreLocal Const store arr$53:TObject = capture $52:TObject [6] mutate $55:TObject = LoadLocal capture arr$53:TObject - [7] mutate $56 = LoadLocal capture x$48 - [8] mutate $57:TFunction<> = PropertyLoad read $55:TObject.at - [9] mutate $58 = PropertyCall read $55:TObject.read $57:TFunction<>(read $56) + [7] mutate $56:TFunction<> = PropertyLoad read $55:TObject.at + [8] mutate $57 = LoadLocal capture x$48 + [9] mutate $58 = PropertyCall read $55:TObject.read $56:TFunction<>(read $57) [10] Return freeze $58 [9] store $41[9:12]:TFunction = StoreLocal Const mutate fn$40[9:12]:TFunction = capture $39[8:12]:TFunction [10] mutate $42[10:12]:TFunction = LoadLocal capture fn$40[9:12]:TFunction diff --git a/compiler/forget/src/__tests__/fixtures/hir/array-at-effect.expect.md b/compiler/forget/src/__tests__/fixtures/hir/array-at-effect.expect.md index b9119689c8..66a18d1167 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/array-at-effect.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/array-at-effect.expect.md @@ -25,12 +25,12 @@ bb0 (block): [5] store $24:TObject = Array [capture $23] [6] store $26:TObject = StoreLocal Const store arr$25:TObject = capture $24:TObject [7] mutate $27:TObject = LoadLocal capture arr$25:TObject - [8] mutate $28:TFunction = Global bar - [9] mutate $29 = LoadLocal read props$19 - [10] mutate $30 = PropertyLoad read $29.y - [11] mutate $31 = Call read $28:TFunction(read $30) - [12] mutate $32:TFunction<> = PropertyLoad read $27:TObject.at - [13] mutate $33 = PropertyCall read $27:TObject.read $32:TFunction<>(read $31) + [8] mutate $28:TFunction<> = PropertyLoad read $27:TObject.at + [9] mutate $29:TFunction = Global bar + [10] mutate $30 = LoadLocal read props$19 + [11] mutate $31 = PropertyLoad read $30.y + [12] mutate $32 = Call read $29:TFunction(read $31) + [13] mutate $33 = PropertyCall read $27:TObject.read $28:TFunction<>(read $32) [14] store $35 = StoreLocal Const mutate result$34 = capture $33 [15] mutate $36 = LoadLocal capture result$34 [16] Return freeze $36 diff --git a/compiler/forget/src/__tests__/fixtures/hir/array-property-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/array-property-call.expect.md index 92d83e67a2..6ea0d433ca 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/array-property-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/array-property-call.expect.md @@ -24,15 +24,15 @@ bb0 (block): [6] store $33[6:12]:TObject = Array [read $29, read $31, read $32:TPrimitive] [7] store $35[7:12]:TObject = StoreLocal Const store a$34[7:12]:TObject = capture $33[6:12]:TObject [8] mutate $36[8:12]:TObject = LoadLocal capture a$34[7:12]:TObject - [9] mutate $37:TPrimitive = 42 - [10] mutate $38[10:12]:TFunction<> = PropertyLoad read $36[8:12]:TObject.push - [11] mutate $39:TPrimitive = PropertyCall mutate $36[8:12]:TObject.read $38[10:12]:TFunction<>(read $37:TPrimitive) + [9] mutate $37[9:12]:TFunction<> = PropertyLoad read $36[8:12]:TObject.push + [10] mutate $38:TPrimitive = 42 + [11] mutate $39:TPrimitive = PropertyCall mutate $36[8:12]:TObject.read $37[9:12]:TFunction<>(read $38:TPrimitive) [12] store $41:TPrimitive = StoreLocal Const mutate x$40:TPrimitive = capture $39:TPrimitive [13] mutate $42:TObject = LoadLocal capture a$34[7:12]:TObject - [14] mutate $43 = LoadLocal read props$27 - [15] mutate $44 = PropertyLoad read $43.c - [16] mutate $45:TFunction<> = PropertyLoad read $42:TObject.at - [17] mutate $46 = PropertyCall read $42:TObject.read $45:TFunction<>(read $44) + [14] mutate $43:TFunction<> = PropertyLoad read $42:TObject.at + [15] mutate $44 = LoadLocal read props$27 + [16] mutate $45 = PropertyLoad read $44.c + [17] mutate $46 = PropertyCall read $42:TObject.read $43:TFunction<>(read $45) [18] store $48 = StoreLocal Const mutate y$47 = capture $46 [19] mutate $49:TObject = LoadLocal capture a$34[7:12]:TObject [20] mutate $50:TPrimitive = LoadLocal capture x$40:TPrimitive diff --git a/compiler/forget/src/__tests__/fixtures/hir/array-push-effect.expect.md b/compiler/forget/src/__tests__/fixtures/hir/array-push-effect.expect.md index 8f90200f08..cb707fbb60 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/array-push-effect.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/array-push-effect.expect.md @@ -32,14 +32,14 @@ bb0 (block): [10] store $38[10:21]:TObject = Array [] [11] store $40[11:21]:TObject = StoreLocal Const store arr$39[11:21]:TObject = capture $38[10:21]:TObject [12] mutate $41[12:21]:TObject = LoadLocal capture arr$39[11:21]:TObject - [13] store $42:TObject = Object { } - [14] mutate $43[14:21]:TFunction<> = PropertyLoad read $41[12:21]:TObject.push - [15] mutate $44:TPrimitive = PropertyCall mutate $41[12:21]:TObject.read $43[14:21]:TFunction<>(capture $42:TObject) + [13] mutate $42[13:21]:TFunction<> = PropertyLoad read $41[12:21]:TObject.push + [14] store $43:TObject = Object { } + [15] mutate $44:TPrimitive = PropertyCall mutate $41[12:21]:TObject.read $42[13:21]:TFunction<>(capture $43:TObject) [16] mutate $45[16:21]:TObject = LoadLocal capture arr$39[11:21]:TObject - [17] mutate $46 = LoadLocal capture x$31 - [18] mutate $47:TObject = LoadLocal capture y$36:TObject - [19] mutate $48[19:21]:TFunction<> = PropertyLoad read $45[16:21]:TObject.push - [20] mutate $49:TPrimitive = PropertyCall mutate $45[16:21]:TObject.read $48[19:21]:TFunction<>(capture $46, capture $47:TObject) + [17] mutate $46[17:21]:TFunction<> = PropertyLoad read $45[16:21]:TObject.push + [18] mutate $47 = LoadLocal capture x$31 + [19] mutate $48:TObject = LoadLocal capture y$36:TObject + [20] mutate $49:TPrimitive = PropertyCall mutate $45[16:21]:TObject.read $46[17:21]:TFunction<>(capture $47, capture $48:TObject) [21] mutate $50:TObject = LoadLocal capture arr$39[11:21]:TObject [22] Return freeze $50:TObject ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction-with-mutation.expect.md index 9fd4956180..9631d27b6a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction-with-mutation.expect.md @@ -22,10 +22,10 @@ bb0 (block): [1] store $38[1:36]:TObject = Array [] [2] store $40[2:36]:TObject = StoreLocal Let store x$39[2:36]:TObject = capture $38[1:36]:TObject [3] mutate $41[3:36]:TObject = LoadLocal capture x$39[2:36]:TObject - [4] mutate $42 = LoadLocal read props$37 - [5] mutate $43 = PropertyLoad read $42.bar - [6] mutate $44[6:36]:TFunction<> = PropertyLoad read $41[3:36]:TObject.push - [7] mutate $45:TPrimitive = PropertyCall mutate $41[3:36]:TObject.read $44[6:36]:TFunction<>(read $43) + [4] mutate $42[4:36]:TFunction<> = PropertyLoad read $41[3:36]:TObject.push + [5] mutate $43 = LoadLocal read props$37 + [6] mutate $44 = PropertyLoad read $43.bar + [7] mutate $45:TPrimitive = PropertyCall mutate $41[3:36]:TObject.read $42[4:36]:TFunction<>(read $44) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -38,10 +38,10 @@ bb3 (value): [16] store $53[16:36]:TObject = Array [capture $52[15:36]:TObject] [17] store $55[17:36] = Destructure Reassign [ mutate x$39[17:36] ] = capture $53[16:36]:TObject [18] mutate $56[18:36] = LoadLocal capture x$39[17:36] - [19] mutate $57 = LoadLocal read props$37 - [20] mutate $58 = PropertyLoad read $57.foo - [21] mutate $59[21:36] = PropertyLoad read $56[18:36].push - [22] mutate $60[22:33] = PropertyCall mutate $56[18:36].read $59[21:36](read $58) + [19] mutate $57[19:36] = PropertyLoad read $56[18:36].push + [20] mutate $58 = LoadLocal read props$37 + [21] mutate $59 = PropertyLoad read $58.foo + [22] mutate $60[22:33] = PropertyCall mutate $56[18:36].read $57[19:36](read $59) [23] store $62[23:33] = StoreLocal Const mutate $61[8:33] = capture $60[22:33] [24] Goto bb1 bb4 (value): @@ -55,9 +55,9 @@ bb1 (block): x$39[2:36]:TPhi: phi(bb3: x$39, bb4: x$39) [28] store $67[28:33] = StoreLocal Const mutate _$66[28:33] = capture $61[8:33] [29] mutate $69 = Global console - [30] mutate $70[30:33] = LoadLocal capture _$66[28:33] - [31] mutate $71 = PropertyLoad read $69.log - [32] mutate $72 = PropertyCall read $69.read $71(mutate $70[30:33]) + [30] mutate $70 = PropertyLoad read $69.log + [31] mutate $71[31:33] = LoadLocal capture _$66[28:33] + [32] mutate $72 = PropertyCall read $69.read $70(mutate $71[31:33]) [33] mutate $73:TFunction = Global mut [34] mutate $74[34:36] = LoadLocal capture x$39[2:36] [35] mutate $76 = Call read $73:TFunction(mutate $74[34:36]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction.expect.md index b143a7e0af..a6a2842f76 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-destruction.expect.md @@ -21,10 +21,10 @@ bb0 (block): [1] store $35[1:8]:TObject = Array [] [2] store $37[2:8]:TObject = StoreLocal Let store x$36[2:8]:TObject = capture $35[1:8]:TObject [3] mutate $38[3:8]:TObject = LoadLocal capture x$36[2:8]:TObject - [4] mutate $39 = LoadLocal read props$34 - [5] mutate $40 = PropertyLoad read $39.bar - [6] mutate $41[6:8]:TFunction<> = PropertyLoad read $38[3:8]:TObject.push - [7] mutate $42:TPrimitive = PropertyCall mutate $38[3:8]:TObject.read $41[6:8]:TFunction<>(read $40) + [4] mutate $39[4:8]:TFunction<> = PropertyLoad read $38[3:8]:TObject.push + [5] mutate $40 = LoadLocal read props$34 + [6] mutate $41 = PropertyLoad read $40.bar + [7] mutate $42:TPrimitive = PropertyCall mutate $38[3:8]:TObject.read $39[4:8]:TFunction<>(read $41) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -37,10 +37,10 @@ bb3 (value): [16] store $50[16:23]:TObject = Array [capture $49[15:23]:TObject] [17] store $52[17:23] = Destructure Reassign [ mutate x$36[17:23] ] = capture $50[16:23]:TObject [18] mutate $53[18:23] = LoadLocal capture x$36[17:23] - [19] mutate $54 = LoadLocal read props$34 - [20] mutate $55 = PropertyLoad read $54.foo - [21] mutate $56[21:23] = PropertyLoad read $53[18:23].push - [22] mutate $57[22:33] = PropertyCall mutate $53[18:23].read $56[21:23](read $55) + [19] mutate $54[19:23] = PropertyLoad read $53[18:23].push + [20] mutate $55 = LoadLocal read props$34 + [21] mutate $56 = PropertyLoad read $55.foo + [22] mutate $57[22:33] = PropertyCall mutate $53[18:23].read $54[19:23](read $56) [23] store $59[23:33] = StoreLocal Const mutate $58[8:33] = capture $57[22:33] [24] Goto bb1 bb4 (value): @@ -54,9 +54,9 @@ bb1 (block): x$36:TPhi: phi(bb3: x$36, bb4: x$36) [28] store $64[28:33] = StoreLocal Const mutate _$63[28:33] = capture $58[8:33] [29] mutate $66 = Global console - [30] mutate $67[30:33] = LoadLocal capture _$63[28:33] - [31] mutate $68 = PropertyLoad read $66.log - [32] mutate $69 = PropertyCall read $66.read $68(mutate $67[30:33]) + [30] mutate $67 = PropertyLoad read $66.log + [31] mutate $68[31:33] = LoadLocal capture _$63[28:33] + [32] mutate $69 = PropertyCall read $66.read $67(mutate $68[31:33]) [33] mutate $70 = LoadLocal capture x$36 [34] Return freeze $70 ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-with-mutation.expect.md index d6ebe2504c..1180fb5195 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary-with-mutation.expect.md @@ -20,10 +20,10 @@ bb0 (block): [1] store $36[1:34]:TObject = Array [] [2] store $38[2:34]:TObject = StoreLocal Let store x$37[2:34]:TObject = capture $36[1:34]:TObject [3] mutate $39[3:34]:TObject = LoadLocal capture x$37[2:34]:TObject - [4] mutate $40 = LoadLocal read props$35 - [5] mutate $41 = PropertyLoad read $40.bar - [6] mutate $42[6:34]:TFunction<> = PropertyLoad read $39[3:34]:TObject.push - [7] mutate $43:TPrimitive = PropertyCall mutate $39[3:34]:TObject.read $42[6:34]:TFunction<>(read $41) + [4] mutate $40[4:34]:TFunction<> = PropertyLoad read $39[3:34]:TObject.push + [5] mutate $41 = LoadLocal read props$35 + [6] mutate $42 = PropertyLoad read $41.bar + [7] mutate $43:TPrimitive = PropertyCall mutate $39[3:34]:TObject.read $40[4:34]:TFunction<>(read $42) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -35,10 +35,10 @@ bb3 (value): [14] store $49[14:34]:TObject = Array [] [15] store $51[15:34]:TObject = StoreLocal Reassign store x$37[15:34]:TObject = capture $49[14:34]:TObject [16] mutate $52[16:34]:TObject = LoadLocal capture x$37[15:34]:TObject - [17] mutate $53 = LoadLocal read props$35 - [18] mutate $54 = PropertyLoad read $53.foo - [19] mutate $55[19:34]:TFunction<> = PropertyLoad read $52[16:34]:TObject.push - [20] mutate $56[20:31]:TPrimitive = PropertyCall mutate $52[16:34]:TObject.read $55[19:34]:TFunction<>(read $54) + [17] mutate $53[17:34]:TFunction<> = PropertyLoad read $52[16:34]:TObject.push + [18] mutate $54 = LoadLocal read props$35 + [19] mutate $55 = PropertyLoad read $54.foo + [20] mutate $56[20:31]:TPrimitive = PropertyCall mutate $52[16:34]:TObject.read $53[17:34]:TFunction<>(read $55) [21] store $58[21:31]:TPrimitive = StoreLocal Const mutate $57[8:31]:TPrimitive = capture $56[20:31]:TPrimitive [22] Goto bb1 bb4 (value): @@ -52,9 +52,9 @@ bb1 (block): x$37[2:34]:TObject: phi(bb3: x$37, bb4: x$37) [26] store $63[26:31] = StoreLocal Const mutate _$62[26:31] = capture $57[8:31]:TPrimitive [27] mutate $65 = Global console - [28] mutate $66[28:31] = LoadLocal capture _$62[26:31] - [29] mutate $67 = PropertyLoad read $65.log - [30] mutate $68 = PropertyCall read $65.read $67(mutate $66[28:31]) + [28] mutate $66 = PropertyLoad read $65.log + [29] mutate $67[29:31] = LoadLocal capture _$62[26:31] + [30] mutate $68 = PropertyCall read $65.read $66(mutate $67[29:31]) [31] mutate $69:TFunction = Global mut [32] mutate $70[32:34] = LoadLocal capture x$37[2:34] [33] mutate $72 = Call read $69:TFunction(mutate $70[32:34]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary.expect.md index b4b9d37e8e..69aaa3c366 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-ternary.expect.md @@ -19,10 +19,10 @@ bb0 (block): [1] store $33[1:8]:TObject = Array [] [2] store $35[2:8]:TObject = StoreLocal Let store x$34[2:8]:TObject = capture $33[1:8]:TObject [3] mutate $36[3:8]:TObject = LoadLocal capture x$34[2:8]:TObject - [4] mutate $37 = LoadLocal read props$32 - [5] mutate $38 = PropertyLoad read $37.bar - [6] mutate $39[6:8]:TFunction<> = PropertyLoad read $36[3:8]:TObject.push - [7] mutate $40:TPrimitive = PropertyCall mutate $36[3:8]:TObject.read $39[6:8]:TFunction<>(read $38) + [4] mutate $37[4:8]:TFunction<> = PropertyLoad read $36[3:8]:TObject.push + [5] mutate $38 = LoadLocal read props$32 + [6] mutate $39 = PropertyLoad read $38.bar + [7] mutate $40:TPrimitive = PropertyCall mutate $36[3:8]:TObject.read $37[4:8]:TFunction<>(read $39) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -34,10 +34,10 @@ bb3 (value): [14] store $46[14:21]:TObject = Array [] [15] store $48[15:21]:TObject = StoreLocal Reassign store x$34[15:21]:TObject = capture $46[14:21]:TObject [16] mutate $49[16:21]:TObject = LoadLocal capture x$34[15:21]:TObject - [17] mutate $50 = LoadLocal read props$32 - [18] mutate $51 = PropertyLoad read $50.foo - [19] mutate $52[19:21]:TFunction<> = PropertyLoad read $49[16:21]:TObject.push - [20] mutate $53[20:31]:TPrimitive = PropertyCall mutate $49[16:21]:TObject.read $52[19:21]:TFunction<>(read $51) + [17] mutate $50[17:21]:TFunction<> = PropertyLoad read $49[16:21]:TObject.push + [18] mutate $51 = LoadLocal read props$32 + [19] mutate $52 = PropertyLoad read $51.foo + [20] mutate $53[20:31]:TPrimitive = PropertyCall mutate $49[16:21]:TObject.read $50[17:21]:TFunction<>(read $52) [21] store $55[21:31]:TPrimitive = StoreLocal Const mutate $54[8:31]:TPrimitive = capture $53[20:31]:TPrimitive [22] Goto bb1 bb4 (value): @@ -51,9 +51,9 @@ bb1 (block): x$34:TObject: phi(bb3: x$34, bb4: x$34) [26] store $60[26:31] = StoreLocal Const mutate _$59[26:31] = capture $54[8:31]:TPrimitive [27] mutate $62 = Global console - [28] mutate $63[28:31] = LoadLocal capture _$59[26:31] - [29] mutate $64 = PropertyLoad read $62.log - [30] mutate $65 = PropertyCall read $62.read $64(mutate $63[28:31]) + [28] mutate $63 = PropertyLoad read $62.log + [29] mutate $64[29:31] = LoadLocal capture _$59[26:31] + [30] mutate $65 = PropertyCall read $62.read $63(mutate $64[29:31]) [31] mutate $66 = LoadLocal capture x$34 [32] Return freeze $66 ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary-with-mutation.expect.md index 7ed9278fa3..b8460c7440 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary-with-mutation.expect.md @@ -22,10 +22,10 @@ bb0 (block): [1] store $44[1:8]:TObject = Array [] [2] store $46[2:8]:TObject = StoreLocal Let store x$45[2:42]:TObject = capture $44[1:8]:TObject [3] mutate $47[3:8]:TObject = LoadLocal capture x$45[2:42]:TObject - [4] mutate $48 = LoadLocal read props$43 - [5] mutate $49 = PropertyLoad read $48.bar - [6] mutate $50[6:8]:TFunction<> = PropertyLoad read $47[3:8]:TObject.push - [7] mutate $51:TPrimitive = PropertyCall mutate $47[3:8]:TObject.read $50[6:8]:TFunction<>(read $49) + [4] mutate $48[4:8]:TFunction<> = PropertyLoad read $47[3:8]:TObject.push + [5] mutate $49 = LoadLocal read props$43 + [6] mutate $50 = PropertyLoad read $49.bar + [7] mutate $51:TPrimitive = PropertyCall mutate $47[3:8]:TObject.read $48[4:8]:TFunction<>(read $50) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -37,10 +37,10 @@ bb3 (value): [14] store $57[14:42]:TObject = Array [] [15] store $59[15:42]:TObject = StoreLocal Reassign store x$45[15:42]:TObject = capture $57[14:42]:TObject [16] mutate $60[16:42]:TObject = LoadLocal capture x$45[15:42]:TObject - [17] mutate $61 = LoadLocal read props$43 - [18] mutate $62 = PropertyLoad read $61.foo - [19] mutate $63[19:42]:TFunction<> = PropertyLoad read $60[16:42]:TObject.push - [20] mutate $64[20:39]:TPrimitive = PropertyCall mutate $60[16:42]:TObject.read $63[19:42]:TFunction<>(read $62) + [17] mutate $61[17:42]:TFunction<> = PropertyLoad read $60[16:42]:TObject.push + [18] mutate $62 = LoadLocal read props$43 + [19] mutate $63 = PropertyLoad read $62.foo + [20] mutate $64[20:39]:TPrimitive = PropertyCall mutate $60[16:42]:TObject.read $61[17:42]:TFunction<>(read $63) [21] store $66[21:39]:TPrimitive = StoreLocal Const mutate $65[8:39]:TPrimitive = capture $64[20:39]:TPrimitive [22] Goto bb1 bb4 (value): @@ -48,10 +48,10 @@ bb4 (value): [25] store $70[25:42]:TObject = Array [] [26] store $72[26:42]:TObject = StoreLocal Reassign store x$45[26:42]:TObject = capture $70[25:42]:TObject [27] mutate $73[27:42]:TObject = LoadLocal capture x$45[26:42]:TObject - [28] mutate $74 = LoadLocal read props$43 - [29] mutate $75 = PropertyLoad read $74.bar - [30] mutate $76[30:42]:TFunction<> = PropertyLoad read $73[27:42]:TObject.push - [31] mutate $77[31:39]:TPrimitive = PropertyCall mutate $73[27:42]:TObject.read $76[30:42]:TFunction<>(read $75) + [28] mutate $74[28:42]:TFunction<> = PropertyLoad read $73[27:42]:TObject.push + [29] mutate $75 = LoadLocal read props$43 + [30] mutate $76 = PropertyLoad read $75.bar + [31] mutate $77[31:39]:TPrimitive = PropertyCall mutate $73[27:42]:TObject.read $74[28:42]:TFunction<>(read $76) [32] store $79[32:39]:TPrimitive = StoreLocal Const mutate $65[8:39]:TPrimitive = capture $77[31:39]:TPrimitive [33] Goto bb1 bb1 (block): @@ -60,9 +60,9 @@ bb1 (block): x$45[15:42]:TObject: phi(bb3: x$45, bb4: x$45) [34] store $81[34:39] = StoreLocal Const mutate _$80[34:39] = capture $65[8:39]:TPrimitive [35] mutate $83 = Global console - [36] mutate $84[36:39] = LoadLocal capture _$80[34:39] - [37] mutate $85 = PropertyLoad read $83.log - [38] mutate $86 = PropertyCall read $83.read $85(mutate $84[36:39]) + [36] mutate $84 = PropertyLoad read $83.log + [37] mutate $85[37:39] = LoadLocal capture _$80[34:39] + [38] mutate $86 = PropertyCall read $83.read $84(mutate $85[37:39]) [39] mutate $87:TFunction = Global mut [40] mutate $88[40:42] = LoadLocal capture x$45[15:42] [41] mutate $90 = Call read $87:TFunction(mutate $88[40:42]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary.expect.md index 5562e58710..03510b7e56 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-ternary.expect.md @@ -21,10 +21,10 @@ bb0 (block): [1] store $41[1:8]:TObject = Array [] [2] store $43[2:8]:TObject = StoreLocal Let store x$42[2:8]:TObject = capture $41[1:8]:TObject [3] mutate $44[3:8]:TObject = LoadLocal capture x$42[2:8]:TObject - [4] mutate $45 = LoadLocal read props$40 - [5] mutate $46 = PropertyLoad read $45.bar - [6] mutate $47[6:8]:TFunction<> = PropertyLoad read $44[3:8]:TObject.push - [7] mutate $48:TPrimitive = PropertyCall mutate $44[3:8]:TObject.read $47[6:8]:TFunction<>(read $46) + [4] mutate $45[4:8]:TFunction<> = PropertyLoad read $44[3:8]:TObject.push + [5] mutate $46 = LoadLocal read props$40 + [6] mutate $47 = PropertyLoad read $46.bar + [7] mutate $48:TPrimitive = PropertyCall mutate $44[3:8]:TObject.read $45[4:8]:TFunction<>(read $47) [8] Ternary test:bb2 fallthrough=bb1 bb2 (value): predecessor blocks: bb0 @@ -36,10 +36,10 @@ bb3 (value): [14] store $54[14:21]:TObject = Array [] [15] store $56[15:21]:TObject = StoreLocal Reassign store x$42[15:21]:TObject = capture $54[14:21]:TObject [16] mutate $57[16:21]:TObject = LoadLocal capture x$42[15:21]:TObject - [17] mutate $58 = LoadLocal read props$40 - [18] mutate $59 = PropertyLoad read $58.foo - [19] mutate $60[19:21]:TFunction<> = PropertyLoad read $57[16:21]:TObject.push - [20] mutate $61[20:39]:TPrimitive = PropertyCall mutate $57[16:21]:TObject.read $60[19:21]:TFunction<>(read $59) + [17] mutate $58[17:21]:TFunction<> = PropertyLoad read $57[16:21]:TObject.push + [18] mutate $59 = LoadLocal read props$40 + [19] mutate $60 = PropertyLoad read $59.foo + [20] mutate $61[20:39]:TPrimitive = PropertyCall mutate $57[16:21]:TObject.read $58[17:21]:TFunction<>(read $60) [21] store $63[21:39]:TPrimitive = StoreLocal Const mutate $62[8:39]:TPrimitive = capture $61[20:39]:TPrimitive [22] Goto bb1 bb4 (value): @@ -47,10 +47,10 @@ bb4 (value): [25] store $67[25:32]:TObject = Array [] [26] store $69[26:32]:TObject = StoreLocal Reassign store x$42[26:32]:TObject = capture $67[25:32]:TObject [27] mutate $70[27:32]:TObject = LoadLocal capture x$42[26:32]:TObject - [28] mutate $71 = LoadLocal read props$40 - [29] mutate $72 = PropertyLoad read $71.bar - [30] mutate $73[30:32]:TFunction<> = PropertyLoad read $70[27:32]:TObject.push - [31] mutate $74[31:39]:TPrimitive = PropertyCall mutate $70[27:32]:TObject.read $73[30:32]:TFunction<>(read $72) + [28] mutate $71[28:32]:TFunction<> = PropertyLoad read $70[27:32]:TObject.push + [29] mutate $72 = LoadLocal read props$40 + [30] mutate $73 = PropertyLoad read $72.bar + [31] mutate $74[31:39]:TPrimitive = PropertyCall mutate $70[27:32]:TObject.read $71[28:32]:TFunction<>(read $73) [32] store $76[32:39]:TPrimitive = StoreLocal Const mutate $62[8:39]:TPrimitive = capture $74[31:39]:TPrimitive [33] Goto bb1 bb1 (block): @@ -59,9 +59,9 @@ bb1 (block): x$42:TObject: phi(bb3: x$42, bb4: x$42) [34] store $78[34:39] = StoreLocal Const mutate _$77[34:39] = capture $62[8:39]:TPrimitive [35] mutate $80 = Global console - [36] mutate $81[36:39] = LoadLocal capture _$77[34:39] - [37] mutate $82 = PropertyLoad read $80.log - [38] mutate $83 = PropertyCall read $80.read $82(mutate $81[36:39]) + [36] mutate $81 = PropertyLoad read $80.log + [37] mutate $82[37:39] = LoadLocal capture _$77[34:39] + [38] mutate $83 = PropertyCall read $80.read $81(mutate $82[37:39]) [39] mutate $84 = LoadLocal capture x$42 [40] Return freeze $84 ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-with-mutation.expect.md index 625e980712..c300ddcc9c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-unconditional-with-mutation.expect.md @@ -27,10 +27,10 @@ bb0 (block): [1] store $35[1:8]:TObject = Array [] [2] store $37[2:8]:TObject = StoreLocal Let store x$36[2:34]:TObject = capture $35[1:8]:TObject [3] mutate $38[3:8]:TObject = LoadLocal capture x$36[2:34]:TObject - [4] mutate $39 = LoadLocal read props$34 - [5] mutate $40 = PropertyLoad read $39.bar - [6] mutate $41[6:8]:TFunction<> = PropertyLoad read $38[3:8]:TObject.push - [7] mutate $42:TPrimitive = PropertyCall mutate $38[3:8]:TObject.read $41[6:8]:TFunction<>(read $40) + [4] mutate $39[4:8]:TFunction<> = PropertyLoad read $38[3:8]:TObject.push + [5] mutate $40 = LoadLocal read props$34 + [6] mutate $41 = PropertyLoad read $40.bar + [7] mutate $42:TPrimitive = PropertyCall mutate $38[3:8]:TObject.read $39[4:8]:TFunction<>(read $41) [8] mutate $43 = LoadLocal read props$34 [9] mutate $44 = PropertyLoad read $43.cond [10] If (read $44) then:bb2 else:bb3 fallthrough=bb1 @@ -39,20 +39,20 @@ bb2 (block): [13] store $48[13:34]:TObject = Array [] [14] store $50[14:34]:TObject = StoreLocal Reassign store x$36[14:34]:TObject = capture $48[13:34]:TObject [15] mutate $51[15:34]:TObject = LoadLocal capture x$36[14:34]:TObject - [16] mutate $52 = LoadLocal read props$34 - [17] mutate $53 = PropertyLoad read $52.foo - [18] mutate $54[18:34]:TFunction<> = PropertyLoad read $51[15:34]:TObject.push - [19] mutate $55:TPrimitive = PropertyCall mutate $51[15:34]:TObject.read $54[18:34]:TFunction<>(read $53) + [16] mutate $52[16:34]:TFunction<> = PropertyLoad read $51[15:34]:TObject.push + [17] mutate $53 = LoadLocal read props$34 + [18] mutate $54 = PropertyLoad read $53.foo + [19] mutate $55:TPrimitive = PropertyCall mutate $51[15:34]:TObject.read $52[16:34]:TFunction<>(read $54) [20] Goto bb1 bb3 (block): predecessor blocks: bb0 [23] store $59[23:34]:TObject = Array [] [24] store $61[24:34]:TObject = StoreLocal Reassign store x$36[24:34]:TObject = capture $59[23:34]:TObject [25] mutate $62[25:34]:TObject = LoadLocal capture x$36[24:34]:TObject - [26] mutate $63 = LoadLocal read props$34 - [27] mutate $64 = PropertyLoad read $63.bar - [28] mutate $65[28:34]:TFunction<> = PropertyLoad read $62[25:34]:TObject.push - [29] mutate $66:TPrimitive = PropertyCall mutate $62[25:34]:TObject.read $65[28:34]:TFunction<>(read $64) + [26] mutate $63[26:34]:TFunction<> = PropertyLoad read $62[25:34]:TObject.push + [27] mutate $64 = LoadLocal read props$34 + [28] mutate $65 = PropertyLoad read $64.bar + [29] mutate $66:TPrimitive = PropertyCall mutate $62[25:34]:TObject.read $63[26:34]:TFunction<>(read $65) [30] Goto bb1 bb1 (block): predecessor blocks: bb2 bb3