From d03c5bc0a0a3ffa16f6c9cf4834bbe2212c3d11c Mon Sep 17 00:00:00 2001 From: Joseph Savona Date: Fri, 9 Dec 2022 07:39:28 -0800 Subject: [PATCH] Run LeaveSSA prior to analyzing reactive scopes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorders LeaveSSA so that it runs before we begin evaluating reactive scopes. Note that reactive scopes must span the full construction of each variable — for variables with a phi, this must span the declaration and all assignments of the phi operands. And that's exactly what the new LeaveSSA does! LeaveSSA removes phi nodes and ensure that all versions of a variable which flow into a phi have been assigned a single canonical identifier (with an appropriate mutable range). This PR includes this and some related changes: * Reorders the pass * Changes hir-test to print the final HIR, eg just prior to codegen * Teaches LeaveSSA to update the mutable range of the canonical identifiers it assigns, based on the min/max of the variables assigned. --- .../playground/components/Editor/Output.tsx | 16 +-- .../src/HIR/InferReactiveScopeVariables.ts | 9 +- compiler/forget/src/HIR/LeaveSSA.ts | 50 ++++++++-- compiler/forget/src/HIR/Pipeline.ts | 6 +- .../_bug_expression-with-assignment.expect.md | 8 +- .../hir/_bug_inverted-if-else.expect.md | 21 ++-- .../fixtures/hir/alias-while.expect.md | 39 ++++---- .../hir/assignment-variations.expect.md | 16 +-- .../src/__tests__/fixtures/hir/call.expect.md | 4 +- .../fixtures/hir/component.expect.md | 11 ++- .../fixtures/hir/constructor.expect.md | 4 +- .../fixtures/hir/extend-scopes-if.expect.md | 4 +- ...reeze-possibly-mutable-arguments.expect.md | 34 ++++--- .../fixtures/hir/inverted-if.expect.md | 4 +- .../fixtures/hir/logical-expression.expect.md | 45 +++++---- .../hir/mutable-lifetime-loops.expect.md | 72 ++++++-------- .../hir/mutable-liverange-loop.expect.md | 16 +-- .../overlapping-scopes-interleaved.expect.md | 8 +- .../hir/overlapping-scopes-shadowed.expect.md | 8 +- ...ng-scopes-shadowing-within-block.expect.md | 8 +- .../hir/overlapping-scopes-while.expect.md | 8 +- .../overlapping-scopes-within-block.expect.md | 8 +- .../hir/reactive-scope-grouping.expect.md | 12 +-- .../fixtures/hir/reactive-scopes.expect.md | 4 +- .../hir/reassignment-conditional.expect.md | 19 ++-- .../reassignment-separate-scopes.expect.md | 30 +++--- .../fixtures/hir/reassignment.expect.md | 16 +-- .../fixtures/hir/reverse-postorder.expect.md | 59 +++++------ .../fixtures/hir/simple-alias.expect.md | 24 ++--- .../fixtures/hir/ssa-call-jsx-2.expect.md | 4 +- .../fixtures/hir/ssa-call-jsx.expect.md | 4 +- .../hir/ssa-complex-multiple-if.expect.md | 24 ++--- .../hir/ssa-complex-single-if.expect.md | 13 ++- .../fixtures/hir/ssa-for-of.expect.md | 12 +-- .../__tests__/fixtures/hir/ssa-for.expect.md | 13 ++- .../fixtures/hir/ssa-if-else.expect.md | 16 +-- .../fixtures/hir/ssa-multiple-phis.expect.md | 49 +++++---- .../ssa-nested-loops-no-reassign.expect.md | 4 +- .../hir/ssa-nested-partial-phi.expect.md | 99 +++++++++++++++++++ .../fixtures/hir/ssa-nested-partial-phi.js | 9 ++ .../ssa-nested-partial-reassignment.expect.md | 13 ++- .../fixtures/hir/ssa-newexpression.expect.md | 4 +- .../hir/ssa-objectexpression-phi.expect.md | 31 +++--- ...a-property-alias-alias-mutate-if.expect.md | 8 +- .../hir/ssa-property-alias-if.expect.md | 8 +- .../ssa-property-alias-mutate-if.expect.md | 8 +- ...-property-alias-mutate-inside-if.expect.md | 8 +- .../fixtures/hir/ssa-reassign.expect.md | 16 +-- .../fixtures/hir/ssa-return.expect.md | 20 ++-- .../fixtures/hir/ssa-shadowing.expect.md | 13 ++- .../fixtures/hir/ssa-sibling-phis.expect.md | 40 ++++---- .../fixtures/hir/ssa-simple-phi.expect.md | 21 ++-- .../fixtures/hir/ssa-simple.expect.md | 8 +- .../fixtures/hir/ssa-single-if.expect.md | 12 +-- .../fixtures/hir/ssa-switch.expect.md | 32 +++--- .../fixtures/hir/ssa-throw.expect.md | 20 ++-- .../hir/ssa-while-no-reassign.expect.md | 4 +- .../fixtures/hir/ssa-while.expect.md | 13 ++- .../hir/switch-non-final-default.expect.md | 23 ++--- .../hir/switch-with-fallthrough.expect.md | 28 +++--- .../__tests__/fixtures/hir/switch.expect.md | 23 ++--- compiler/forget/src/__tests__/hir-test.ts | 20 +--- 62 files changed, 658 insertions(+), 525 deletions(-) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js diff --git a/compiler/forget/packages/playground/components/Editor/Output.tsx b/compiler/forget/packages/playground/components/Editor/Output.tsx index 42d7b622b6..0c9e7536d2 100644 --- a/compiler/forget/packages/playground/components/Editor/Output.tsx +++ b/compiler/forget/packages/playground/components/Editor/Output.tsx @@ -87,6 +87,9 @@ function compile(source: string): CompilerOutput | CompilerError { inferMutableRanges(ir); const inferMutableRangesOutput = printHIR(ir.body); + leaveSSA(ir); + const leaveSSAOutput = printHIR(ir.body); + inferReactiveScopeVariables(ir); const inferReactiveScopeVariablesOutput = printHIR(ir.body); @@ -96,9 +99,6 @@ function compile(source: string): CompilerOutput | CompilerError { inferReactiveScopeDependencies(ir); const inferReactiveScopeDependenciesOutput = printHIR(ir.body); - leaveSSA(ir); - const leaveSSAOutput = printHIR(ir.body); - codegen(ir); const ast = codegen(ir); const generated = generate( @@ -183,6 +183,11 @@ function Output({ store, setTabsOpen, tabsOpen }: Props) { output={compilerOutput.inferMutableRangesOutput} > ), + LeaveSSA: ( + + ), InferReactiveScopeVariables: ( ), - LeaveSSA: ( - - ), JS: , SourceMap: ( <> diff --git a/compiler/forget/src/HIR/InferReactiveScopeVariables.ts b/compiler/forget/src/HIR/InferReactiveScopeVariables.ts index 512e3fa9e0..ddb5ff1917 100644 --- a/compiler/forget/src/HIR/InferReactiveScopeVariables.ts +++ b/compiler/forget/src/HIR/InferReactiveScopeVariables.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import invariant from "invariant"; import DisjointSet from "./DisjointSet"; import { HIRFunction, @@ -68,10 +69,10 @@ export function inferReactiveScopeVariables(fn: HIRFunction) { // that mutate together. const scopeIdentifiers = new DisjointSet(); for (const [_, block] of fn.body.blocks) { - for (const phi of block.phis) { - const operands: Array = [phi.id, ...phi.operands.values()]; - scopeIdentifiers.union(operands); - } + invariant( + block.phis.size === 0, + "Expected phis to be cleared by LeaveSSA pass" + ); for (const instr of block.instructions) { const operands: Array = []; diff --git a/compiler/forget/src/HIR/LeaveSSA.ts b/compiler/forget/src/HIR/LeaveSSA.ts index 19f62f21bf..2ac8da4984 100644 --- a/compiler/forget/src/HIR/LeaveSSA.ts +++ b/compiler/forget/src/HIR/LeaveSSA.ts @@ -11,8 +11,11 @@ import { HIRFunction, Identifier, Instruction, + InstructionId, InstructionKind, + makeInstructionId, Phi, + Place, } from "./HIR"; import { eachInstructionValueOperand, eachTerminalOperand } from "./visitors"; @@ -28,6 +31,7 @@ export function leaveSSA(fn: HIRFunction) { // Maps identifiers that appear as a phi or phi operand to a single canonical identifier // for all instances. const variableMapping: Map = new Map(); + const hasDeclaration: Set = new Set(); for (const [, block] of fn.body.blocks) { // Identifiers (from phis) that *may* need a new `let` declaration created. If the original @@ -78,13 +82,28 @@ export function leaveSSA(fn: HIRFunction) { canonicalId = operand; } } + canonicalId.mutableRange.start = Math.min( + canonicalId.mutableRange.start, + terminal.id + ) as InstructionId; variableMapping.set(phi.id, canonicalId); - needsDeclaration.add(canonicalId); + if (!hasDeclaration.has(canonicalId)) { + needsDeclaration.add(canonicalId); + } } + // all versions of the variable need to be remapped to the canonical id + // also extend the mutable range of the canonical id based on the min/max + // of the ranges of its operands + let start = canonicalId.mutableRange.start as number; + let end = canonicalId.mutableRange.end as number; for (const [, operand] of phi.operands) { + start = Math.min(start, operand.mutableRange.start); + end = Math.max(end, operand.mutableRange.end); variableMapping.set(operand, canonicalId); } + canonicalId.mutableRange.start = makeInstructionId(start); + canonicalId.mutableRange.end = makeInstructionId(end); } // Visit instructions and rewrite identifiers based on the variable mapping @@ -92,9 +111,7 @@ export function leaveSSA(fn: HIRFunction) { for (const instr of block.instructions) { const { lvalue, value } = instr; if (lvalue !== null) { - lvalue.place.identifier = - variableMapping.get(lvalue.place.identifier) ?? - lvalue.place.identifier; + updatePlace(lvalue.place, variableMapping); if (lvalue.place.memberPath === null) { if (!variableMapping.has(lvalue.place.identifier)) { // This variable does not flow into a phi, therefore there @@ -109,11 +126,11 @@ export function leaveSSA(fn: HIRFunction) { // reassign the variable in the first place. needsDeclaration.delete(lvalue.place.identifier); } + hasDeclaration.add(lvalue.place.identifier); } } for (const operand of eachInstructionValueOperand(value)) { - operand.identifier = - variableMapping.get(operand.identifier) ?? operand.identifier; + updatePlace(operand, variableMapping); } } @@ -151,3 +168,24 @@ export function leaveSSA(fn: HIRFunction) { block.phis.clear(); } } + +function updatePlace( + place: Place, + variableMapping: Map +) { + const prevIdentifier = place.identifier; + const nextIdentifier = variableMapping.get(prevIdentifier); + if (nextIdentifier === undefined || nextIdentifier === prevIdentifier) { + return; + } + nextIdentifier.mutableRange.start = makeInstructionId( + Math.min( + nextIdentifier.mutableRange.start, + prevIdentifier.mutableRange.start + ) + ); + nextIdentifier.mutableRange.end = makeInstructionId( + Math.max(nextIdentifier.mutableRange.end, prevIdentifier.mutableRange.end) + ); + place.identifier = nextIdentifier; +} diff --git a/compiler/forget/src/HIR/Pipeline.ts b/compiler/forget/src/HIR/Pipeline.ts index 2663a1e4f4..c447c36e8e 100644 --- a/compiler/forget/src/HIR/Pipeline.ts +++ b/compiler/forget/src/HIR/Pipeline.ts @@ -51,6 +51,9 @@ export default function ( if (flags.inferMutableRanges) { inferMutableRanges(ir); } + if (flags.leaveSSA) { + leaveSSA(ir); + } if (flags.inferReactiveScopeVariables) { inferReactiveScopeVariables(ir); } @@ -60,9 +63,6 @@ export default function ( if (flags.inferReactiveScopeDependencies) { inferReactiveScopeDependencies(ir); } - if (flags.leaveSSA) { - leaveSSA(ir); - } if (flags.codegen) { return { ast: codegen(ir), diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md index a703b6e9bf..6968aebf9f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md @@ -15,8 +15,8 @@ function f() { ``` bb0: - [1] Let mutate x$4_@0 = 1 - [2] Reassign mutate x$5_@1 = 2 + [1] Const mutate x$4_@0 = 1 + [2] Const mutate x$5_@1 = 2 [3] Const mutate $6_@2 = Binary read x$5_@1 + read x$5_@1 [4] Const mutate $7_@3 = Binary read $6_@2 + read x$5_@1 [5] Return read $7_@3 @@ -35,8 +35,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$4_@0 = 1 - [2] Reassign mutate x$5_@1 = 2 + [1] Const mutate x$4_@0 = 1 + [2] Const mutate x$5_@1 = 2 [3] Const mutate $6_@2 = Binary read x$5_@1 + read x$5_@1 [4] Const mutate $7_@3 = Binary read $6_@2 + read x$5_@1 "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_inverted-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug_inverted-if-else.expect.md index 89989d051e..9a6334a713 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/_bug_inverted-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_inverted-if-else.expect.md @@ -20,23 +20,22 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$8_@0 = null + [1] Const mutate x$8_@0 = null [2] If (read a$5) then:bb3 else:bb2 fallthrough=bb2 bb3: predecessor blocks: bb0 - [3] Reassign mutate x$9_@1[3:6] = read b$6 + [3] Const mutate x$9_@1 = read b$6 [4] Goto bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$10_@1[3:6] = read c$7 + [5] Const mutate x$10_@2 = read c$7 [6] Goto bb1 bb1: predecessor blocks: bb3 bb2 - x$11_@1[3:6]: phi(bb3: x$9_@1, bb2: x$10_@1) - [7] Return read x$11_@1 -scope1 [3:6]: + [7] Return read x$11 +scope1 [3:4]: - read b$6 - - read a$5 +scope2 [5:6]: - read c$7 ``` @@ -47,24 +46,24 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$8_@0 = null + [1] Const mutate x$8_@0 = null "] bb0_instrs --> bb0_terminal(["If (read a$5)"]) end subgraph bb3 bb3_instrs[" - [3] Reassign mutate x$9_@1[3:6] = read b$6 + [3] Const mutate x$9_@1 = read b$6 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$10_@1[3:6] = read c$7 + [5] Const mutate x$10_@2 = read c$7 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return read x$11_@1"]) + bb1_terminal(["Return read x$11"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md index b2cb6cb033..70ddeda17b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md @@ -33,24 +33,21 @@ bb0: [4] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 - a$12_@0[0:12]: phi(bb0: a$8_@0, bb3: a$15_@0) - b$14_@0[0:12]: phi(bb0: b$9_@0, bb3: b$17_@0) - c$16_@0[0:12]: phi(bb0: c$10_@0, bb3: c$18_@0) [5] If (read cond$7) then:bb3 else:bb2 fallthrough=bb2 bb3: predecessor blocks: bb1 - [6] Let mutate z$13_@0[0:12] = read a$12_@0 - [7] Reassign mutate a$15_@0[0:12] = read b$14_@0 - [8] Reassign mutate b$17_@0[0:12] = read c$16_@0 - [9] Reassign mutate c$18_@0[0:12] = read z$13_@0 - [10] Call mutate mutate$6_@0(mutate a$15_@0, mutate b$17_@0) + [6] Const mutate z$13_@0[0:12] = read a$8_@0 + [7] Reassign mutate a$8_@0[0:12] = read b$9_@0 + [8] Reassign mutate b$9_@0[0:12] = read c$10_@0 + [9] Reassign mutate c$10_@0[0:12] = read z$13_@0 + [10] Call mutate mutate$6_@0(mutate a$8_@0, mutate b$9_@0) [11] Goto(Continue) bb1 bb2: predecessor blocks: bb1 - [12] read a$12_@0 - [13] read b$14_@0 - [14] read c$16_@0 - [15] Return freeze a$12_@0 + [12] read a$8_@0 + [13] read b$9_@0 + [14] read c$10_@0 + [15] Return freeze a$8_@0 ``` @@ -72,21 +69,21 @@ flowchart TB end subgraph bb3 bb3_instrs[" - [6] Let mutate z$13_@0[0:12] = read a$12_@0 - [7] Reassign mutate a$15_@0[0:12] = read b$14_@0 - [8] Reassign mutate b$17_@0[0:12] = read c$16_@0 - [9] Reassign mutate c$18_@0[0:12] = read z$13_@0 - [10] Call mutate mutate$6_@0(mutate a$15_@0, mutate b$17_@0) + [6] Const mutate z$13_@0[0:12] = read a$8_@0 + [7] Reassign mutate a$8_@0[0:12] = read b$9_@0 + [8] Reassign mutate b$9_@0[0:12] = read c$10_@0 + [9] Reassign mutate c$10_@0[0:12] = read z$13_@0 + [10] Call mutate mutate$6_@0(mutate a$8_@0, mutate b$9_@0) "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [12] read a$12_@0 - [13] read b$14_@0 - [14] read c$16_@0 + [12] read a$8_@0 + [13] read b$9_@0 + [14] read c$10_@0 "] - bb2_instrs --> bb2_terminal(["Return freeze a$12_@0"]) + bb2_instrs --> bb2_terminal(["Return freeze a$8_@0"]) end %% Jumps 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 c4208f4695..7dfa8c02dd 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md @@ -20,13 +20,13 @@ function g(a) { ``` bb0: - [1] Let mutate x$5_@0 = 1 + [1] Const mutate x$5_@0 = 1 [2] Const mutate $6_@1 = 1 - [3] Reassign mutate x$7_@2 = Binary read x$5_@0 + read $6_@1 + [3] Const mutate x$7_@2 = Binary read x$5_@0 + read $6_@1 [4] Const mutate $8_@3 = 1 - [5] Reassign mutate x$9_@4 = Binary read x$7_@2 + read $8_@3 + [5] Const mutate x$9_@4 = Binary read x$7_@2 + read $8_@3 [6] Const mutate $10_@5 = 1 - [7] Reassign mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5 + [7] Const mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5 [8] Return scope2 [3:4]: - read x$5_@0 @@ -46,13 +46,13 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$5_@0 = 1 + [1] Const mutate x$5_@0 = 1 [2] Const mutate $6_@1 = 1 - [3] Reassign mutate x$7_@2 = Binary read x$5_@0 + read $6_@1 + [3] Const mutate x$7_@2 = Binary read x$5_@0 + read $6_@1 [4] Const mutate $8_@3 = 1 - [5] Reassign mutate x$9_@4 = Binary read x$7_@2 + read $8_@3 + [5] Const mutate x$9_@4 = Binary read x$7_@2 + read $8_@3 [6] Const mutate $10_@5 = 1 - [7] Reassign mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5 + [7] Const mutate x$11_@6 = Binary read x$9_@4 >>> read $10_@5 "] bb0_instrs --> bb0_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md index e7eb75ae26..aa50a5f7a8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md @@ -50,7 +50,7 @@ bb0: [2] Const mutate b$11_@0[0:7] = Object { } [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = "div" - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] Call mutate foo$4_@0(mutate b$11_@0) [7] Const mutate $14_@3 = "div" [8] Const mutate $15_@4 = JSX @@ -74,7 +74,7 @@ flowchart TB [2] Const mutate b$11_@0[0:7] = Object { } [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = 'div' - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] Call mutate foo$4_@0(mutate b$11_@0) [7] Const mutate $14_@3 = 'div' [8] Const mutate $15_@4 = JSX diff --git a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md index e959a98117..f7c39ff2fe 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md @@ -49,6 +49,7 @@ bb3: predecessor blocks: bb1 [9] Const mutate $34_@6 = null [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6 + [11] Let mutate $37_@3[0:19] = undefined [11] If (read $36_@3) then:bb8 else:bb9 fallthrough=bb7 bb8: predecessor blocks: bb3 @@ -56,12 +57,11 @@ bb8: [13] Goto bb7 bb9: predecessor blocks: bb3 - [14] Const mutate $39_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3) + [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3) [15] Goto bb7 bb7: predecessor blocks: bb8 bb9 - $40_@3[0:19]: phi(bb8: $37_@3, bb9: $39_@3) - [16] If (read $40_@3) then:bb5 else:bb4 fallthrough=bb4 + [16] If (read $37_@3) then:bb5 else:bb4 fallthrough=bb4 bb5: predecessor blocks: bb7 [17] Goto(Continue) bb1 @@ -117,6 +117,7 @@ flowchart TB bb3_instrs[" [9] Const mutate $34_@6 = null [10] Const mutate $36_@3[0:19] = Binary read item$10_@3 == read $34_@6 + [11] Let mutate $37_@3[0:19] = undefined "] bb3_instrs --> bb3_terminal(["If (read $36_@3)"]) end @@ -128,12 +129,12 @@ flowchart TB end subgraph bb9 bb9_instrs[" - [14] Const mutate $39_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3) + [14] Const mutate $37_@3[0:19] = Call mutate seen$30_@3.has(mutate item$10_@3) "] bb9_instrs --> bb9_terminal(["Goto"]) end subgraph bb7 - bb7_terminal(["If (read $40_@3)"]) + bb7_terminal(["If (read $37_@3)"]) end subgraph bb5 bb5_terminal(["Goto"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md index 46b5471b1d..06aee4b185 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md @@ -50,7 +50,7 @@ bb0: [2] Const mutate b$11_@0[0:7] = Object { } [3] New mutate Foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = "div" - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] New mutate Foo$4_@0(mutate b$11_@0) [7] Const mutate $14_@3 = "div" [8] Const mutate $15_@4 = JSX @@ -74,7 +74,7 @@ flowchart TB [2] Const mutate b$11_@0[0:7] = Object { } [3] New mutate Foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = 'div' - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] New mutate Foo$4_@0(mutate b$11_@0) [7] Const mutate $14_@3 = 'div' [8] Const mutate $15_@4 = JSX diff --git a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md index 3e3438bab5..81d880bcdc 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md @@ -23,7 +23,7 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$10_@0[1:8] = Array [] + [1] Const mutate x$10_@0[1:8] = Array [] [2] If (read a$7) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 @@ -59,7 +59,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$10_@0[1:8] = Array [] + [1] Const mutate x$10_@0[1:8] = Array [] "] bb0_instrs --> bb0_terminal(["If (read a$7)"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md index c662505eeb..9cd53a4082 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md @@ -28,29 +28,30 @@ function call(x) {} bb0: [1] Const mutate cond$8_@0 = read props$7.cond [2] Const mutate x$9_@1 = read props$7.x - [3] Let mutate a$10_@2 = undefined + [3] Const mutate a$10_@2 = undefined + [4] Let mutate a$11_@3[4:9] = undefined [4] If (read cond$8_@0) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate a$11_@3[5:8] = read x$9_@1 + [5] Reassign mutate a$11_@3[4:9] = read x$9_@1 [6] Goto bb1 bb3: predecessor blocks: bb0 - [7] Reassign mutate a$12_@3[5:8] = Array [] + [7] Reassign mutate a$11_@3[4:9] = Array [] [8] Goto bb1 bb1: predecessor blocks: bb2 bb3 - a$14_@3[5:8]: phi(bb2: a$11_@3, bb3: a$12_@3) - [9] Call read useFreeze$5(freeze a$14_@3) - [10] Call read useFreeze$5(read a$14_@3) - [11] Call mutate call$6_@4(read a$14_@3) - [12] Return read a$14_@3 + [9] Call read useFreeze$5(freeze a$11_@3) + [10] Call read useFreeze$5(read a$11_@3) + [11] Call mutate call$6_@4(read a$11_@3) + [12] Return read a$11_@3 scope0 [1:2]: - read props$7.cond scope1 [2:3]: - read props$7.x -scope3 [5:8]: +scope3 [4:9]: - read x$9_@1 + - read cond$8_@0 ``` ### CFG @@ -62,29 +63,30 @@ flowchart TB bb0_instrs[" [1] Const mutate cond$8_@0 = read props$7.cond [2] Const mutate x$9_@1 = read props$7.x - [3] Let mutate a$10_@2 = undefined + [3] Const mutate a$10_@2 = undefined + [4] Let mutate a$11_@3[4:9] = undefined "] bb0_instrs --> bb0_terminal(["If (read cond$8_@0)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate a$11_@3[5:8] = read x$9_@1 + [5] Reassign mutate a$11_@3[4:9] = read x$9_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [7] Reassign mutate a$12_@3[5:8] = Array [] + [7] Reassign mutate a$11_@3[4:9] = Array [] "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [9] Call read useFreeze$5(freeze a$14_@3) - [10] Call read useFreeze$5(read a$14_@3) - [11] Call mutate call$6_@4(read a$14_@3) + [9] Call read useFreeze$5(freeze a$11_@3) + [10] Call read useFreeze$5(read a$11_@3) + [11] Call mutate call$6_@4(read a$11_@3) "] - bb1_instrs --> bb1_terminal(["Return read a$14_@3"]) + bb1_instrs --> bb1_terminal(["Return read a$11_@3"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md index da7e9ce49f..3d5661bc78 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md @@ -18,7 +18,7 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate y$8_@0[1:6] = Array [] + [1] Const mutate y$8_@0[1:6] = Array [] [2] If (read a$5) then:bb3 else:bb1 fallthrough=bb1 bb3: predecessor blocks: bb0 @@ -43,7 +43,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate y$8_@0[1:6] = Array [] + [1] Const mutate y$8_@0[1:6] = Array [] "] bb0_instrs --> bb0_terminal(["If (read a$5)"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md index c20f685f1f..75d1bfb61b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md @@ -24,19 +24,19 @@ function g() {} ``` bb0: [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0() + [2] Let mutate $6_@1[0:7] = undefined [2] If (read $5_@0) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Const mutate $6_@1[0:6] = Call mutate g$4_@1() + [3] Const mutate $6_@1[0:7] = Call mutate g$4_@1() [4] Goto bb1 bb3: predecessor blocks: bb0 - [5] Const mutate $7_@1[0:6] = read $5_@0 + [5] Const mutate $6_@1[0:7] = read $5_@0 [6] Goto bb1 bb1: predecessor blocks: bb2 bb3 - $8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1) - [7] Return freeze $8_@1 + [7] Return freeze $6_@1 ``` @@ -48,23 +48,24 @@ flowchart TB subgraph bb0 bb0_instrs[" [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0() + [2] Let mutate $6_@1[0:7] = undefined "] bb0_instrs --> bb0_terminal(["If (read $5_@0)"]) end subgraph bb2 bb2_instrs[" - [3] Const mutate $6_@1[0:6] = Call mutate g$4_@1() + [3] Const mutate $6_@1[0:7] = Call mutate g$4_@1() "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Const mutate $7_@1[0:6] = read $5_@0 + [5] Const mutate $6_@1[0:7] = read $5_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return freeze $8_@1"]) + bb1_terminal(["Return freeze $6_@1"]) end %% Jumps @@ -92,19 +93,19 @@ function And$0() { ``` bb0: [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0() + [2] Let mutate $6_@1[0:7] = undefined [2] If (read $5_@0) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Const mutate $6_@1[0:6] = read $5_@0 + [3] Const mutate $6_@1[0:7] = read $5_@0 [4] Goto bb1 bb3: predecessor blocks: bb0 - [5] Const mutate $7_@1[0:6] = Call mutate g$4_@1() + [5] Const mutate $6_@1[0:7] = Call mutate g$4_@1() [6] Goto bb1 bb1: predecessor blocks: bb2 bb3 - $8_@1[0:6]: phi(bb2: $6_@1, bb3: $7_@1) - [7] Return freeze $8_@1 + [7] Return freeze $6_@1 ``` @@ -116,23 +117,24 @@ flowchart TB subgraph bb0 bb0_instrs[" [1] Const mutate $5_@0[0:2] = Call mutate f$1_@0() + [2] Let mutate $6_@1[0:7] = undefined "] bb0_instrs --> bb0_terminal(["If (read $5_@0)"]) end subgraph bb2 bb2_instrs[" - [3] Const mutate $6_@1[0:6] = read $5_@0 + [3] Const mutate $6_@1[0:7] = read $5_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Const mutate $7_@1[0:6] = Call mutate g$4_@1() + [5] Const mutate $6_@1[0:7] = Call mutate g$4_@1() "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return freeze $8_@1"]) + bb1_terminal(["Return freeze $6_@1"]) end %% Jumps @@ -162,19 +164,19 @@ bb0: [1] Const mutate $9_@0[0:2] = Call mutate f$2_@0() [2] Const mutate $10_@1 = null [3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1 + [4] Let mutate $12_@3[0:9] = undefined [4] If (read $11_@2) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Const mutate $12_@3[0:8] = read $9_@0 + [5] Const mutate $12_@3[0:9] = read $9_@0 [6] Goto bb1 bb3: predecessor blocks: bb0 - [7] Const mutate $13_@3[0:8] = Call mutate g$7_@3() + [7] Const mutate $12_@3[0:9] = Call mutate g$7_@3() [8] Goto bb1 bb1: predecessor blocks: bb2 bb3 - $14_@3[0:8]: phi(bb2: $12_@3, bb3: $13_@3) - [9] Return freeze $14_@3 + [9] Return freeze $12_@3 scope2 [3:4]: - read $9_@0 - read $10_@1 @@ -190,23 +192,24 @@ flowchart TB [1] Const mutate $9_@0[0:2] = Call mutate f$2_@0() [2] Const mutate $10_@1 = null [3] Const mutate $11_@2 = Binary read $9_@0 != read $10_@1 + [4] Let mutate $12_@3[0:9] = undefined "] bb0_instrs --> bb0_terminal(["If (read $11_@2)"]) end subgraph bb2 bb2_instrs[" - [5] Const mutate $12_@3[0:8] = read $9_@0 + [5] Const mutate $12_@3[0:9] = read $9_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [7] Const mutate $13_@3[0:8] = Call mutate g$7_@3() + [7] Const mutate $12_@3[0:9] = Call mutate g$7_@3() "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return freeze $14_@3"]) + bb1_terminal(["Return freeze $12_@3"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md index 1c3331937f..038ffd893c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md @@ -97,52 +97,44 @@ function cond$0(x$2) {} ``` bb0: - [1] Let mutate a$13_@0[0:23] = Object { } - [2] Let mutate b$14_@0[0:23] = Object { } - [3] Let mutate c$15_@0[0:23] = Object { } - [4] Let mutate d$16_@0[0:23] = Object { } + [1] Let mutate a$18_@0[0:23] = Object { } + [2] Let mutate b$20_@0[0:23] = Object { } + [3] Let mutate c$22_@0[0:23] = Object { } + [4] Let mutate d$24_@0[0:23] = Object { } [5] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb4 - a$18_@0[0:23]: phi(bb0: a$13_@0, bb4: a$21_@0) - b$20_@0[0:23]: phi(bb0: b$14_@0, bb4: b$23_@0) - c$22_@0[0:23]: phi(bb0: c$15_@0, bb4: c$25_@0) - d$24_@0[0:23]: phi(bb0: d$16_@0, bb4: d$26_@0) [6] Const mutate $17_@1[6:8] = true [7] If (read $17_@1) then:bb3 else:bb2 fallthrough=bb2 bb3: predecessor blocks: bb1 - [8] Let mutate z$19_@0[0:23] = read a$18_@0 - [9] Reassign mutate a$21_@0[0:23] = read b$20_@0 - [10] Reassign mutate b$23_@0[0:23] = read c$22_@0 - [11] Reassign mutate c$25_@0[0:23] = read d$24_@0 - [12] Reassign mutate d$26_@0[0:23] = read z$19_@0 - [13] Call mutate mutate$7_@0(mutate a$21_@0, mutate b$23_@0) - [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$21_@0) + [8] Const mutate z$19_@0[0:23] = read a$18_@0 + [9] Reassign mutate a$18_@0[0:23] = read b$20_@0 + [10] Reassign mutate b$20_@0[0:23] = read c$22_@0 + [11] Reassign mutate c$22_@0[0:23] = read d$24_@0 + [12] Reassign mutate d$24_@0[0:23] = read z$19_@0 + [13] Call mutate mutate$7_@0(mutate a$18_@0, mutate b$20_@0) + [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$18_@0) [15] If (read $29_@0) then:bb2 else:bb4 fallthrough=bb4 bb4: predecessor blocks: bb3 [16] Goto(Continue) bb1 bb2: predecessor blocks: bb3 bb1 - a$30_@0[0:23]: phi(bb3: a$21_@0, bb1: a$18_@0) - b$31_@0[0:23]: phi(bb3: b$23_@0, bb1: b$20_@0) - c$32_@0[0:23]: phi(bb3: c$25_@0, bb1: c$22_@0) - d$33_@0[0:23]: phi(bb3: d$26_@0, bb1: d$24_@0) - [17] If (read a$30_@0) then:bb7 else:bb7 fallthrough=bb7 + [17] If (read a$18_@0) then:bb7 else:bb7 fallthrough=bb7 bb7: predecessor blocks: bb2 - [18] If (read b$31_@0) then:bb9 else:bb9 fallthrough=bb9 + [18] If (read b$20_@0) then:bb9 else:bb9 fallthrough=bb9 bb9: predecessor blocks: bb7 - [19] If (read c$32_@0) then:bb11 else:bb11 fallthrough=bb11 + [19] If (read c$22_@0) then:bb11 else:bb11 fallthrough=bb11 bb11: predecessor blocks: bb9 - [20] If (read d$33_@0) then:bb13 else:bb13 fallthrough=bb13 + [20] If (read d$24_@0) then:bb13 else:bb13 fallthrough=bb13 bb13: predecessor blocks: bb11 [21] Const mutate $34_@2 = null - [22] Call mutate mutate$7_@0(mutate d$33_@0, read $34_@2) + [22] Call mutate mutate$7_@0(mutate d$24_@0, read $34_@2) [23] Return ``` @@ -154,10 +146,10 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate a$13_@0[0:23] = Object { } - [2] Let mutate b$14_@0[0:23] = Object { } - [3] Let mutate c$15_@0[0:23] = Object { } - [4] Let mutate d$16_@0[0:23] = Object { } + [1] Let mutate a$18_@0[0:23] = Object { } + [2] Let mutate b$20_@0[0:23] = Object { } + [3] Let mutate c$22_@0[0:23] = Object { } + [4] Let mutate d$24_@0[0:23] = Object { } "] bb0_instrs --> bb0_terminal(["While"]) end @@ -169,13 +161,13 @@ flowchart TB end subgraph bb3 bb3_instrs[" - [8] Let mutate z$19_@0[0:23] = read a$18_@0 - [9] Reassign mutate a$21_@0[0:23] = read b$20_@0 - [10] Reassign mutate b$23_@0[0:23] = read c$22_@0 - [11] Reassign mutate c$25_@0[0:23] = read d$24_@0 - [12] Reassign mutate d$26_@0[0:23] = read z$19_@0 - [13] Call mutate mutate$7_@0(mutate a$21_@0, mutate b$23_@0) - [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$21_@0) + [8] Const mutate z$19_@0[0:23] = read a$18_@0 + [9] Reassign mutate a$18_@0[0:23] = read b$20_@0 + [10] Reassign mutate b$20_@0[0:23] = read c$22_@0 + [11] Reassign mutate c$22_@0[0:23] = read d$24_@0 + [12] Reassign mutate d$24_@0[0:23] = read z$19_@0 + [13] Call mutate mutate$7_@0(mutate a$18_@0, mutate b$20_@0) + [14] Const mutate $29_@0[0:23] = Call mutate cond$8_@0(mutate a$18_@0) "] bb3_instrs --> bb3_terminal(["If (read $29_@0)"]) end @@ -183,21 +175,21 @@ flowchart TB bb4_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["If (read a$30_@0)"]) + bb2_terminal(["If (read a$18_@0)"]) end subgraph bb7 - bb7_terminal(["If (read b$31_@0)"]) + bb7_terminal(["If (read b$20_@0)"]) end subgraph bb9 - bb9_terminal(["If (read c$32_@0)"]) + bb9_terminal(["If (read c$22_@0)"]) end subgraph bb11 - bb11_terminal(["If (read d$33_@0)"]) + bb11_terminal(["If (read d$24_@0)"]) end subgraph bb13 bb13_instrs[" [21] Const mutate $34_@2 = null - [22] Call mutate mutate$7_@0(mutate d$33_@0, read $34_@2) + [22] Call mutate mutate$7_@0(mutate d$24_@0, read $34_@2) "] bb13_instrs --> bb13_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md index 58b79e8e30..d4f912a8c0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md @@ -92,10 +92,10 @@ function cond$0() {} ``` bb0: - [1] Let mutate a$12_@0[0:18] = Object { } - [2] Let mutate b$13_@0[0:18] = Object { } - [3] Let mutate c$14_@1 = Object { } - [4] Let mutate d$15_@0[0:18] = Object { } + [1] Const mutate a$12_@0[0:18] = Object { } + [2] Const mutate b$13_@0[0:18] = Object { } + [3] Const mutate c$14_@1 = Object { } + [4] Const mutate d$15_@0[0:18] = Object { } [5] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb4 @@ -136,10 +136,10 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate a$12_@0[0:18] = Object { } - [2] Let mutate b$13_@0[0:18] = Object { } - [3] Let mutate c$14_@1 = Object { } - [4] Let mutate d$15_@0[0:18] = Object { } + [1] Const mutate a$12_@0[0:18] = Object { } + [2] Const mutate b$13_@0[0:18] = Object { } + [3] Const mutate c$14_@1 = Object { } + [4] Const mutate d$15_@0[0:18] = Object { } "] bb0_instrs --> bb0_terminal(["While"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md index 97cc7a29ec..515a3143ff 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-interleaved.expect.md @@ -15,8 +15,8 @@ function foo(a, b) { ``` bb0: - [1] Let mutate x$7_@0[1:5] = Array [] - [2] Let mutate y$8_@0[1:5] = Array [] + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@0[1:5] = Array [] [3] Call mutate x$7_@0.push(read a$5) [4] Call mutate y$8_@0.push(read b$6) [5] Return @@ -32,8 +32,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$7_@0[1:5] = Array [] - [2] Let mutate y$8_@0[1:5] = Array [] + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@0[1:5] = Array [] [3] Call mutate x$7_@0.push(read a$5) [4] Call mutate y$8_@0.push(read b$6) "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md index e31eebbaa1..d62b0ae459 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowed.expect.md @@ -15,8 +15,8 @@ function foo(a, b) { ``` bb0: - [1] Let mutate x$7_@0[1:5] = Array [] - [2] Let mutate y$8_@1[2:4] = Array [] + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@1[2:4] = Array [] [3] Call mutate y$8_@1.push(read b$6) [4] Call mutate x$7_@0.push(read a$5) [5] Return @@ -32,8 +32,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$7_@0[1:5] = Array [] - [2] Let mutate y$8_@1[2:4] = Array [] + [1] Const mutate x$7_@0[1:5] = Array [] + [2] Const mutate y$8_@1[2:4] = Array [] [3] Call mutate y$8_@1.push(read b$6) [4] Call mutate x$7_@0.push(read a$5) "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md index 43f7316eb8..424d34233d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md @@ -21,11 +21,11 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$11_@0[1:11] = Array [] + [1] Const mutate x$11_@0[1:11] = Array [] [2] If (read a$8) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate y$12_@1[3:7] = Array [] + [3] Const mutate y$12_@1[3:7] = Array [] [4] If (read b$9) then:bb4 else:bb3 fallthrough=bb3 bb4: predecessor blocks: bb2 @@ -57,13 +57,13 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$11_@0[1:11] = Array [] + [1] Const mutate x$11_@0[1:11] = Array [] "] bb0_instrs --> bb0_terminal(["If (read a$8)"]) end subgraph bb2 bb2_instrs[" - [3] Let mutate y$12_@1[3:7] = Array [] + [3] Const mutate y$12_@1[3:7] = Array [] "] bb2_instrs --> bb2_terminal(["If (read b$9)"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md index 9bb61e3ccc..55f85d983e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md @@ -17,8 +17,8 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$9_@0[1:8] = Array [] - [2] Let mutate y$10_@0[1:8] = Array [] + [1] Const mutate x$9_@0[1:8] = Array [] + [2] Const mutate y$10_@0[1:8] = Array [] [3] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 @@ -44,8 +44,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$9_@0[1:8] = Array [] - [2] Let mutate y$10_@0[1:8] = Array [] + [1] Const mutate x$9_@0[1:8] = Array [] + [2] Const mutate y$10_@0[1:8] = Array [] "] bb0_instrs --> bb0_terminal(["While"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md index fdf3a1010d..e471dd7995 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md @@ -21,11 +21,11 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$9_@0[1:9] = Array [] + [1] Const mutate x$9_@0[1:9] = Array [] [2] If (read a$6) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate y$10_@0[1:9] = Array [] + [3] Const mutate y$10_@0[1:9] = Array [] [4] If (read b$7) then:bb4 else:bb3 fallthrough=bb3 bb4: predecessor blocks: bb2 @@ -51,13 +51,13 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$9_@0[1:9] = Array [] + [1] Const mutate x$9_@0[1:9] = Array [] "] bb0_instrs --> bb0_terminal(["If (read a$6)"]) end subgraph bb2 bb2_instrs[" - [3] Let mutate y$10_@0[1:9] = Array [] + [3] Const mutate y$10_@0[1:9] = Array [] "] bb2_instrs --> bb2_terminal(["If (read b$7)"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md index 008aca38f8..9173a7c6fa 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md @@ -18,9 +18,9 @@ function foo() { ``` bb0: - [1] Let mutate x$4_@0[1:6] = Object { } - [2] Let mutate y$5_@1[2:5] = Array [] - [3] Let mutate z$6_@1[2:5] = Object { } + [1] Const mutate x$4_@0[1:6] = Object { } + [2] Const mutate y$5_@1[2:5] = Array [] + [3] Const mutate z$6_@1[2:5] = Object { } [4] Call mutate y$5_@1.push(mutate z$6_@1) [5] Reassign mutate x$4_@0.y[1:6] = read y$5_@1 [6] Return freeze x$4_@0 @@ -35,9 +35,9 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$4_@0[1:6] = Object { } - [2] Let mutate y$5_@1[2:5] = Array [] - [3] Let mutate z$6_@1[2:5] = Object { } + [1] Const mutate x$4_@0[1:6] = Object { } + [2] Const mutate y$5_@1[2:5] = Array [] + [3] Const mutate z$6_@1[2:5] = Object { } [4] Call mutate y$5_@1.push(mutate z$6_@1) [5] Reassign mutate x$4_@0.y[1:6] = read y$5_@1 "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md index 6aa83da0dd..aa6d913ec8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md @@ -19,7 +19,7 @@ function f(a, b) { ``` bb0: - [1] Let mutate x$10_@0[1:8] = Array [] + [1] Const mutate x$10_@0[1:8] = Array [] [2] Const mutate $11_@1 = 1 [3] Const mutate $12_@2 = Binary read a$8.length === read $11_@1 [4] If (read $12_@2) then:bb2 else:bb1 fallthrough=bb1 @@ -53,7 +53,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$10_@0[1:8] = Array [] + [1] Const mutate x$10_@0[1:8] = Array [] [2] Const mutate $11_@1 = 1 [3] Const mutate $12_@2 = Binary read a$8.length === read $11_@1 "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md index fcefff2c63..8138b36630 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md @@ -25,28 +25,29 @@ function Component(props) { bb0: [1] Let mutate x$7_@0[1:7] = Array [] [2] Call mutate x$7_@0.push(read props$6.p0) - [3] Let mutate y$8_@0[1:7] = read x$7_@0 + [3] Const mutate y$8_@0[1:7] = read x$7_@0 [4] If (read props$6.p1) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$9_@0[1:7] = Array [] + [5] Reassign mutate x$7_@0[1:7] = Array [] [6] Goto bb1 bb1: predecessor blocks: bb2 bb0 - x$11_@0[1:7]: phi(bb2: x$9_@0, bb0: x$7_@0) - [7] Let mutate _$12_@1 = JSX + [7] Const mutate _$12_@1 = JSX [8] Call read y$8_@0.push(read props$6.p2) - [9] Const mutate $15_@2 = JSX + [9] Const mutate $15_@2 = JSX [10] Return read $15_@2 scope0 [1:7]: - read props$6.p0 - read props$6.p1 scope1 [7:8]: - read Component$0 + - freeze x$7_@0 - read y$8_@0.push - read props$6.p2 scope2 [9:10]: - read Component$0 + - read x$7_@0 - read y$8_@0 ``` @@ -59,21 +60,21 @@ flowchart TB bb0_instrs[" [1] Let mutate x$7_@0[1:7] = Array [] [2] Call mutate x$7_@0.push(read props$6.p0) - [3] Let mutate y$8_@0[1:7] = read x$7_@0 + [3] Const mutate y$8_@0[1:7] = read x$7_@0 "] bb0_instrs --> bb0_terminal(["If (read props$6.p1)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$9_@0[1:7] = Array [] + [5] Reassign mutate x$7_@0[1:7] = Array [] "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [7] Let mutate _$12_@1 = JSX + [7] Const mutate _$12_@1 = JSX [8] Call read y$8_@0.push(read props$6.p2) - [9] Const mutate $15_@2 = JSX + [9] Const mutate $15_@2 = JSX "] bb1_instrs --> bb1_terminal(["Return read $15_@2"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md index c15bd7a239..cf5079a158 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md @@ -34,7 +34,7 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$16_@0[1:5] = Array [] + [1] Const mutate x$16_@0[1:5] = Array [] [2] If (read a$13) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 @@ -43,30 +43,30 @@ bb2: bb1: predecessor blocks: bb2 bb0 [5] Const mutate $17_@1 = "div" - [6] Let mutate y$19_@2 = JSX {freeze x$16_@0} + [6] Const mutate y$19_@2 = JSX {freeze x$16_@0} [7] Const mutate $20_@3 = 0 + [8] Let mutate x$22_@4[8:15] = undefined [8] Switch (read b$14) Case read $20_@3: bb5 Default: bb4 Fallthrough: bb3 bb5: predecessor blocks: bb1 - [9] Reassign mutate x$22_@4[9:14] = Array [] + [9] Reassign mutate x$22_@4[8:15] = Array [] [10] Call mutate x$22_@4.push(read b$14) [11] Goto bb3 bb4: predecessor blocks: bb1 - [12] Reassign mutate x$23_@4[9:14] = Array [] - [13] Call mutate x$23_@4.push(read c$15) + [12] Reassign mutate x$22_@4[8:15] = Array [] + [13] Call mutate x$22_@4.push(read c$15) [14] Goto bb3 bb3: predecessor blocks: bb5 bb4 - x$30_@4[9:14]: phi(bb5: x$22_@4, bb4: x$23_@4) [15] Const mutate $25_@5 = "div" [16] Const mutate $26_@6 = "\n " [17] Const mutate $27_@7 = "\n " [18] Const mutate $28_@8 = "\n " - [19] Const mutate $31_@9 = JSX {read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$30_@4}{read $28_@8} + [19] Const mutate $31_@9 = JSX {read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$22_@4}{read $28_@8} [20] Return read $31_@9 scope0 [1:5]: - read a$13 @@ -74,7 +74,7 @@ scope0 [1:5]: scope2 [6:7]: - read $17_@1 - freeze x$16_@0 -scope4 [9:14]: +scope4 [8:15]: - read c$15 - read b$14 - read b$14 @@ -83,6 +83,7 @@ scope9 [19:20]: - read $26_@6 - read y$19_@2 - read $27_@7 + - freeze x$22_@4 - read $28_@8 ``` @@ -93,7 +94,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$16_@0[1:5] = Array [] + [1] Const mutate x$16_@0[1:5] = Array [] "] bb0_instrs --> bb0_terminal(["If (read a$13)"]) end @@ -106,22 +107,23 @@ flowchart TB subgraph bb1 bb1_instrs[" [5] Const mutate $17_@1 = 'div' - [6] Let mutate y$19_@2 = JSX {freeze x$16_@0} + [6] Const mutate y$19_@2 = JSX {freeze x$16_@0} [7] Const mutate $20_@3 = 0 + [8] Let mutate x$22_@4[8:15] = undefined "] bb1_instrs --> bb1_terminal(["Switch (read b$14)"]) end subgraph bb5 bb5_instrs[" - [9] Reassign mutate x$22_@4[9:14] = Array [] + [9] Reassign mutate x$22_@4[8:15] = Array [] [10] Call mutate x$22_@4.push(read b$14) "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb4 bb4_instrs[" - [12] Reassign mutate x$23_@4[9:14] = Array [] - [13] Call mutate x$23_@4.push(read c$15) + [12] Reassign mutate x$22_@4[8:15] = Array [] + [13] Call mutate x$22_@4.push(read c$15) "] bb4_instrs --> bb4_terminal(["Goto"]) end @@ -131,7 +133,7 @@ flowchart TB [16] Const mutate $26_@6 = '\n ' [17] Const mutate $27_@7 = '\n ' [18] Const mutate $28_@8 = '\n ' - [19] Const mutate $31_@9 = JSX {read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$30_@4}{read $28_@8} + [19] Const mutate $31_@9 = JSX {read $26_@6}{read y$19_@2}{read $27_@7}{freeze x$22_@4}{read $28_@8} "] bb3_instrs --> bb3_terminal(["Return read $31_@9"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md index 2b5d7d45de..2f627e55ef 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md @@ -21,11 +21,11 @@ function Component(props) { ``` bb0: - [1] Let mutate x$7_@0[1:7] = Array [] + [1] Const mutate x$7_@0[1:7] = Array [] [2] Call mutate x$7_@0.push(read props$6.p0) - [3] Let mutate y$8_@0[1:7] = read x$7_@0 - [4] Reassign mutate x$9_@1 = Array [] - [5] Let mutate _$10_@2 = JSX + [3] Const mutate y$8_@0[1:7] = read x$7_@0 + [4] Const mutate x$9_@1 = Array [] + [5] Const mutate _$10_@2 = JSX [6] Call mutate y$8_@0.push(read props$6.p1) [7] Const mutate $11_@3 = JSX [8] Return read $11_@3 @@ -48,11 +48,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$7_@0[1:7] = Array [] + [1] Const mutate x$7_@0[1:7] = Array [] [2] Call mutate x$7_@0.push(read props$6.p0) - [3] Let mutate y$8_@0[1:7] = read x$7_@0 - [4] Reassign mutate x$9_@1 = Array [] - [5] Let mutate _$10_@2 = JSX + [3] Const mutate y$8_@0[1:7] = read x$7_@0 + [4] Const mutate x$9_@1 = Array [] + [5] Const mutate _$10_@2 = JSX [6] Call mutate y$8_@0.push(read props$6.p1) [7] Const mutate $11_@3 = JSX "] diff --git a/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md index 4133c31866..23006a17e7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md @@ -36,54 +36,56 @@ function Component(props) { ``` bb0: - [1] Let mutate x$7_@0 = undefined + [1] Const mutate x$7_@0 = undefined + [2] Let mutate x$11_@1[2:18] = undefined [2] If (read props$6.cond) then:bb2 else:bb10 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Const mutate $8_@1 = 2 - [4] Const mutate $9_@2 = 1 - [5] Const mutate $10_@3 = 0 + [3] Const mutate $8_@2 = 2 + [4] Const mutate $9_@3 = 1 + [5] Const mutate $10_@4 = 0 [6] Switch (read props$6.test) - Case read $10_@3: bb8 - Case read $9_@2: bb6 - Case read $8_@1: bb4 + Case read $10_@4: bb8 + Case read $9_@3: bb6 + Case read $8_@2: bb4 Default: bb4 Fallthrough: bb1 bb8: predecessor blocks: bb2 - [7] Reassign mutate x$11_@4[7:17] = read props$6.v0 + [7] Reassign mutate x$11_@1[2:18] = read props$6.v0 [8] Goto bb1 bb6: predecessor blocks: bb2 - [9] Reassign mutate x$12_@4[7:17] = read props$6.v1 + [9] Reassign mutate x$11_@1[2:18] = read props$6.v1 [10] Goto bb1 bb4: predecessor blocks: bb2 - [11] Reassign mutate x$13_@4[7:17] = read props$6.v2 + [11] Reassign mutate x$11_@1[2:18] = read props$6.v2 [12] Goto bb1 bb10: predecessor blocks: bb0 [13] If (read props$6.cond2) then:bb12 else:bb13 fallthrough=bb1 bb12: predecessor blocks: bb10 - [14] Reassign mutate x$14_@4[7:17] = read props$6.b + [14] Reassign mutate x$11_@1[2:18] = read props$6.b [15] Goto bb1 bb13: predecessor blocks: bb10 - [16] Reassign mutate x$15_@4[7:17] = read props$6.c + [16] Reassign mutate x$11_@1[2:18] = read props$6.c [17] Goto bb1 bb1: predecessor blocks: bb8 bb6 bb4 bb12 bb13 - x$16_@4[7:17]: phi(bb8: x$11_@4, bb6: x$12_@4, bb4: x$13_@4, bb12: x$14_@4, bb13: x$15_@4) - [18] read x$16_@4 + [18] read x$11_@1 [19] Return -scope4 [7:17]: +scope1 [2:18]: - read props$6.v2 - read props$6.v1 - read props$6.v0 - read props$6.test - read props$6.b - read props$6.c + - read props$6.cond2 + - read props$6.cond ``` ### CFG @@ -93,33 +95,34 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$7_@0 = undefined + [1] Const mutate x$7_@0 = undefined + [2] Let mutate x$11_@1[2:18] = undefined "] bb0_instrs --> bb0_terminal(["If (read props$6.cond)"]) end subgraph bb2 bb2_instrs[" - [3] Const mutate $8_@1 = 2 - [4] Const mutate $9_@2 = 1 - [5] Const mutate $10_@3 = 0 + [3] Const mutate $8_@2 = 2 + [4] Const mutate $9_@3 = 1 + [5] Const mutate $10_@4 = 0 "] bb2_instrs --> bb2_terminal(["Switch (read props$6.test)"]) end subgraph bb8 bb8_instrs[" - [7] Reassign mutate x$11_@4[7:17] = read props$6.v0 + [7] Reassign mutate x$11_@1[2:18] = read props$6.v0 "] bb8_instrs --> bb8_terminal(["Goto"]) end subgraph bb6 bb6_instrs[" - [9] Reassign mutate x$12_@4[7:17] = read props$6.v1 + [9] Reassign mutate x$11_@1[2:18] = read props$6.v1 "] bb6_instrs --> bb6_terminal(["Goto"]) end subgraph bb4 bb4_instrs[" - [11] Reassign mutate x$13_@4[7:17] = read props$6.v2 + [11] Reassign mutate x$11_@1[2:18] = read props$6.v2 "] bb4_instrs --> bb4_terminal(["Goto"]) end @@ -128,19 +131,19 @@ flowchart TB end subgraph bb12 bb12_instrs[" - [14] Reassign mutate x$14_@4[7:17] = read props$6.b + [14] Reassign mutate x$11_@1[2:18] = read props$6.b "] bb12_instrs --> bb12_terminal(["Goto"]) end subgraph bb13 bb13_instrs[" - [16] Reassign mutate x$15_@4[7:17] = read props$6.c + [16] Reassign mutate x$11_@1[2:18] = read props$6.c "] bb13_instrs --> bb13_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [18] read x$16_@4 + [18] read x$11_@1 "] bb1_instrs --> bb1_terminal(["Return"]) end @@ -149,9 +152,9 @@ flowchart TB bb0_terminal -- "then" --> bb2 bb0_terminal -- "else" --> bb10 bb0_terminal -- "fallthrough" --> bb1 - bb2_terminal -- "read $10_@3" --> bb8 - bb2_terminal -- "read $9_@2" --> bb6 - bb2_terminal -- "read $8_@1" --> bb4 + bb2_terminal -- "read $10_@4" --> bb8 + bb2_terminal -- "read $9_@3" --> bb6 + bb2_terminal -- "read $8_@2" --> bb4 bb2_terminal -- "default" --> bb4 bb2_terminal -- "fallthrough" --> bb1 bb8_terminal --> bb1 diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md index f2ad814ebd..9292e01da1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md @@ -47,12 +47,12 @@ function mutate$0() {} ``` bb0: - [1] Let mutate a$5_@0 = Object { } - [2] Let mutate b$6_@1[0:8] = Object { } - [3] Let mutate c$7_@1[0:8] = Object { } - [4] Reassign mutate a$8_@1[0:8] = read b$6_@1 - [5] Reassign mutate b$9_@1[0:8] = read c$7_@1 - [6] Reassign mutate c$10_@1[0:8] = read a$8_@1 + [1] Const mutate a$5_@0 = Object { } + [2] Const mutate b$6_@1[0:8] = Object { } + [3] Const mutate c$7_@1[0:8] = Object { } + [4] Const mutate a$8_@1[0:8] = read b$6_@1 + [5] Const mutate b$9_@1[0:8] = read c$7_@1 + [6] Const mutate c$10_@1[0:8] = read a$8_@1 [7] Call mutate mutate$4_@1(mutate a$8_@1, mutate b$9_@1) [8] Return freeze c$10_@1 @@ -65,12 +65,12 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate a$5_@0 = Object { } - [2] Let mutate b$6_@1[0:8] = Object { } - [3] Let mutate c$7_@1[0:8] = Object { } - [4] Reassign mutate a$8_@1[0:8] = read b$6_@1 - [5] Reassign mutate b$9_@1[0:8] = read c$7_@1 - [6] Reassign mutate c$10_@1[0:8] = read a$8_@1 + [1] Const mutate a$5_@0 = Object { } + [2] Const mutate b$6_@1[0:8] = Object { } + [3] Const mutate c$7_@1[0:8] = Object { } + [4] Const mutate a$8_@1[0:8] = read b$6_@1 + [5] Const mutate b$9_@1[0:8] = read c$7_@1 + [6] Const mutate c$10_@1[0:8] = read a$8_@1 [7] Call mutate mutate$4_@1(mutate a$8_@1, mutate b$9_@1) "] bb0_instrs --> bb0_terminal(["Return freeze c$10_@1"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md index 1112def4d9..3b4a9eda96 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md @@ -57,7 +57,7 @@ bb0: bb2: predecessor blocks: bb0 [6] Const mutate $14_@1 = "div" - [7] Let mutate _$15_@2 = JSX + [7] Const mutate _$15_@2 = JSX [8] Goto bb1 bb1: predecessor blocks: bb2 bb0 @@ -90,7 +90,7 @@ flowchart TB subgraph bb2 bb2_instrs[" [6] Const mutate $14_@1 = 'div' - [7] Let mutate _$15_@2 = JSX + [7] Const mutate _$15_@2 = JSX "] bb2_instrs --> bb2_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md index 002fba21e2..9052a9ed43 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md @@ -50,7 +50,7 @@ bb0: [2] Const mutate b$11_@0[0:7] = Object { } [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = "div" - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] Call mutate foo$4_@0(read a$10_@0, mutate b$11_@0) [7] Const mutate $14_@3 = "div" [8] Const mutate $15_@4 = JSX @@ -74,7 +74,7 @@ flowchart TB [2] Const mutate b$11_@0[0:7] = Object { } [3] Call mutate foo$4_@0(mutate a$10_@0, mutate b$11_@0) [4] Const mutate $12_@1 = 'div' - [5] Let mutate _$13_@2 = JSX + [5] Const mutate _$13_@2 = JSX [6] Call mutate foo$4_@0(read a$10_@0, mutate b$11_@0) [7] Const mutate $14_@3 = 'div' [8] Const mutate $15_@4 = JSX diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md index 9a5d73f716..31c40dda46 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md @@ -21,29 +21,28 @@ function foo() { ``` bb0: - [1] Let mutate x$7_@0[1:14] = 1 - [2] Let mutate y$8_@1 = 2 + [1] Let mutate x$7_@0[1:8] = 1 + [2] Const mutate y$8_@1 = 2 [3] Const mutate $9_@2 = 2 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2 [5] If (read $10_@3) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [6] Reassign mutate x$11_@0[1:14] = 3 + [6] Reassign mutate x$7_@0[1:8] = 3 [7] Goto bb1 bb1: predecessor blocks: bb2 bb0 - x$17_@0[1:14]: phi(bb2: x$11_@0, bb0: x$7_@0) [8] Const mutate $12_@4 = 3 [9] Const mutate $14_@5 = Binary read y$8_@1 === read $12_@4 + [10] Let mutate x$15_@6[1:14] = undefined [10] If (read $14_@5) then:bb4 else:bb3 fallthrough=bb3 bb4: predecessor blocks: bb1 - [11] Reassign mutate x$15_@0[1:14] = 5 + [11] Reassign mutate x$15_@6[1:14] = 5 [12] Goto bb3 bb3: predecessor blocks: bb4 bb1 - x$16_@0[1:14]: phi(bb4: x$15_@0, bb1: x$17_@0) - [13] Reassign mutate y$18_@0[1:14] = read x$16_@0 + [13] Const mutate y$18_@6[1:14] = read x$15_@6 [14] Return scope3 [4:5]: - read y$8_@1 @@ -60,8 +59,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$7_@0[1:14] = 1 - [2] Let mutate y$8_@1 = 2 + [1] Let mutate x$7_@0[1:8] = 1 + [2] Const mutate y$8_@1 = 2 [3] Const mutate $9_@2 = 2 [4] Const mutate $10_@3 = Binary read y$8_@1 === read $9_@2 "] @@ -69,7 +68,7 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [6] Reassign mutate x$11_@0[1:14] = 3 + [6] Reassign mutate x$7_@0[1:8] = 3 "] bb2_instrs --> bb2_terminal(["Goto"]) end @@ -77,18 +76,19 @@ flowchart TB bb1_instrs[" [8] Const mutate $12_@4 = 3 [9] Const mutate $14_@5 = Binary read y$8_@1 === read $12_@4 + [10] Let mutate x$15_@6[1:14] = undefined "] bb1_instrs --> bb1_terminal(["If (read $14_@5)"]) end subgraph bb4 bb4_instrs[" - [11] Reassign mutate x$15_@0[1:14] = 5 + [11] Reassign mutate x$15_@6[1:14] = 5 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [13] Reassign mutate y$18_@0[1:14] = read x$16_@0 + [13] Const mutate y$18_@6[1:14] = read x$15_@6 "] bb3_instrs --> bb3_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md index 8f2d5e5db9..924f0f0f7e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md @@ -19,18 +19,17 @@ function foo() { ``` bb0: [1] Let mutate x$5_@0[1:9] = 1 - [2] Let mutate y$6_@1 = 2 + [2] Const mutate y$6_@1 = 2 [3] Const mutate $7_@2 = 2 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2 [5] If (read $8_@3) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [6] Reassign mutate x$9_@0[1:9] = 3 + [6] Reassign mutate x$5_@0[1:9] = 3 [7] Goto bb1 bb1: predecessor blocks: bb2 bb0 - x$10_@0[1:9]: phi(bb2: x$9_@0, bb0: x$5_@0) - [8] Reassign mutate y$11_@0[1:9] = read x$10_@0 + [8] Const mutate y$11_@0[1:9] = read x$5_@0 [9] Return scope3 [4:5]: - read y$6_@1 @@ -45,7 +44,7 @@ flowchart TB subgraph bb0 bb0_instrs[" [1] Let mutate x$5_@0[1:9] = 1 - [2] Let mutate y$6_@1 = 2 + [2] Const mutate y$6_@1 = 2 [3] Const mutate $7_@2 = 2 [4] Const mutate $8_@3 = Binary read y$6_@1 === read $7_@2 "] @@ -53,13 +52,13 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [6] Reassign mutate x$9_@0[1:9] = 3 + [6] Reassign mutate x$5_@0[1:9] = 3 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [8] Reassign mutate y$11_@0[1:9] = read x$10_@0 + [8] Const mutate y$11_@0[1:9] = read x$5_@0 "] bb1_instrs --> bb1_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md index 7aafc6d070..3b6f55073b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-of.expect.md @@ -19,18 +19,18 @@ function foo(cond) { ``` bb0: - [1] Let mutate items$5_@0 = Array [] + [1] Const mutate items$5_@0 = Array [] [2] Goto bb1 bb1: predecessor blocks: bb0 bb4 [3] If (read items$5_@0) then:bb3 else:bb2 fallthrough=bb2 bb3: predecessor blocks: bb1 - [4] Let mutate y$7_@1 = 0 + [4] Const mutate y$7_@1 = 0 [5] If (read cond$4) then:bb5 else:bb4 fallthrough=bb4 bb5: predecessor blocks: bb3 - [6] Reassign mutate y$9_@2 = 1 + [6] Const mutate y$9_@2 = 1 [7] Goto bb4 bb4: predecessor blocks: bb5 bb3 @@ -48,7 +48,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate items$5_@0 = Array [] + [1] Const mutate items$5_@0 = Array [] "] bb0_instrs --> bb0_terminal(["Goto"]) end @@ -57,13 +57,13 @@ flowchart TB end subgraph bb3 bb3_instrs[" - [4] Let mutate y$7_@1 = 0 + [4] Const mutate y$7_@1 = 0 "] bb3_instrs --> bb3_terminal(["If (read cond$4)"]) end subgraph bb5 bb5_instrs[" - [6] Reassign mutate y$9_@2 = 1 + [6] Const mutate y$9_@2 = 1 "] bb5_instrs --> bb5_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md index 895cb9f422..bdc078f059 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md @@ -20,18 +20,17 @@ bb0: [2] For init=bb3 test=bb1 loop=bb5 update=bb4 fallthrough=bb2 bb3: predecessor blocks: bb0 - [3] Let mutate i$8_@1[3:13] = 0 + [3] Const mutate i$8_@1[3:13] = 0 [4] Goto bb1 bb1: predecessor blocks: bb3 bb4 - x$13_@0[1:13]: phi(bb3: x$7_@0, bb4: x$14_@0) [5] Const mutate $9_@2 = 10 [6] Const mutate $11_@3[6:8] = Binary read i$8_@1 < read $9_@2 [7] If (read $11_@3) then:bb5 else:bb2 fallthrough=bb2 bb5: predecessor blocks: bb1 [8] Const mutate $12_@4 = 1 - [9] Reassign mutate x$14_@0[1:13] = Binary read x$13_@0 + read $12_@4 + [9] Reassign mutate x$7_@0[1:13] = Binary read x$7_@0 + read $12_@4 [10] Goto(Continue) bb4 bb4: predecessor blocks: bb5 @@ -39,7 +38,7 @@ bb4: [12] Goto bb1 bb2: predecessor blocks: bb1 - [13] Return read x$13_@0 + [13] Return read x$7_@0 scope3 [6:8]: - read $9_@2 ``` @@ -57,7 +56,7 @@ flowchart TB end subgraph bb3 bb3_instrs[" - [3] Let mutate i$8_@1[3:13] = 0 + [3] Const mutate i$8_@1[3:13] = 0 "] bb3_instrs --> bb3_terminal(["Goto"]) end @@ -71,7 +70,7 @@ flowchart TB subgraph bb5 bb5_instrs[" [8] Const mutate $12_@4 = 1 - [9] Reassign mutate x$14_@0[1:13] = Binary read x$13_@0 + read $12_@4 + [9] Reassign mutate x$7_@0[1:13] = Binary read x$7_@0 + read $12_@4 "] bb5_instrs --> bb5_terminal(["Goto"]) end @@ -82,7 +81,7 @@ flowchart TB bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["Return read x$13_@0"]) + bb2_terminal(["Return read x$7_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md index cc530e4c59..fa34e500b8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md @@ -19,16 +19,16 @@ function foo() { ``` bb0: - [1] Let mutate x$5_@0 = 1 - [2] Let mutate y$6_@1 = 2 + [1] Const mutate x$5_@0 = 1 + [2] Const mutate y$6_@1 = 2 [3] If (read y$6_@1) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1 + [4] Const mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1 [5] Goto bb1 bb3: predecessor blocks: bb0 - [6] Let mutate z$8_@3 = read x$5_@0 + [6] Const mutate z$8_@3 = read x$5_@0 [7] Goto bb1 bb1: predecessor blocks: bb2 bb3 @@ -47,20 +47,20 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$5_@0 = 1 - [2] Let mutate y$6_@1 = 2 + [1] Const mutate x$5_@0 = 1 + [2] Const mutate y$6_@1 = 2 "] bb0_instrs --> bb0_terminal(["If (read y$6_@1)"]) end subgraph bb2 bb2_instrs[" - [4] Let mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1 + [4] Const mutate z$7_@2 = Binary read x$5_@0 + read y$6_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Let mutate z$8_@3 = read x$5_@0 + [6] Const mutate z$8_@3 = read x$5_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md index 9cc8ded1f7..f834e51a43 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md @@ -28,25 +28,25 @@ function foo(a, b, c, d) { ``` bb0: - [1] Let mutate x$13_@0 = 0 + [1] Const mutate x$13_@0 = 0 [2] Const mutate $14_@1 = true + [3] Let mutate x$18_@2[3:20] = undefined [3] If (read $14_@1) then:bb2 else:bb6 fallthrough=bb1 bb2: predecessor blocks: bb0 - [4] Const mutate $15_@2 = true - [5] If (read $15_@2) then:bb4 else:bb5 fallthrough=bb3 + [4] Const mutate $15_@3 = true + [5] If (read $15_@3) then:bb4 else:bb5 fallthrough=bb3 bb4: predecessor blocks: bb2 - [6] Reassign mutate x$16_@3[6:17] = read a$9 + [6] Reassign mutate x$18_@2[3:20] = read a$9 [7] Goto bb3 bb5: predecessor blocks: bb2 - [8] Reassign mutate x$17_@3[6:17] = read b$10 + [8] Reassign mutate x$18_@2[3:20] = read b$10 [9] Goto bb3 bb3: predecessor blocks: bb4 bb5 - x$18_@3[6:17]: phi(bb4: x$16_@3, bb5: x$17_@3) - [10] read x$18_@3 + [10] read x$18_@2 [11] Goto bb1 bb6: predecessor blocks: bb0 @@ -54,28 +54,26 @@ bb6: [13] If (read $19_@4) then:bb8 else:bb9 fallthrough=bb7 bb8: predecessor blocks: bb6 - [14] Reassign mutate x$20_@3[6:17] = read c$11 + [14] Reassign mutate x$18_@2[3:20] = read c$11 [15] Goto bb7 bb9: predecessor blocks: bb6 - [16] Reassign mutate x$21_@3[6:17] = read d$12 + [16] Reassign mutate x$18_@2[3:20] = read d$12 [17] Goto bb7 bb7: predecessor blocks: bb8 bb9 - x$22_@3[6:17]: phi(bb8: x$20_@3, bb9: x$21_@3) - [18] read x$22_@3 + [18] read x$18_@2 [19] Goto bb1 bb1: predecessor blocks: bb3 bb7 - x$23_@3[6:17]: phi(bb3: x$18_@3, bb7: x$22_@3) - [20] read x$23_@3 + [20] read x$18_@2 [21] Return -scope3 [6:17]: +scope2 [3:20]: - read a$9 - read b$10 - - read $15_@2 - read c$11 - read d$12 + - read $14_@1 ``` ### CFG @@ -85,32 +83,33 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$13_@0 = 0 + [1] Const mutate x$13_@0 = 0 [2] Const mutate $14_@1 = true + [3] Let mutate x$18_@2[3:20] = undefined "] bb0_instrs --> bb0_terminal(["If (read $14_@1)"]) end subgraph bb2 bb2_instrs[" - [4] Const mutate $15_@2 = true + [4] Const mutate $15_@3 = true "] - bb2_instrs --> bb2_terminal(["If (read $15_@2)"]) + bb2_instrs --> bb2_terminal(["If (read $15_@3)"]) end subgraph bb4 bb4_instrs[" - [6] Reassign mutate x$16_@3[6:17] = read a$9 + [6] Reassign mutate x$18_@2[3:20] = read a$9 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb5 bb5_instrs[" - [8] Reassign mutate x$17_@3[6:17] = read b$10 + [8] Reassign mutate x$18_@2[3:20] = read b$10 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [10] read x$18_@3 + [10] read x$18_@2 "] bb3_instrs --> bb3_terminal(["Goto"]) end @@ -122,25 +121,25 @@ flowchart TB end subgraph bb8 bb8_instrs[" - [14] Reassign mutate x$20_@3[6:17] = read c$11 + [14] Reassign mutate x$18_@2[3:20] = read c$11 "] bb8_instrs --> bb8_terminal(["Goto"]) end subgraph bb9 bb9_instrs[" - [16] Reassign mutate x$21_@3[6:17] = read d$12 + [16] Reassign mutate x$18_@2[3:20] = read d$12 "] bb9_instrs --> bb9_terminal(["Goto"]) end subgraph bb7 bb7_instrs[" - [18] read x$22_@3 + [18] read x$18_@2 "] bb7_instrs --> bb7_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [20] read x$23_@3 + [20] read x$18_@2 "] bb1_instrs --> bb1_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md index e0f0d190f6..f7f1e79e03 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md @@ -21,7 +21,7 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$9_@0 = 0 + [1] Const mutate x$9_@0 = 0 [2] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb5 @@ -63,7 +63,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$9_@0 = 0 + [1] Const mutate x$9_@0 = 0 "] bb0_instrs --> bb0_terminal(["While"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md new file mode 100644 index 0000000000..3d00090cd2 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md @@ -0,0 +1,99 @@ + +## Input + +```javascript +function foo(a, b, c) { + let x = a; + if (b) { + if (c) { + x = c; + } + x; + } +} + +``` + +## HIR + +``` +bb0: + [1] Const mutate x$8_@0[1:8] = read a$5 + [2] If (read b$6) then:bb2 else:bb1 fallthrough=bb1 +bb2: + predecessor blocks: bb0 + [3] If (read c$7) then:bb4 else:bb3 fallthrough=bb3 +bb4: + predecessor blocks: bb2 + [4] Reassign mutate x$8_@0[1:8] = read c$7 + [5] Goto bb3 +bb3: + predecessor blocks: bb4 bb2 + [6] read x$8_@0 + [7] Goto bb1 +bb1: + predecessor blocks: bb3 bb0 + [8] Return +scope0 [1:8]: + - read a$5 + - read c$7 + - read c$7 + - read b$6 +``` + +### CFG + +```mermaid +flowchart TB + %% Basic Blocks + subgraph bb0 + bb0_instrs[" + [1] Const mutate x$8_@0[1:8] = read a$5 + "] + bb0_instrs --> bb0_terminal(["If (read b$6)"]) + end + subgraph bb2 + bb2_terminal(["If (read c$7)"]) + end + subgraph bb4 + bb4_instrs[" + [4] Reassign mutate x$8_@0[1:8] = read c$7 + "] + bb4_instrs --> bb4_terminal(["Goto"]) + end + subgraph bb3 + bb3_instrs[" + [6] read x$8_@0 + "] + bb3_instrs --> bb3_terminal(["Goto"]) + end + subgraph bb1 + bb1_terminal(["Return"]) + end + + %% Jumps + bb0_terminal -- "then" --> bb2 + bb0_terminal -- "else" --> bb1 + bb2_terminal -- "then" --> bb4 + bb2_terminal -- "else" --> bb3 + bb4_terminal --> bb3 + bb3_terminal --> bb1 + +``` + +## Code + +```javascript +function foo$0(a$5, b$6, c$7) { + const x$8 = a$5; + bb1: if (b$6) { + bb3: if (c$7) { + x$8 = c$7; + } + + x$8; + } +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js new file mode 100644 index 0000000000..9118aa4cc2 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js @@ -0,0 +1,9 @@ +function foo(a, b, c) { + let x = a; + if (b) { + if (c) { + x = c; + } + x; + } +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md index 69b0c972f1..1845d20cfc 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md @@ -24,19 +24,18 @@ bb0: [2] If (read a$7) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Reassign mutate x$13_@0[1:8] = read b$8 + [3] Reassign mutate x$12_@0[1:8] = read b$8 [4] Goto bb1 bb3: predecessor blocks: bb0 [5] If (read c$9) then:bb5 else:bb1 fallthrough=bb1 bb5: predecessor blocks: bb3 - [6] Reassign mutate x$14_@0[1:8] = read d$10 + [6] Reassign mutate x$12_@0[1:8] = read d$10 [7] Goto bb1 bb1: predecessor blocks: bb2 bb5 bb3 - x$15_@0[1:8]: phi(bb2: x$13_@0, bb5: x$14_@0, bb3: x$12_@0) - [8] Return read x$15_@0 + [8] Return read x$12_@0 scope0 [1:8]: - read b$8 - read d$10 @@ -57,7 +56,7 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [3] Reassign mutate x$13_@0[1:8] = read b$8 + [3] Reassign mutate x$12_@0[1:8] = read b$8 "] bb2_instrs --> bb2_terminal(["Goto"]) end @@ -66,12 +65,12 @@ flowchart TB end subgraph bb5 bb5_instrs[" - [6] Reassign mutate x$14_@0[1:8] = read d$10 + [6] Reassign mutate x$12_@0[1:8] = read d$10 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return read x$15_@0"]) + bb1_terminal(["Return read x$12_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md index c9bdd07aad..6a87423160 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md @@ -46,7 +46,7 @@ function Foo$0() {} bb0: [1] Const mutate a$7_@0[0:4] = Array [] [2] Const mutate b$8_@0[0:4] = Object { } - [3] Let mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0) + [3] Const mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0) [4] Return freeze c$9_@0 ``` @@ -60,7 +60,7 @@ flowchart TB bb0_instrs[" [1] Const mutate a$7_@0[0:4] = Array [] [2] Const mutate b$8_@0[0:4] = Object { } - [3] Let mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0) + [3] Const mutate c$9_@0[0:4] = New mutate Foo$5_@0(mutate a$7_@0, mutate b$8_@0) "] bb0_instrs --> bb0_terminal(["Return freeze c$9_@0"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md index 65082830ad..85b5e3dd7d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md @@ -25,24 +25,23 @@ bb0: [1] Let mutate x$6_@0[1:10] = 1 [2] Let mutate y$7_@0[1:10] = 2 [3] Const mutate $8_@2 = 1 - [4] Const mutate $9_@3 = Binary read x$6_@0 > read $8_@2 - [5] If (read $9_@3) then:bb2 else:bb3 fallthrough=bb1 + [4] Const mutate $9_@0[1:10] = Binary read x$6_@0 > read $8_@2 + [5] If (read $9_@0) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [6] Reassign mutate x$10_@0[1:10] = 2 + [6] Reassign mutate x$6_@0[1:10] = 2 [7] Goto bb1 bb3: predecessor blocks: bb0 - [8] Reassign mutate y$11_@0[1:10] = 3 + [8] Reassign mutate y$7_@0[1:10] = 3 [9] Goto bb1 bb1: predecessor blocks: bb2 bb3 - x$12_@0[1:10]: phi(bb2: x$10_@0, bb3: x$6_@0) - y$13_@0[1:10]: phi(bb2: y$7_@0, bb3: y$11_@0) - [10] Let mutate t$14_@4 = Object { x: read x$12_@0, y: read y$13_@0 } - [11] Return freeze t$14_@4 -scope3 [4:5]: - - read $8_@2 + [10] Const mutate t$14_@3 = Object { x: read x$6_@0, y: read y$7_@0 } + [11] Return freeze t$14_@3 +scope3 [10:11]: + - read x$6_@0 + - read y$7_@0 ``` ### CFG @@ -55,27 +54,27 @@ flowchart TB [1] Let mutate x$6_@0[1:10] = 1 [2] Let mutate y$7_@0[1:10] = 2 [3] Const mutate $8_@2 = 1 - [4] Const mutate $9_@3 = Binary read x$6_@0 > read $8_@2 + [4] Const mutate $9_@0[1:10] = Binary read x$6_@0 > read $8_@2 "] - bb0_instrs --> bb0_terminal(["If (read $9_@3)"]) + bb0_instrs --> bb0_terminal(["If (read $9_@0)"]) end subgraph bb2 bb2_instrs[" - [6] Reassign mutate x$10_@0[1:10] = 2 + [6] Reassign mutate x$6_@0[1:10] = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [8] Reassign mutate y$11_@0[1:10] = 3 + [8] Reassign mutate y$7_@0[1:10] = 3 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [10] Let mutate t$14_@4 = Object { x: read x$12_@0, y: read y$13_@0 } + [10] Const mutate t$14_@3 = Object { x: read x$6_@0, y: read y$7_@0 } "] - bb1_instrs --> bb1_terminal(["Return freeze t$14_@4"]) + bb1_instrs --> bb1_terminal(["Return freeze t$14_@3"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md index 3efa4ee7d0..97ab761b76 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md @@ -27,12 +27,12 @@ bb0: [3] If (read a$7) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [4] Let mutate y$10_@0[0:11] = Object { } + [4] Const mutate y$10_@0[0:11] = Object { } [5] Reassign mutate x$9_@0.y[0:11] = read y$10_@0 [6] Goto bb1 bb3: predecessor blocks: bb0 - [7] Let mutate z$11_@0[0:11] = Object { } + [7] Const mutate z$11_@0[0:11] = Object { } [8] Reassign mutate x$9_@0.z[0:11] = read z$11_@0 [9] Goto bb1 bb1: @@ -56,14 +56,14 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [4] Let mutate y$10_@0[0:11] = Object { } + [4] Const mutate y$10_@0[0:11] = Object { } [5] Reassign mutate x$9_@0.y[0:11] = read y$10_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [7] Let mutate z$11_@0[0:11] = Object { } + [7] Const mutate z$11_@0[0:11] = Object { } [8] Reassign mutate x$9_@0.z[0:11] = read z$11_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md index cf4d2aac0d..4e1602d91d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md @@ -24,12 +24,12 @@ bb0: [2] If (read a$5) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate y$7_@1 = Object { } + [3] Const mutate y$7_@1 = Object { } [4] Reassign mutate x$6_@0.y[1:9] = read y$7_@1 [5] Goto bb1 bb3: predecessor blocks: bb0 - [6] Let mutate z$8_@2 = Object { } + [6] Const mutate z$8_@2 = Object { } [7] Reassign mutate x$6_@0.z[1:9] = read z$8_@2 [8] Goto bb1 bb1: @@ -56,14 +56,14 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [3] Let mutate y$7_@1 = Object { } + [3] Const mutate y$7_@1 = Object { } [4] Reassign mutate x$6_@0.y[1:9] = read y$7_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Let mutate z$8_@2 = Object { } + [6] Const mutate z$8_@2 = Object { } [7] Reassign mutate x$6_@0.z[1:9] = read z$8_@2 "] bb3_instrs --> bb3_terminal(["Goto"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md index d61071c942..60db051fe8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md @@ -25,12 +25,12 @@ bb0: [2] If (read a$6) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate y$8_@0[0:10] = Object { } + [3] Const mutate y$8_@0[0:10] = Object { } [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0 [5] Goto bb1 bb3: predecessor blocks: bb0 - [6] Let mutate z$9_@0[0:10] = Object { } + [6] Const mutate z$9_@0[0:10] = Object { } [7] Reassign mutate x$7_@0.z[0:10] = read z$9_@0 [8] Goto bb1 bb1: @@ -53,14 +53,14 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [3] Let mutate y$8_@0[0:10] = Object { } + [3] Const mutate y$8_@0[0:10] = Object { } [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Let mutate z$9_@0[0:10] = Object { } + [6] Const mutate z$9_@0[0:10] = Object { } [7] Reassign mutate x$7_@0.z[0:10] = read z$9_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md index 534b95ad2a..260f00877c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md @@ -25,13 +25,13 @@ bb0: [2] If (read a$6) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate y$8_@0[0:10] = Object { } + [3] Const mutate y$8_@0[0:10] = Object { } [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0 [5] Call mutate mutate$4_@0(mutate y$8_@0) [6] Goto bb1 bb3: predecessor blocks: bb0 - [7] Let mutate z$9_@1 = Object { } + [7] Const mutate z$9_@1 = Object { } [8] Reassign mutate x$7_@0.z[0:10] = read z$9_@1 [9] Goto bb1 bb1: @@ -54,7 +54,7 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [3] Let mutate y$8_@0[0:10] = Object { } + [3] Const mutate y$8_@0[0:10] = Object { } [4] Reassign mutate x$7_@0.y[0:10] = read y$8_@0 [5] Call mutate mutate$4_@0(mutate y$8_@0) "] @@ -62,7 +62,7 @@ flowchart TB end subgraph bb3 bb3_instrs[" - [7] Let mutate z$9_@1 = Object { } + [7] Const mutate z$9_@1 = Object { } [8] Reassign mutate x$7_@0.z[0:10] = read z$9_@1 "] bb3_instrs --> bb3_terminal(["Goto"]) diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-reassign.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-reassign.expect.md index e5c957e562..e579726fd4 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-reassign.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-reassign.expect.md @@ -16,10 +16,10 @@ function foo(a, b, c) { ``` bb0: - [1] Let mutate x$8_@0 = 0 - [2] Reassign mutate x$9_@1 = read a$5 - [3] Reassign mutate x$10_@2 = read b$6 - [4] Reassign mutate x$11_@3 = read c$7 + [1] Const mutate x$8_@0 = 0 + [2] Const mutate x$9_@1 = read a$5 + [3] Const mutate x$10_@2 = read b$6 + [4] Const mutate x$11_@3 = read c$7 [5] Return read x$11_@3 scope1 [2:3]: - read a$5 @@ -36,10 +36,10 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$8_@0 = 0 - [2] Reassign mutate x$9_@1 = read a$5 - [3] Reassign mutate x$10_@2 = read b$6 - [4] Reassign mutate x$11_@3 = read c$7 + [1] Const mutate x$8_@0 = 0 + [2] Const mutate x$9_@1 = read a$5 + [3] Const mutate x$10_@2 = read b$6 + [4] Const mutate x$11_@3 = read c$7 "] bb0_instrs --> bb0_terminal(["Return read x$11_@3"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md index 33be65cfc8..0d055cbf5d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md @@ -19,18 +19,16 @@ function foo() { bb0: [1] Let mutate x$4_@0[1:7] = 1 [2] Const mutate $5_@1 = 1 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1 - [4] If (read $6_@2) then:bb2 else:bb1 fallthrough=bb1 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1 + [4] If (read $6_@0) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$7_@0[1:7] = 2 + [5] Reassign mutate x$4_@0[1:7] = 2 [6] Goto bb1 bb1: predecessor blocks: bb2 bb0 - x$8_@0[1:7]: phi(bb2: x$7_@0, bb0: x$4_@0) - [7] Return read x$8_@0 -scope2 [3:4]: - - read $5_@1 + [7] Return read x$4_@0 + ``` ### CFG @@ -42,18 +40,18 @@ flowchart TB bb0_instrs[" [1] Let mutate x$4_@0[1:7] = 1 [2] Const mutate $5_@1 = 1 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1 "] - bb0_instrs --> bb0_terminal(["If (read $6_@2)"]) + bb0_instrs --> bb0_terminal(["If (read $6_@0)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$7_@0[1:7] = 2 + [5] Reassign mutate x$4_@0[1:7] = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Return read x$8_@0"]) + bb1_terminal(["Return read x$4_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md index 3e6d8ad457..db3125e60a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md @@ -52,17 +52,16 @@ bb0: [2] If (read cond$5) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [3] Let mutate str$7_@1 = "other test" + [3] Const mutate str$7_@1 = "other test" [4] Call mutate log$4_@2(read str$7_@1) [5] Goto bb1 bb3: predecessor blocks: bb0 - [6] Reassign mutate str$8_@0[1:8] = "fallthrough test" + [6] Reassign mutate str$6_@0[1:8] = "fallthrough test" [7] Goto bb1 bb1: predecessor blocks: bb2 bb3 - str$10_@0[1:8]: phi(bb2: str$6_@0, bb3: str$8_@0) - [8] Call mutate log$4_@2(read str$10_@0) + [8] Call mutate log$4_@2(read str$6_@0) [9] Return ``` @@ -80,20 +79,20 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [3] Let mutate str$7_@1 = 'other test' + [3] Const mutate str$7_@1 = 'other test' [4] Call mutate log$4_@2(read str$7_@1) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Reassign mutate str$8_@0[1:8] = 'fallthrough test' + [6] Reassign mutate str$6_@0[1:8] = 'fallthrough test' "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [8] Call mutate log$4_@2(read str$10_@0) + [8] Call mutate log$4_@2(read str$6_@0) "] bb1_instrs --> bb1_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md index 4b02019526..c3e955e5a2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md @@ -28,52 +28,54 @@ function foo(a, b, c, d) { ``` bb0: - [1] Let mutate x$13_@0 = 0 + [1] Const mutate x$13_@0 = 0 [2] Const mutate $14_@1 = true [3] If (read $14_@1) then:bb2 else:bb6 fallthrough=bb1 bb2: predecessor blocks: bb0 [4] Const mutate $15_@2 = true + [5] Let mutate x$16_@3[5:10] = undefined [5] If (read $15_@2) then:bb4 else:bb5 fallthrough=bb3 bb4: predecessor blocks: bb2 - [6] Reassign mutate x$16_@3[6:9] = read a$9 + [6] Reassign mutate x$16_@3[5:10] = read a$9 [7] Goto bb3 bb5: predecessor blocks: bb2 - [8] Reassign mutate x$17_@3[6:9] = read b$10 + [8] Reassign mutate x$16_@3[5:10] = read b$10 [9] Goto bb3 bb3: predecessor blocks: bb4 bb5 - x$18_@3[6:9]: phi(bb4: x$16_@3, bb5: x$17_@3) - [10] read x$18_@3 + [10] read x$16_@3 [11] Goto bb1 bb6: predecessor blocks: bb0 [12] Const mutate $19_@4 = true + [13] Let mutate x$20_@5[13:18] = undefined [13] If (read $19_@4) then:bb8 else:bb9 fallthrough=bb7 bb8: predecessor blocks: bb6 - [14] Reassign mutate x$20_@5[14:17] = read c$11 + [14] Reassign mutate x$20_@5[13:18] = read c$11 [15] Goto bb7 bb9: predecessor blocks: bb6 - [16] Reassign mutate x$21_@5[14:17] = read d$12 + [16] Reassign mutate x$20_@5[13:18] = read d$12 [17] Goto bb7 bb7: predecessor blocks: bb8 bb9 - x$22_@5[14:17]: phi(bb8: x$20_@5, bb9: x$21_@5) - [18] read x$22_@5 + [18] read x$20_@5 [19] Goto bb1 bb1: predecessor blocks: bb3 bb7 [20] Return -scope3 [6:9]: +scope3 [5:10]: - read a$9 - read b$10 -scope5 [14:17]: + - read $15_@2 +scope5 [13:18]: - read c$11 - read d$12 + - read $19_@4 ``` ### CFG @@ -83,7 +85,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$13_@0 = 0 + [1] Const mutate x$13_@0 = 0 [2] Const mutate $14_@1 = true "] bb0_instrs --> bb0_terminal(["If (read $14_@1)"]) @@ -91,48 +93,50 @@ flowchart TB subgraph bb2 bb2_instrs[" [4] Const mutate $15_@2 = true + [5] Let mutate x$16_@3[5:10] = undefined "] bb2_instrs --> bb2_terminal(["If (read $15_@2)"]) end subgraph bb4 bb4_instrs[" - [6] Reassign mutate x$16_@3[6:9] = read a$9 + [6] Reassign mutate x$16_@3[5:10] = read a$9 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb5 bb5_instrs[" - [8] Reassign mutate x$17_@3[6:9] = read b$10 + [8] Reassign mutate x$16_@3[5:10] = read b$10 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [10] read x$18_@3 + [10] read x$16_@3 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb6 bb6_instrs[" [12] Const mutate $19_@4 = true + [13] Let mutate x$20_@5[13:18] = undefined "] bb6_instrs --> bb6_terminal(["If (read $19_@4)"]) end subgraph bb8 bb8_instrs[" - [14] Reassign mutate x$20_@5[14:17] = read c$11 + [14] Reassign mutate x$20_@5[13:18] = read c$11 "] bb8_instrs --> bb8_terminal(["Goto"]) end subgraph bb9 bb9_instrs[" - [16] Reassign mutate x$21_@5[14:17] = read d$12 + [16] Reassign mutate x$20_@5[13:18] = read d$12 "] bb9_instrs --> bb9_terminal(["Goto"]) end subgraph bb7 bb7_instrs[" - [18] read x$22_@5 + [18] read x$20_@5 "] bb7_instrs --> bb7_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md index 90bdbee104..30d24d7585 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md @@ -20,27 +20,27 @@ function foo() { ``` bb0: - [1] Let mutate y$5_@0 = 2 + [1] Const mutate y$5_@0 = 2 [2] Const mutate $6_@1 = 1 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1 + [4] Let mutate y$8_@3[4:10] = undefined [4] If (read $7_@2) then:bb2 else:bb3 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate y$8_@3[5:10] = 1 + [5] Reassign mutate y$8_@3[4:10] = 1 [6] Goto bb1 bb3: predecessor blocks: bb0 - [7] Reassign mutate y$9_@3[5:10] = 2 + [7] Reassign mutate y$8_@3[4:10] = 2 [8] Goto bb1 bb1: predecessor blocks: bb2 bb3 - y$10_@3[5:10]: phi(bb2: y$8_@3, bb3: y$9_@3) - [9] Let mutate x$11_@3[5:10] = read y$10_@3 + [9] Const mutate x$11_@3[4:10] = read y$8_@3 [10] Return scope2 [3:4]: - read y$5_@0 - read $6_@1 -scope3 [5:10]: +scope3 [4:10]: - read $7_@2 ``` @@ -51,27 +51,28 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate y$5_@0 = 2 + [1] Const mutate y$5_@0 = 2 [2] Const mutate $6_@1 = 1 [3] Const mutate $7_@2 = Binary read y$5_@0 > read $6_@1 + [4] Let mutate y$8_@3[4:10] = undefined "] bb0_instrs --> bb0_terminal(["If (read $7_@2)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate y$8_@3[5:10] = 1 + [5] Reassign mutate y$8_@3[4:10] = 1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [7] Reassign mutate y$9_@3[5:10] = 2 + [7] Reassign mutate y$8_@3[4:10] = 2 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [9] Let mutate x$11_@3[5:10] = read y$10_@3 + [9] Const mutate x$11_@3[4:10] = read y$8_@3 "] bb1_instrs --> bb1_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple.expect.md index cc17b32e36..e935b42ec6 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple.expect.md @@ -13,8 +13,8 @@ function foo() { ``` bb0: - [1] Let mutate x$3_@0 = 1 - [2] Let mutate y$4_@1 = 2 + [1] Const mutate x$3_@0 = 1 + [2] Const mutate y$4_@1 = 2 [3] Return ``` @@ -26,8 +26,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$3_@0 = 1 - [2] Let mutate y$4_@1 = 2 + [1] Const mutate x$3_@0 = 1 + [2] Const mutate y$4_@1 = 2 "] bb0_instrs --> bb0_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md index 8d0a4b4338..9c90603e4c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md @@ -17,12 +17,12 @@ function foo() { ``` bb0: - [1] Let mutate x$4_@0 = 1 - [2] Let mutate y$5_@1 = 2 + [1] Const mutate x$4_@0 = 1 + [2] Const mutate y$5_@1 = 2 [3] If (read y$5_@1) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [4] Let mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1 + [4] Const mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1 [5] Goto bb1 bb1: predecessor blocks: bb2 bb0 @@ -39,14 +39,14 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$4_@0 = 1 - [2] Let mutate y$5_@1 = 2 + [1] Const mutate x$4_@0 = 1 + [2] Const mutate y$5_@1 = 2 "] bb0_instrs --> bb0_terminal(["If (read y$5_@1)"]) end subgraph bb2 bb2_instrs[" - [4] Let mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1 + [4] Const mutate z$6_@2 = Binary read x$4_@0 + read y$5_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md index a358ffe9e7..83660156d9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md @@ -28,11 +28,12 @@ function foo() { ``` bb0: - [1] Let mutate x$10_@0 = 1 + [1] Const mutate x$10_@0 = 1 [2] Const mutate $11_@1 = 2 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1 [4] Const mutate $13_@3 = 1 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3 + [6] Let mutate x$16_@5[6:17] = undefined [6] Switch (read x$10_@0) Case read $14_@4: bb5 Case read $12_@2: bb3 @@ -40,23 +41,22 @@ bb0: Fallthrough: bb1 bb5: predecessor blocks: bb0 - [7] Const mutate $15_@5 = 1 - [8] Reassign mutate x$16_@6[8:17] = Binary read x$10_@0 + read $15_@5 + [7] Const mutate $15_@6 = 1 + [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6 [9] Goto bb1 bb3: predecessor blocks: bb0 [10] Const mutate $17_@7 = 2 - [11] Reassign mutate x$18_@6[8:17] = Binary read x$10_@0 + read $17_@7 + [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7 [12] Goto bb1 bb2: predecessor blocks: bb0 [13] Const mutate $19_@8 = 3 - [14] Reassign mutate x$20_@6[8:17] = Binary read x$10_@0 + read $19_@8 + [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8 [15] Goto bb1 bb1: predecessor blocks: bb5 bb3 bb2 - x$21_@6[8:17]: phi(bb5: x$16_@6, bb3: x$18_@6, bb2: x$20_@6) - [16] Let mutate y$22_@6[8:17] = read x$21_@6 + [16] Const mutate y$22_@5[6:17] = read x$16_@5 [17] Return scope2 [3:4]: - read x$10_@0 @@ -64,12 +64,13 @@ scope2 [3:4]: scope4 [5:6]: - read x$10_@0 - read $13_@3 -scope6 [8:17]: +scope5 [6:17]: - read x$10_@0 +scope8 [13:14]: - read x$10_@0 scope7 [10:11]: - read x$10_@0 -scope5 [7:8]: +scope6 [7:8]: - read x$10_@0 ``` @@ -80,38 +81,39 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$10_@0 = 1 + [1] Const mutate x$10_@0 = 1 [2] Const mutate $11_@1 = 2 [3] Const mutate $12_@2 = Binary read x$10_@0 === read $11_@1 [4] Const mutate $13_@3 = 1 [5] Const mutate $14_@4 = Binary read x$10_@0 === read $13_@3 + [6] Let mutate x$16_@5[6:17] = undefined "] bb0_instrs --> bb0_terminal(["Switch (read x$10_@0)"]) end subgraph bb5 bb5_instrs[" - [7] Const mutate $15_@5 = 1 - [8] Reassign mutate x$16_@6[8:17] = Binary read x$10_@0 + read $15_@5 + [7] Const mutate $15_@6 = 1 + [8] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $15_@6 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" [10] Const mutate $17_@7 = 2 - [11] Reassign mutate x$18_@6[8:17] = Binary read x$10_@0 + read $17_@7 + [11] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $17_@7 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" [13] Const mutate $19_@8 = 3 - [14] Reassign mutate x$20_@6[8:17] = Binary read x$10_@0 + read $19_@8 + [14] Reassign mutate x$16_@5[6:17] = Binary read x$10_@0 + read $19_@8 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [16] Let mutate y$22_@6[8:17] = read x$21_@6 + [16] Const mutate y$22_@5[6:17] = read x$16_@5 "] bb1_instrs --> bb1_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md index 669e36b3a7..cad5be1b3b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md @@ -18,18 +18,16 @@ function foo() { bb0: [1] Let mutate x$4_@0[1:7] = 1 [2] Const mutate $5_@1 = 1 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1 - [4] If (read $6_@2) then:bb2 else:bb1 fallthrough=bb1 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1 + [4] If (read $6_@0) then:bb2 else:bb1 fallthrough=bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$7_@0[1:7] = 2 + [5] Reassign mutate x$4_@0[1:7] = 2 [6] Goto bb1 bb1: predecessor blocks: bb2 bb0 - x$8_@0[1:7]: phi(bb2: x$7_@0, bb0: x$4_@0) - [7] Throw read x$8_@0 -scope2 [3:4]: - - read $5_@1 + [7] Throw read x$4_@0 + ``` ### CFG @@ -41,18 +39,18 @@ flowchart TB bb0_instrs[" [1] Let mutate x$4_@0[1:7] = 1 [2] Const mutate $5_@1 = 1 - [3] Const mutate $6_@2 = Binary read x$4_@0 === read $5_@1 + [3] Const mutate $6_@0[1:7] = Binary read x$4_@0 === read $5_@1 "] - bb0_instrs --> bb0_terminal(["If (read $6_@2)"]) + bb0_instrs --> bb0_terminal(["If (read $6_@0)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$7_@0[1:7] = 2 + [5] Reassign mutate x$4_@0[1:7] = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["Throw read x$8_@0"]) + bb1_terminal(["Throw read x$4_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md index e20b65de8f..e6ef3781b6 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md @@ -17,7 +17,7 @@ function foo() { ``` bb0: - [1] Let mutate x$5_@0 = 1 + [1] Const mutate x$5_@0 = 1 [2] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 @@ -46,7 +46,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$5_@0 = 1 + [1] Const mutate x$5_@0 = 1 "] bb0_instrs --> bb0_terminal(["While"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md index 2789b37964..8fda351553 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md @@ -21,18 +21,17 @@ bb0: [2] While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 - x$7_@0[1:9]: phi(bb0: x$5_@0, bb3: x$10_@0) [3] Const mutate $6_@1 = 10 - [4] Const mutate $8_@0[1:9] = Binary read x$7_@0 < read $6_@1 + [4] Const mutate $8_@0[1:9] = Binary read x$5_@0 < read $6_@1 [5] If (read $8_@0) then:bb3 else:bb2 fallthrough=bb2 bb3: predecessor blocks: bb1 [6] Const mutate $9_@2 = 1 - [7] Reassign mutate x$10_@0[1:9] = Binary read x$7_@0 + read $9_@2 + [7] Reassign mutate x$5_@0[1:9] = Binary read x$5_@0 + read $9_@2 [8] Goto(Continue) bb1 bb2: predecessor blocks: bb1 - [9] Return read x$7_@0 + [9] Return read x$5_@0 ``` @@ -50,19 +49,19 @@ flowchart TB subgraph bb1 bb1_instrs[" [3] Const mutate $6_@1 = 10 - [4] Const mutate $8_@0[1:9] = Binary read x$7_@0 < read $6_@1 + [4] Const mutate $8_@0[1:9] = Binary read x$5_@0 < read $6_@1 "] bb1_instrs --> bb1_terminal(["If (read $8_@0)"]) end subgraph bb3 bb3_instrs[" [6] Const mutate $9_@2 = 1 - [7] Reassign mutate x$10_@0[1:9] = Binary read x$7_@0 + read $9_@2 + [7] Reassign mutate x$5_@0[1:9] = Binary read x$5_@0 + read $9_@2 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["Return read x$7_@0"]) + bb2_terminal(["Return read x$5_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md index fdf868c6cc..bfb1e5bd77 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md @@ -32,7 +32,7 @@ function Component(props) { ``` bb0: - [1] Let mutate x$10_@0[1:12] = Array [] + [1] Const mutate x$10_@0[1:12] = Array [] [2] Let mutate y$11_@0[1:12] = undefined [3] Const mutate $12_@1 = false [4] Const mutate $13_@2 = true @@ -46,18 +46,17 @@ bb0: bb6: predecessor blocks: bb0 [7] Call mutate x$10_@0.push(read props$9.p2) - [8] Reassign mutate y$15_@0[1:12] = Array [] + [8] Reassign mutate y$11_@0[1:12] = Array [] [9] Goto bb1 bb2: predecessor blocks: bb0 - [10] Reassign mutate y$16_@0[1:12] = read x$10_@0 + [10] Reassign mutate y$11_@0[1:12] = read x$10_@0 [11] Goto bb1 bb1: predecessor blocks: bb0 bb6 bb2 - y$20_@0[1:12]: phi(bb0: y$11_@0, bb6: y$15_@0, bb2: y$16_@0) [12] Const mutate child$19_@4 = JSX - [13] Call read y$20_@0.push(read props$9.p4) - [14] Const mutate $22_@5 = JSX {read child$19_@4} + [13] Call read y$11_@0.push(read props$9.p4) + [14] Const mutate $22_@5 = JSX {read child$19_@4} [15] Return read $22_@5 scope0 [1:12]: - read props$9.p2 @@ -65,9 +64,11 @@ scope0 [1:12]: scope4 [12:13]: - read Component$0 - freeze x$10_@0 + - read y$11_@0.push - read props$9.p4 scope5 [14:15]: - read Component$0 + - freeze y$11_@0 - read child$19_@4 ``` @@ -78,7 +79,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$10_@0[1:12] = Array [] + [1] Const mutate x$10_@0[1:12] = Array [] [2] Let mutate y$11_@0[1:12] = undefined [3] Const mutate $12_@1 = false [4] Const mutate $13_@2 = true @@ -89,21 +90,21 @@ flowchart TB subgraph bb6 bb6_instrs[" [7] Call mutate x$10_@0.push(read props$9.p2) - [8] Reassign mutate y$15_@0[1:12] = Array [] + [8] Reassign mutate y$11_@0[1:12] = Array [] "] bb6_instrs --> bb6_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [10] Reassign mutate y$16_@0[1:12] = read x$10_@0 + [10] Reassign mutate y$11_@0[1:12] = read x$10_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" [12] Const mutate child$19_@4 = JSX - [13] Call read y$20_@0.push(read props$9.p4) - [14] Const mutate $22_@5 = JSX {read child$19_@4} + [13] Call read y$11_@0.push(read props$9.p4) + [14] Const mutate $22_@5 = JSX {read child$19_@4} "] bb1_instrs --> bb1_terminal(["Return read $22_@5"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md index 267fbbf5dc..4c1fc55365 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md @@ -36,7 +36,7 @@ function foo(x) { ``` bb0: - [1] Let mutate y$10_@0 = undefined + [1] Const mutate y$10_@0 = undefined [2] Const mutate $11_@1 = 5 [3] Const mutate $12_@2 = 4 [4] Const mutate $13_@3 = 3 @@ -54,27 +54,27 @@ bb0: Fallthrough: bb1 bb10: predecessor blocks: bb0 - [9] Reassign mutate y$17_@7 = 0 + [9] Const mutate y$17_@7 = 0 [10] Goto bb9 bb9: predecessor blocks: bb10 bb0 - [11] Reassign mutate y$18_@8 = 1 + [11] Const mutate y$18_@8 = 1 [12] Goto bb1 bb5: predecessor blocks: bb0 - [13] Reassign mutate y$19_@9 = 3 + [13] Const mutate y$19_@9 = 3 [14] Goto bb1 bb4: predecessor blocks: bb0 - [15] Reassign mutate y$20_@10 = 4 + [15] Const mutate y$20_@10 = 4 [16] Goto bb3 bb3: predecessor blocks: bb4 bb0 - [17] Reassign mutate y$21_@11 = 5 + [17] Const mutate y$21_@11 = 5 [18] Goto bb2 bb2: predecessor blocks: bb3 bb0 - [19] Reassign mutate y$22_@12 = 0 + [19] Const mutate y$22_@12 = 0 [20] Goto bb1 bb1: predecessor blocks: bb9 bb0 bb5 bb2 @@ -89,7 +89,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate y$10_@0 = undefined + [1] Const mutate y$10_@0 = undefined [2] Const mutate $11_@1 = 5 [3] Const mutate $12_@2 = 4 [4] Const mutate $13_@3 = 3 @@ -101,37 +101,37 @@ flowchart TB end subgraph bb10 bb10_instrs[" - [9] Reassign mutate y$17_@7 = 0 + [9] Const mutate y$17_@7 = 0 "] bb10_instrs --> bb10_terminal(["Goto"]) end subgraph bb9 bb9_instrs[" - [11] Reassign mutate y$18_@8 = 1 + [11] Const mutate y$18_@8 = 1 "] bb9_instrs --> bb9_terminal(["Goto"]) end subgraph bb5 bb5_instrs[" - [13] Reassign mutate y$19_@9 = 3 + [13] Const mutate y$19_@9 = 3 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb4 bb4_instrs[" - [15] Reassign mutate y$20_@10 = 4 + [15] Const mutate y$20_@10 = 4 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [17] Reassign mutate y$21_@11 = 5 + [17] Const mutate y$21_@11 = 5 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [19] Reassign mutate y$22_@12 = 0 + [19] Const mutate y$22_@12 = 0 "] bb2_instrs --> bb2_terminal(["Goto"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md index 18676026ea..2cc0afbc80 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md @@ -28,7 +28,7 @@ function Component(props) { ``` bb0: - [1] Let mutate x$9_@0[1:12] = Array [] + [1] Const mutate x$9_@0[1:12] = Array [] [2] Let mutate y$10_@0[1:12] = undefined [3] Const mutate $11_@1 = false [4] Const mutate $12_@2 = true @@ -41,18 +41,17 @@ bb4: predecessor blocks: bb0 [6] Call mutate x$9_@0.push(read props$8.p2) [7] Call mutate x$9_@0.push(read props$8.p3) - [8] Reassign mutate y$13_@3 = Array [] + [8] Const mutate y$13_@3 = Array [] [9] Goto bb2 bb2: predecessor blocks: bb4 bb0 - [10] Reassign mutate y$15_@0[1:12] = read x$9_@0 + [10] Reassign mutate y$10_@0[1:12] = read x$9_@0 [11] Goto bb1 bb1: predecessor blocks: bb2 bb0 - y$20_@0[1:12]: phi(bb2: y$15_@0, bb0: y$10_@0) [12] Const mutate child$19_@4 = JSX - [13] Call read y$20_@0.push(read props$8.p4) - [14] Const mutate $23_@5 = JSX {read child$19_@4} + [13] Call read y$10_@0.push(read props$8.p4) + [14] Const mutate $23_@5 = JSX {read child$19_@4} [15] Return read $23_@5 scope0 [1:12]: - read props$8.p2 @@ -61,9 +60,11 @@ scope0 [1:12]: scope4 [12:13]: - read Component$0 - freeze x$9_@0 + - read y$10_@0.push - read props$8.p4 scope5 [14:15]: - read Component$0 + - read y$10_@0 - read child$19_@4 ``` @@ -74,7 +75,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$9_@0[1:12] = Array [] + [1] Const mutate x$9_@0[1:12] = Array [] [2] Let mutate y$10_@0[1:12] = undefined [3] Const mutate $11_@1 = false [4] Const mutate $12_@2 = true @@ -85,21 +86,21 @@ flowchart TB bb4_instrs[" [6] Call mutate x$9_@0.push(read props$8.p2) [7] Call mutate x$9_@0.push(read props$8.p3) - [8] Reassign mutate y$13_@3 = Array [] + [8] Const mutate y$13_@3 = Array [] "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [10] Reassign mutate y$15_@0[1:12] = read x$9_@0 + [10] Reassign mutate y$10_@0[1:12] = read x$9_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" [12] Const mutate child$19_@4 = JSX - [13] Call read y$20_@0.push(read props$8.p4) - [14] Const mutate $23_@5 = JSX {read child$19_@4} + [13] Call read y$10_@0.push(read props$8.p4) + [14] Const mutate $23_@5 = JSX {read child$19_@4} "] bb1_instrs --> bb1_terminal(["Return read $23_@5"]) end diff --git a/compiler/forget/src/__tests__/hir-test.ts b/compiler/forget/src/__tests__/hir-test.ts index 74f49383ed..cdb8288486 100644 --- a/compiler/forget/src/__tests__/hir-test.ts +++ b/compiler/forget/src/__tests__/hir-test.ts @@ -127,22 +127,7 @@ function transform( traverse(ast, { FunctionDeclaration: { enter(nodePath) { - const { ir } = run(nodePath, { - eliminateRedundantPhi: true, - inferReferenceEffects: true, - inferMutableRanges: true, - inferReactiveScopeVariables: true, - inferReactiveScopes: true, - inferReactiveScopeDependencies: true, - leaveSSA: false, - codegen: false, - }); - - // Print the HIR before leaving SSA. - const textHIR = printFunction(ir); - const visualization = visualizeHIRMermaid(ir); - - const { ast } = run(nodePath, { + const { ir, ast } = run(nodePath, { eliminateRedundantPhi: true, inferReferenceEffects: true, inferMutableRanges: true, @@ -153,6 +138,9 @@ function transform( codegen: true, }); + const textHIR = printFunction(ir); + const visualization = visualizeHIRMermaid(ir); + invariant(ast !== null, "ast is null when codegen option is enabled"); const text = prettier.format(generate(ast).code.replace("\n\n", "\n"), { semi: true,