diff --git a/compiler/forget/src/HIR/DisjointSet.ts b/compiler/forget/src/HIR/DisjointSet.ts index cdcdc2e5a9..9ced0bd61c 100644 --- a/compiler/forget/src/HIR/DisjointSet.ts +++ b/compiler/forget/src/HIR/DisjointSet.ts @@ -22,7 +22,7 @@ export default class DisjointSet { const first = items.shift(); invariant(first != null, "Expected set to be non-empty"); // determine an arbitrary "root" for this set: if the first - // item already has a root use that, otherwise the first item + // item already has a root then use that, otherwise the first item // will be the new root. let root = this.#entries.get(first); if (root == null) { @@ -31,19 +31,19 @@ export default class DisjointSet { } // update remaining items (which may already be part of other sets) for (const item of items) { - let parent = this.#entries.get(item); - if (parent == null) { + let itemParent = this.#entries.get(item); + if (itemParent == null) { // new item, no existing set to update this.#entries.set(item, root); continue; - } else if (parent === root) { + } else if (itemParent === root) { continue; } else { let current = item; - while (parent !== root && parent !== current) { + while (itemParent !== root) { this.#entries.set(current, root); - current = parent; - parent = this.#entries.get(current)!; + current = itemParent; + itemParent = this.#entries.get(current)!; } } } diff --git a/compiler/forget/src/HIR/EnterSSA.ts b/compiler/forget/src/HIR/EnterSSA.ts index ad833bfdfe..a53076a8d2 100644 --- a/compiler/forget/src/HIR/EnterSSA.ts +++ b/compiler/forget/src/HIR/EnterSSA.ts @@ -56,6 +56,7 @@ class SSABuilder { start: 0, end: 0, }, + scope: null, // reset along w the mutable range }; } diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index e5d4add96d..e3b0284ff2 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -277,10 +277,17 @@ export type MutableRange = { * Represents a user-defined variable (has a name) or a temporary variable (no name). */ export type Identifier = { - preSsaId: IdentifierId | null; // the original `id` value prior to entering SSA form - id: IdentifierId; // unique value to distinguish a variable, since name is not guaranteed to exist or be unique - name: string | null; // null for temporaries. name is primarily used for debugging. + // the original `id` value prior to entering SSA form + preSsaId: IdentifierId | null; + // unique value to distinguish a variable, since name is not guaranteed to exist or be unique + id: IdentifierId; + // null for temporaries. name is primarily used for debugging. + name: string | null; + // The range for which this variable is mutable mutableRange: MutableRange; + // The ID of the reactive scope which will compute this value. Multiple variables may have + // the same scope id. + scope: ScopeId | null; }; /** diff --git a/compiler/forget/src/HIR/HIRBuilder.ts b/compiler/forget/src/HIR/HIRBuilder.ts index 54b8db3513..f42bf43fb2 100644 --- a/compiler/forget/src/HIR/HIRBuilder.ts +++ b/compiler/forget/src/HIR/HIRBuilder.ts @@ -113,6 +113,7 @@ export default class HIRBuilder { id, name: null, mutableRange: { start: 0, end: 0 }, + scope: null, }; } @@ -125,6 +126,7 @@ export default class HIRBuilder { id, name: node.name, mutableRange: { start: 0, end: 0 }, + scope: null, }; this.#bindings.set(node, identifier); } diff --git a/compiler/forget/src/HIR/InferReactiveScopeVariables.ts b/compiler/forget/src/HIR/InferReactiveScopeVariables.ts new file mode 100644 index 0000000000..f1aaaa42e2 --- /dev/null +++ b/compiler/forget/src/HIR/InferReactiveScopeVariables.ts @@ -0,0 +1,125 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import DisjointSet from "./DisjointSet"; +import { + HIRFunction, + Identifier, + Instruction, + makeScopeId, + Place, + ScopeId, +} from "./HIR"; +import { eachInstructionOperand } from "./visitors"; + +/** + * For each mutable variable, infers a reactive scope which will construct that + * variable. Variables that co-mutate are assigned to the same reactive scope. + * This pass does *not* infer the set of instructions necessary to compute each + * variable/scope, only the set of variables that will be computed by each scope. + * + * Examples: + * ```javascript + * // Mutable arguments + * let x = {}; + * let y = []; + * foo(x, y); // both args mutable, could alias each other + * y.push(x); // y is part of callee, counts as operand + * + * let z = {}; + * y.push(z); + * + * // Mutable assignment + * let x = {}; + * let y = []; + * x.y = y; // trivial aliasing + * ``` + * + * More generally, all mutable operands (incl lvalue) of an instruction must go in the + * same scope. + * + * ## Implementation + * + * 1. Iterate over all instructions in all blocks (order does not matter, single pass), + * and create disjoint sets ({@link DisjointSet}) for each set of operands that + * mutate together per above rules. + * 2. Iterate the contents of each set, and assign a new {@link ScopeId} to each set, + * and update the `scope` property of each item in that set to that scope id. + * + * ## Other Issues Uncovered + * + * 1. Mutable lifetimes need to account for aliasing. + * + * ```javascript + * let x = {}; + * let y = []; + * x.y = y; // RHS is not considered mutable here bc not further mutation + * mutate(x); // bc y is aliased here, it should still be considered mutable above + * ``` + * + * 2. Mutable lifetimes need to account for SSA reassignment. + * + * ```javascript + * // y is never considered mutable bc SSA treats subsequent assignments as distinct identifiers + * let y; + * if (cond) { + * y = ...; + * } else { + * y = ...; + * } + * ``` + */ +export function inferReactiveScopeVariables(fn: HIRFunction) { + // Represents the set of reactive scopes as disjoint sets of identifiers + // that mutate together. + const scopes = new DisjointSet(); + for (const [_, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const operands: Array = []; + if (instr.lvalue !== null) { + // invariant( + // isMutable(instr, instr.lvalue!.place), + // "Assignment always means the value is mutable:\n" + + // printMixedHIR(instr) + // ); + operands.push(instr.lvalue!.place.identifier); + } + for (const operand of eachInstructionOperand(instr)) { + if (isMutable(instr, operand)) { + operands.push(operand.identifier); + } + } + if (operands.length !== 0) { + scopes.union(operands); + } + } + } + + // Maps each scope (by its identifying member) to a ScopeId value + const scopeIds: Map = new Map(); + + // Iterate over all the identifiers in all scopes, and assign each + // identifier to its group's scope id. The first identifier in each + // group assigns the scope id for that group. + scopes.forEach((identifier, groupIdentifier) => { + let scopeId = scopeIds.get(groupIdentifier); + if (scopeId == null) { + scopeId = makeScopeId(scopeIds.size); + scopeIds.set(groupIdentifier, scopeId); + } + identifier.scope = scopeId; + }); +} + +// Is the operand mutable at this given instruction +function isMutable(instr: Instruction, place: Place): boolean { + return ( + // TODO: should start really be exclusive? + instr.id > place.identifier.mutableRange.start && + instr.id <= place.identifier.mutableRange.end + ); +} diff --git a/compiler/forget/src/HIR/PrintHIR.ts b/compiler/forget/src/HIR/PrintHIR.ts index 3856a36beb..2d5202058f 100644 --- a/compiler/forget/src/HIR/PrintHIR.ts +++ b/compiler/forget/src/HIR/PrintHIR.ts @@ -296,7 +296,9 @@ export function printPlace(place: Place): string { } export function printIdentifier(id: Identifier): string { - return `${id.name ?? ""}\$${id.id}`; + return `${id.name ?? ""}\$${id.id}${ + id.scope !== null ? `_@${id.scope}` : "" + }`; } export function printSourceLocation(loc: SourceLocation): string { 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 a3cd091631..9999c7c34e 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$1 = 1 - [2] Const mutate $2 = 1 - [3] Reassign mutate x$1 = Binary read x$1 + read $2 - [4] Const mutate $3 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $3 - [6] Const mutate $4 = 1 - [7] Reassign mutate x$1 = Binary read x$1 >>> read $4 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Reassign mutate x$1_@2 = Binary read x$1_@0 + read $2_@1 + [4] Const mutate $3_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1_@2 + read $3_@3 + [6] Const mutate $4_@5 = 1 + [7] Reassign mutate x$1_@6 = Binary read x$1_@4 >>> read $4_@5 Return ``` @@ -37,13 +37,13 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Const mutate $2 = 1 - [3] Reassign mutate x$1 = Binary read x$1 + read $2 - [4] Const mutate $3 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $3 - [6] Const mutate $4 = 1 - [7] Reassign mutate x$1 = Binary read x$1 >>> read $4 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Reassign mutate x$1_@2 = Binary read x$1_@0 + read $2_@1 + [4] Const mutate $3_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1_@2 + read $3_@3 + [6] Const mutate $4_@5 = 1 + [7] Reassign mutate x$1_@6 = Binary read x$1_@4 >>> read $4_@5 "] bb0_instrs --> bb0_terminal(["Return"]) end @@ -68,10 +68,10 @@ function f$0() { ``` bb0: - [1] Const mutate $2 = 1 - [2] Reassign mutate a$1.b.c[0:4] = Binary read a$1.b.c + read $2 - [3] Const mutate $3 = 2 - [4] Reassign mutate a$1.b.c[0:4] = Binary read a$1.b.c * read $3 + [1] Const mutate $2_@0 = 1 + [2] Reassign mutate a$1_@1.b.c[0:4] = Binary read a$1_@1.b.c + read $2_@0 + [3] Const mutate $3_@2 = 2 + [4] Reassign mutate a$1_@1.b.c[0:4] = Binary read a$1_@1.b.c * read $3_@2 Return ``` @@ -82,10 +82,10 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate $2 = 1 - [2] Reassign mutate a$1.b.c[0:4] = Binary read a$1.b.c + read $2 - [3] Const mutate $3 = 2 - [4] Reassign mutate a$1.b.c[0:4] = Binary read a$1.b.c * read $3 + [1] Const mutate $2_@0 = 1 + [2] Reassign mutate a$1_@1.b.c[0:4] = Binary read a$1_@1.b.c + read $2_@0 + [3] Const mutate $3_@2 = 2 + [4] Reassign mutate a$1_@1.b.c[0:4] = Binary read a$1_@1.b.c * read $3_@2 "] 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 3515a0e12c..56a9835c54 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md @@ -47,15 +47,15 @@ function foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = "div" - [5] Let mutate _$5 = JSX - [6] Call mutate foo$4(mutate b$3) - [7] Const mutate $7 = "div" - [8] Const mutate $8 = JSX - Return read $8 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = "div" + [5] Let mutate _$5_@2 = JSX + [6] Call mutate foo$4_@0(mutate b$3_@0) + [7] Const mutate $7_@3 = "div" + [8] Const mutate $8_@4 = JSX + Return read $8_@4 ``` ### CFG @@ -65,16 +65,16 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = 'div' - [5] Let mutate _$5 = JSX - [6] Call mutate foo$4(mutate b$3) - [7] Const mutate $7 = 'div' - [8] Const mutate $8 = JSX + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = 'div' + [5] Let mutate _$5_@2 = JSX + [6] Call mutate foo$4_@0(mutate b$3_@0) + [7] Const mutate $7_@3 = 'div' + [8] Const mutate $8_@4 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $8"]) + bb0_instrs --> bb0_terminal(["Return read $8_@4"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md index add0f27edf..fcf0d8a791 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md @@ -35,28 +35,28 @@ function Component(props) { ``` bb0: - [1] Const mutate items$2 = read props$1.items - [2] Const mutate maxItems$3 = read props$1.maxItems - [3] Const mutate renderedItems$4[3:14] = Array [] - [4] Const mutate seen$5[4:11] = New mutate Set$6() - [5] Const mutate $9 = 0 - [6] Const mutate max$7 = Call mutate Math$8.max(read $9, read maxItems$3) + [1] Const mutate items$2_@0 = read props$1.items + [2] Const mutate maxItems$3_@1 = read props$1.maxItems + [3] Const mutate renderedItems$4_@2[3:14] = Array [] + [4] Const mutate seen$5_@3[4:11] = New mutate Set$6_@3() + [5] Const mutate $9_@4 = 0 + [6] Const mutate max$7_@5 = Call mutate Math$8_@5.max(read $9_@4, read maxItems$3_@1) Goto bb1 bb1: predecessor blocks: bb0 bb5 bb10 - If (read items$2) then:bb3 else:bb2 + If (read items$2_@0) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [7] Const mutate $11 = null - [8] Const mutate $12 = Binary read item$10 == read $11 - If (read $12) then:bb8 else:bb9 + [7] Const mutate $11_@6 = null + [8] Const mutate $12_@3 = Binary read item$10_@3 == read $11_@6 + If (read $12_@3) then:bb8 else:bb9 bb8: predecessor blocks: bb3 - [9] Const mutate $13 = read $12 + [9] Const mutate $13_@7 = read $12_@3 Goto bb7 bb9: predecessor blocks: bb3 - [10] Const mutate $13 = Call mutate seen$5.has(mutate item$10) + [10] Const mutate $13_@3 = Call mutate seen$5_@3.has(mutate item$10_@3) Goto bb7 bb7: predecessor blocks: bb8 bb9 @@ -66,27 +66,27 @@ bb5: Goto(Continue) bb1 bb4: predecessor blocks: bb7 - [11] Call mutate seen$5.add(mutate item$10) - [12] Const mutate $14 = "div" - [13] Const mutate $15 = JSX {read item$10} - [14] Call mutate renderedItems$4.push(read $15) - [15] Const mutate $16 = Binary read renderedItems$4.length >= read max$7 - If (read $16) then:bb2 else:bb10 + [11] Call mutate seen$5_@3.add(mutate item$10_@3) + [12] Const mutate $14_@8 = "div" + [13] Const mutate $15_@9 = JSX {read item$10_@3} + [14] Call mutate renderedItems$4_@2.push(read $15_@9) + [15] Const mutate $16_@10 = Binary read renderedItems$4_@2.length >= read max$7_@5 + If (read $16_@10) then:bb2 else:bb10 bb10: predecessor blocks: bb4 Goto(Continue) bb1 bb2: predecessor blocks: bb4 bb1 - [16] Const mutate count$17 = read renderedItems$4.length - [17] Const mutate $18 = "div" - [18] Const mutate $19 = "\n " - [19] Const mutate $20 = "h1" - [20] Const mutate $21 = " Items" - [21] Const mutate $22 = JSX {freeze count$17}{read $21} - [22] Const mutate $23 = "\n " - [23] Const mutate $24 = "\n " - [24] Const mutate $25 = JSX {read $19}{read $22}{read $23}{freeze renderedItems$4}{read $24} - Return read $25 + [16] Const mutate count$17_@11 = read renderedItems$4_@2.length + [17] Const mutate $18_@12 = "div" + [18] Const mutate $19_@13 = "\n " + [19] Const mutate $20_@14 = "h1" + [20] Const mutate $21_@15 = " Items" + [21] Const mutate $22_@16 = JSX {freeze count$17_@11}{read $21_@15} + [22] Const mutate $23_@17 = "\n " + [23] Const mutate $24_@18 = "\n " + [24] Const mutate $25_@19 = JSX {read $19_@13}{read $22_@16}{read $23_@17}{freeze renderedItems$4_@2}{read $24_@18} + Return read $25_@19 ``` ### CFG @@ -96,34 +96,34 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate items$2 = read props$1.items - [2] Const mutate maxItems$3 = read props$1.maxItems - [3] Const mutate renderedItems$4[3:14] = Array [] - [4] Const mutate seen$5[4:11] = New mutate Set$6() - [5] Const mutate $9 = 0 - [6] Const mutate max$7 = Call mutate Math$8.max(read $9, read maxItems$3) + [1] Const mutate items$2_@0 = read props$1.items + [2] Const mutate maxItems$3_@1 = read props$1.maxItems + [3] Const mutate renderedItems$4_@2[3:14] = Array [] + [4] Const mutate seen$5_@3[4:11] = New mutate Set$6_@3() + [5] Const mutate $9_@4 = 0 + [6] Const mutate max$7_@5 = Call mutate Math$8_@5.max(read $9_@4, read maxItems$3_@1) "] bb0_instrs --> bb0_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["If (read items$2)"]) + bb1_terminal(["If (read items$2_@0)"]) end subgraph bb3 bb3_instrs[" - [7] Const mutate $11 = null - [8] Const mutate $12 = Binary read item$10 == read $11 + [7] Const mutate $11_@6 = null + [8] Const mutate $12_@3 = Binary read item$10_@3 == read $11_@6 "] - bb3_instrs --> bb3_terminal(["If (read $12)"]) + bb3_instrs --> bb3_terminal(["If (read $12_@3)"]) end subgraph bb8 bb8_instrs[" - [9] Const mutate $13 = read $12 + [9] Const mutate $13_@7 = read $12_@3 "] bb8_instrs --> bb8_terminal(["Goto"]) end subgraph bb9 bb9_instrs[" - [10] Const mutate $13 = Call mutate seen$5.has(mutate item$10) + [10] Const mutate $13_@3 = Call mutate seen$5_@3.has(mutate item$10_@3) "] bb9_instrs --> bb9_terminal(["Goto"]) end @@ -135,30 +135,30 @@ flowchart TB end subgraph bb4 bb4_instrs[" - [11] Call mutate seen$5.add(mutate item$10) - [12] Const mutate $14 = 'div' - [13] Const mutate $15 = JSX {read item$10} - [14] Call mutate renderedItems$4.push(read $15) - [15] Const mutate $16 = Binary read renderedItems$4.length >= read max$7 + [11] Call mutate seen$5_@3.add(mutate item$10_@3) + [12] Const mutate $14_@8 = 'div' + [13] Const mutate $15_@9 = JSX {read item$10_@3} + [14] Call mutate renderedItems$4_@2.push(read $15_@9) + [15] Const mutate $16_@10 = Binary read renderedItems$4_@2.length >= read max$7_@5 "] - bb4_instrs --> bb4_terminal(["If (read $16)"]) + bb4_instrs --> bb4_terminal(["If (read $16_@10)"]) end subgraph bb10 bb10_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [16] Const mutate count$17 = read renderedItems$4.length - [17] Const mutate $18 = 'div' - [18] Const mutate $19 = '\n ' - [19] Const mutate $20 = 'h1' - [20] Const mutate $21 = ' Items' - [21] Const mutate $22 = JSX {freeze count$17}{read $21} - [22] Const mutate $23 = '\n ' - [23] Const mutate $24 = '\n ' - [24] Const mutate $25 = JSX {read $19}{read $22}{read $23}{freeze renderedItems$4}{read $24} + [16] Const mutate count$17_@11 = read renderedItems$4_@2.length + [17] Const mutate $18_@12 = 'div' + [18] Const mutate $19_@13 = '\n ' + [19] Const mutate $20_@14 = 'h1' + [20] Const mutate $21_@15 = ' Items' + [21] Const mutate $22_@16 = JSX {freeze count$17_@11}{read $21_@15} + [22] Const mutate $23_@17 = '\n ' + [23] Const mutate $24_@18 = '\n ' + [24] Const mutate $25_@19 = JSX {read $19_@13}{read $22_@16}{read $23_@17}{freeze renderedItems$4_@2}{read $24_@18} "] - bb2_instrs --> bb2_terminal(["Return read $25"]) + bb2_instrs --> bb2_terminal(["Return read $25_@19"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md index f40fb37ea3..88cd552d11 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md @@ -78,17 +78,17 @@ function Component(props) { ``` bb0: - [1] Const mutate a_DEBUG$2[1:4] = Array [] - [2] Call mutate a_DEBUG$2.push(read props$1.a) + [1] Const mutate a_DEBUG$2_@0[1:4] = Array [] + [2] Call mutate a_DEBUG$2_@0.push(read props$1.a) If (read props$1.b) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Const mutate $3 = null - Return read $3 + [3] Const mutate $3_@1 = null + Return read $3_@1 bb1: predecessor blocks: bb0 - [4] Call mutate a_DEBUG$2.push(read props$1.d) - Return freeze a_DEBUG$2 + [4] Call mutate a_DEBUG$2_@0.push(read props$1.d) + Return freeze a_DEBUG$2_@0 ``` ### CFG @@ -98,22 +98,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a_DEBUG$2[1:4] = Array [] - [2] Call mutate a_DEBUG$2.push(read props$1.a) + [1] Const mutate a_DEBUG$2_@0[1:4] = Array [] + [2] Call mutate a_DEBUG$2_@0.push(read props$1.a) "] bb0_instrs --> bb0_terminal(["If (read props$1.b)"]) end subgraph bb2 bb2_instrs[" - [3] Const mutate $3 = null + [3] Const mutate $3_@1 = null "] - bb2_instrs --> bb2_terminal(["Return read $3"]) + bb2_instrs --> bb2_terminal(["Return read $3_@1"]) end subgraph bb1 bb1_instrs[" - [4] Call mutate a_DEBUG$2.push(read props$1.d) + [4] Call mutate a_DEBUG$2_@0.push(read props$1.d) "] - bb1_instrs --> bb1_terminal(["Return freeze a_DEBUG$2"]) + bb1_instrs --> bb1_terminal(["Return freeze a_DEBUG$2_@0"]) end %% Jumps @@ -141,17 +141,17 @@ function Component$0(props$1) { ``` bb0: - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) If (read props$1.b) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate a$2.push(read props$1.c) + [3] Call mutate a$2_@0.push(read props$1.c) Goto bb1 bb1: predecessor blocks: bb2 bb0 - [4] Call mutate a$2.push(read props$1.d) - Return freeze a$2 + [4] Call mutate a$2_@0.push(read props$1.d) + Return freeze a$2_@0 ``` ### CFG @@ -161,22 +161,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) "] bb0_instrs --> bb0_terminal(["If (read props$1.b)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate a$2.push(read props$1.c) + [3] Call mutate a$2_@0.push(read props$1.c) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [4] Call mutate a$2.push(read props$1.d) + [4] Call mutate a$2_@0.push(read props$1.d) "] - bb1_instrs --> bb1_terminal(["Return freeze a$2"]) + bb1_instrs --> bb1_terminal(["Return freeze a$2_@0"]) end %% Jumps @@ -205,18 +205,18 @@ function Component$0(props$1) { ``` bb0: - [1] Const mutate a$2[1:5] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:5] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) If (read props$1.b) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate a$2.push(read props$1.c) - [4] Const mutate $3 = null - Return read $3 + [3] Call mutate a$2_@0.push(read props$1.c) + [4] Const mutate $3_@1 = null + Return read $3_@1 bb1: predecessor blocks: bb0 - [5] Call mutate a$2.push(read props$1.d) - Return freeze a$2 + [5] Call mutate a$2_@0.push(read props$1.d) + Return freeze a$2_@0 ``` ### CFG @@ -226,23 +226,23 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:5] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:5] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) "] bb0_instrs --> bb0_terminal(["If (read props$1.b)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate a$2.push(read props$1.c) - [4] Const mutate $3 = null + [3] Call mutate a$2_@0.push(read props$1.c) + [4] Const mutate $3_@1 = null "] - bb2_instrs --> bb2_terminal(["Return read $3"]) + bb2_instrs --> bb2_terminal(["Return read $3_@1"]) end subgraph bb1 bb1_instrs[" - [5] Call mutate a$2.push(read props$1.d) + [5] Call mutate a$2_@0.push(read props$1.d) "] - bb1_instrs --> bb1_terminal(["Return freeze a$2"]) + bb1_instrs --> bb1_terminal(["Return freeze a$2_@0"]) end %% Jumps @@ -271,17 +271,17 @@ function Component$0(props$1) { ``` bb0: - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) If (read props$1.b) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate a$2.push(read props$1.c) - Return freeze a$2 + [3] Call mutate a$2_@0.push(read props$1.c) + Return freeze a$2_@0 bb1: predecessor blocks: bb0 - [4] Call mutate a$2.push(read props$1.d) - Return freeze a$2 + [4] Call mutate a$2_@0.push(read props$1.d) + Return freeze a$2_@0 ``` ### CFG @@ -291,22 +291,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) "] bb0_instrs --> bb0_terminal(["If (read props$1.b)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate a$2.push(read props$1.c) + [3] Call mutate a$2_@0.push(read props$1.c) "] - bb2_instrs --> bb2_terminal(["Return freeze a$2"]) + bb2_instrs --> bb2_terminal(["Return freeze a$2_@0"]) end subgraph bb1 bb1_instrs[" - [4] Call mutate a$2.push(read props$1.d) + [4] Call mutate a$2_@0.push(read props$1.d) "] - bb1_instrs --> bb1_terminal(["Return freeze a$2"]) + bb1_instrs --> bb1_terminal(["Return freeze a$2_@0"]) end %% Jumps @@ -335,17 +335,17 @@ function Component$0(props$1) { ``` bb0: - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) If (read props$1.b) then:bb1 else:bb2 bb2: predecessor blocks: bb0 - [3] Call mutate a$2.push(read props$1.c) + [3] Call mutate a$2_@0.push(read props$1.c) Goto bb1 bb1: predecessor blocks: bb0 bb2 - [4] Call mutate a$2.push(read props$1.d) - Return freeze a$2 + [4] Call mutate a$2_@0.push(read props$1.d) + Return freeze a$2_@0 ``` ### CFG @@ -355,22 +355,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:4] = Array [] - [2] Call mutate a$2.push(read props$1.a) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Call mutate a$2_@0.push(read props$1.a) "] bb0_instrs --> bb0_terminal(["If (read props$1.b)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate a$2.push(read props$1.c) + [3] Call mutate a$2_@0.push(read props$1.c) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [4] Call mutate a$2.push(read props$1.d) + [4] Call mutate a$2_@0.push(read props$1.d) "] - bb1_instrs --> bb1_terminal(["Return freeze a$2"]) + bb1_instrs --> bb1_terminal(["Return freeze a$2_@0"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md b/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md index 230b86c216..ca992ca580 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md @@ -67,24 +67,24 @@ function mayMutate() {} ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:4] = Array [] - If (read b$3) then:bb2 else:bb1 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@1[2:4] = Array [] + If (read b$3_@1) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate a$2.push(read props$1.p0) + [3] Call mutate a$2_@0.push(read props$1.p0) Goto bb1 bb1: predecessor blocks: bb2 bb0 If (read props$1.p1) then:bb4 else:bb3 bb4: predecessor blocks: bb1 - [4] Call mutate b$3.push(read props$1.p2) + [4] Call mutate b$3_@1.push(read props$1.p2) Goto bb3 bb3: predecessor blocks: bb4 bb1 - [5] Const mutate $5 = JSX - Return read $5 + [5] Const mutate $5_@2 = JSX + Return read $5_@2 ``` ### CFG @@ -94,14 +94,14 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:4] = Array [] + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@1[2:4] = Array [] "] - bb0_instrs --> bb0_terminal(["If (read b$3)"]) + bb0_instrs --> bb0_terminal(["If (read b$3_@1)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate a$2.push(read props$1.p0) + [3] Call mutate a$2_@0.push(read props$1.p0) "] bb2_instrs --> bb2_terminal(["Goto"]) end @@ -110,15 +110,15 @@ flowchart TB end subgraph bb4 bb4_instrs[" - [4] Call mutate b$3.push(read props$1.p2) + [4] Call mutate b$3_@1.push(read props$1.p2) "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Const mutate $5 = JSX + [5] Const mutate $5_@2 = JSX "] - bb3_instrs --> bb3_terminal(["Return read $5"]) + bb3_instrs --> bb3_terminal(["Return read $5_@2"]) end %% Jumps @@ -153,25 +153,25 @@ function Component$0(props$1) { ``` bb0: - [1] Const mutate a$2[1:4] = Array [] - [2] Const mutate b$3[2:5] = Array [] - [3] Const mutate $5 = Call mutate mayMutate$4(mutate b$3) - If (read $5) then:bb2 else:bb1 + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Const mutate b$3_@1[2:5] = Array [] + [3] Const mutate $5_@1 = Call mutate mayMutate$4_@1(mutate b$3_@1) + If (read $5_@1) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [4] Call mutate a$2.push(read props$1.p0) + [4] Call mutate a$2_@0.push(read props$1.p0) Goto bb1 bb1: predecessor blocks: bb2 bb0 If (read props$1.p1) then:bb4 else:bb3 bb4: predecessor blocks: bb1 - [5] Call mutate b$3.push(read props$1.p2) + [5] Call mutate b$3_@1.push(read props$1.p2) Goto bb3 bb3: predecessor blocks: bb4 bb1 - [6] Const mutate $7 = JSX - Return read $7 + [6] Const mutate $7_@2 = JSX + Return read $7_@2 ``` ### CFG @@ -181,15 +181,15 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:4] = Array [] - [2] Const mutate b$3[2:5] = Array [] - [3] Const mutate $5 = Call mutate mayMutate$4(mutate b$3) + [1] Const mutate a$2_@0[1:4] = Array [] + [2] Const mutate b$3_@1[2:5] = Array [] + [3] Const mutate $5_@1 = Call mutate mayMutate$4_@1(mutate b$3_@1) "] - bb0_instrs --> bb0_terminal(["If (read $5)"]) + bb0_instrs --> bb0_terminal(["If (read $5_@1)"]) end subgraph bb2 bb2_instrs[" - [4] Call mutate a$2.push(read props$1.p0) + [4] Call mutate a$2_@0.push(read props$1.p0) "] bb2_instrs --> bb2_terminal(["Goto"]) end @@ -198,15 +198,15 @@ flowchart TB end subgraph bb4 bb4_instrs[" - [5] Call mutate b$3.push(read props$1.p2) + [5] Call mutate b$3_@1.push(read props$1.p2) "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Const mutate $7 = JSX + [6] Const mutate $7_@2 = JSX "] - bb3_instrs --> bb3_terminal(["Return read $7"]) + bb3_instrs --> bb3_terminal(["Return read $7_@2"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md index fe70ee0766..4911b0ee41 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md @@ -47,15 +47,15 @@ function Foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] New mutate Foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = "div" - [5] Let mutate _$5 = JSX - [6] New mutate Foo$4(mutate b$3) - [7] Const mutate $7 = "div" - [8] Const mutate $8 = JSX - Return read $8 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] New mutate Foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = "div" + [5] Let mutate _$5_@2 = JSX + [6] New mutate Foo$4_@0(mutate b$3_@0) + [7] Const mutate $7_@3 = "div" + [8] Const mutate $8_@4 = JSX + Return read $8_@4 ``` ### CFG @@ -65,16 +65,16 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] New mutate Foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = 'div' - [5] Let mutate _$5 = JSX - [6] New mutate Foo$4(mutate b$3) - [7] Const mutate $7 = 'div' - [8] Const mutate $8 = JSX + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] New mutate Foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = 'div' + [5] Let mutate _$5_@2 = JSX + [6] New mutate Foo$4_@0(mutate b$3_@0) + [7] Const mutate $7_@3 = 'div' + [8] Const mutate $8_@4 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $8"]) + bb0_instrs --> bb0_terminal(["Return read $8_@4"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md index 44e5111643..b00c8c706b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md @@ -18,10 +18,10 @@ function foo(x) {} ``` bb0: - [1] Const mutate a$1 = Array [] - [2] Const mutate b$2 = read a$1 - [3] Call read useFreeze$3(freeze a$1) - [4] Call mutate foo$4(read b$2) + [1] Const mutate a$1_@0 = Array [] + [2] Const mutate b$2_@1 = read a$1_@0 + [3] Call read useFreeze$3(freeze a$1_@0) + [4] Call mutate foo$4_@2(read b$2_@1) Return ``` @@ -32,10 +32,10 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$1 = Array [] - [2] Const mutate b$2 = read a$1 - [3] Call read useFreeze$3(freeze a$1) - [4] Call mutate foo$4(read b$2) + [1] Const mutate a$1_@0 = Array [] + [2] Const mutate b$2_@1 = read a$1_@0 + [3] Call read useFreeze$3(freeze a$1_@0) + [4] Call mutate foo$4_@2(read b$2_@1) "] bb0_instrs --> bb0_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md index e8c5324747..dc414ede46 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md @@ -79,14 +79,14 @@ function foo$0() { ``` bb0: - [1] Const mutate x$2 = Array [] - [2] Const mutate y$3 = Call read useFreeze$4(freeze x$2) - [3] Call mutate foo$5(read y$3, read x$2) - [4] Const mutate $6 = "\n " - [5] Const mutate $7 = "\n " - [6] Const mutate $8 = "\n " - [7] Const mutate $9 = JSX {read $6}{read x$2}{read $7}{read y$3}{read $8} - Return read $9 + [1] Const mutate x$2_@0 = Array [] + [2] Const mutate y$3_@1 = Call read useFreeze$4(freeze x$2_@0) + [3] Call mutate foo$5_@2(read y$3_@1, read x$2_@0) + [4] Const mutate $6_@3 = "\n " + [5] Const mutate $7_@4 = "\n " + [6] Const mutate $8_@5 = "\n " + [7] Const mutate $9_@6 = JSX {read $6_@3}{read x$2_@0}{read $7_@4}{read y$3_@1}{read $8_@5} + Return read $9_@6 ``` ### CFG @@ -96,15 +96,15 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate x$2 = Array [] - [2] Const mutate y$3 = Call read useFreeze$4(freeze x$2) - [3] Call mutate foo$5(read y$3, read x$2) - [4] Const mutate $6 = '\n ' - [5] Const mutate $7 = '\n ' - [6] Const mutate $8 = '\n ' - [7] Const mutate $9 = JSX {read $6}{read x$2}{read $7}{read y$3}{read $8} + [1] Const mutate x$2_@0 = Array [] + [2] Const mutate y$3_@1 = Call read useFreeze$4(freeze x$2_@0) + [3] Call mutate foo$5_@2(read y$3_@1, read x$2_@0) + [4] Const mutate $6_@3 = '\n ' + [5] Const mutate $7_@4 = '\n ' + [6] Const mutate $8_@5 = '\n ' + [7] Const mutate $9_@6 = JSX {read $6_@3}{read x$2_@0}{read $7_@4}{read y$3_@1}{read $8_@5} "] - bb0_instrs --> bb0_terminal(["Return read $9"]) + bb0_instrs --> bb0_terminal(["Return read $9_@6"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md index 21d3344028..1b8f615dcf 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md @@ -19,11 +19,11 @@ function call(x) {} ``` bb0: - [1] Const mutate a$1 = Array [] - [2] Call read useFreeze$2(freeze a$1) - [3] Call read useFreeze$2(read a$1) - [4] Call mutate call$3(read a$1) - Return read a$1 + [1] Const mutate a$1_@0 = Array [] + [2] Call read useFreeze$2(freeze a$1_@0) + [3] Call read useFreeze$2(read a$1_@0) + [4] Call mutate call$3_@1(read a$1_@0) + Return read a$1_@0 ``` ### CFG @@ -33,12 +33,12 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$1 = Array [] - [2] Call read useFreeze$2(freeze a$1) - [3] Call read useFreeze$2(read a$1) - [4] Call mutate call$3(read a$1) + [1] Const mutate a$1_@0 = Array [] + [2] Call read useFreeze$2(freeze a$1_@0) + [3] Call read useFreeze$2(read a$1_@0) + [4] Call mutate call$3_@1(read a$1_@0) "] - bb0_instrs --> bb0_terminal(["Return read a$1"]) + bb0_instrs --> bb0_terminal(["Return read a$1_@0"]) end %% Jumps 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 2b8b3dda3c..5f92a7f196 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 @@ -26,23 +26,23 @@ function call(x) {} ``` bb0: - [1] Const mutate cond$2 = read props$1.cond - [2] Const mutate x$3 = read props$1.x - [3] Let mutate a$4 = undefined - If (read cond$2) then:bb2 else:bb3 + [1] Const mutate cond$2_@0 = read props$1.cond + [2] Const mutate x$3_@1 = read props$1.x + [3] Let mutate a$4_@2 = undefined + If (read cond$2_@0) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [4] Reassign mutate a$4 = read x$3 + [4] Reassign mutate a$4_@3 = read x$3_@1 Goto bb1 bb3: predecessor blocks: bb0 - [5] Reassign mutate a$4 = Array [] + [5] Reassign mutate a$4_@4 = Array [] Goto bb1 bb1: predecessor blocks: bb2 bb3 [6] Call read useFreeze$5(freeze a$4) [7] Call read useFreeze$5(read a$4) - [8] Call mutate call$6(read a$4) + [8] Call mutate call$6_@5(read a$4) Return read a$4 ``` @@ -53,21 +53,21 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate cond$2 = read props$1.cond - [2] Const mutate x$3 = read props$1.x - [3] Let mutate a$4 = undefined + [1] Const mutate cond$2_@0 = read props$1.cond + [2] Const mutate x$3_@1 = read props$1.x + [3] Let mutate a$4_@2 = undefined "] - bb0_instrs --> bb0_terminal(["If (read cond$2)"]) + bb0_instrs --> bb0_terminal(["If (read cond$2_@0)"]) end subgraph bb2 bb2_instrs[" - [4] Reassign mutate a$4 = read x$3 + [4] Reassign mutate a$4_@3 = read x$3_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Reassign mutate a$4 = Array [] + [5] Reassign mutate a$4_@4 = Array [] "] bb3_instrs --> bb3_terminal(["Goto"]) end @@ -75,7 +75,7 @@ flowchart TB bb1_instrs[" [6] Call read useFreeze$5(freeze a$4) [7] Call read useFreeze$5(read a$4) - [8] Call mutate call$6(read a$4) + [8] Call mutate call$6_@5(read a$4) "] bb1_instrs --> bb1_terminal(["Return read a$4"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md index e02591b869..e2185eda83 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md @@ -149,18 +149,18 @@ function Foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:4] = Call mutate compute$3(read props$1.b) + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:4] = Call mutate compute$3_@0(read props$1.b) If (read props$1.c) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate mutate$5(mutate a$2) - [4] Call mutate mutate$5(mutate b$4) + [3] Call mutate mutate$5_@0(mutate a$2_@0) + [4] Call mutate mutate$5_@0(mutate b$4_@0) Goto bb1 bb1: predecessor blocks: bb2 bb0 - [5] Const mutate $7 = JSX - Return read $7 + [5] Const mutate $7_@1 = JSX + Return read $7_@1 ``` ### CFG @@ -170,23 +170,23 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:4] = Call mutate compute$3(read props$1.b) + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:4] = Call mutate compute$3_@0(read props$1.b) "] bb0_instrs --> bb0_terminal(["If (read props$1.c)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate mutate$5(mutate a$2) - [4] Call mutate mutate$5(mutate b$4) + [3] Call mutate mutate$5_@0(mutate a$2_@0) + [4] Call mutate mutate$5_@0(mutate b$4_@0) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [5] Const mutate $7 = JSX + [5] Const mutate $7_@1 = JSX "] - bb1_instrs --> bb1_terminal(["Return read $7"]) + bb1_instrs --> bb1_terminal(["Return read $7_@1"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md b/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md index 1caf8e9acb..f8be029c6d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md @@ -28,10 +28,10 @@ function Foo() {} ``` bb0: - [1] Const mutate a$2 = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4 = Call mutate compute$3(read props$1.b) - [3] Const mutate $6 = JSX - Return read $6 + [1] Const mutate a$2_@0 = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0 = Call mutate compute$3_@0(read props$1.b) + [3] Const mutate $6_@1 = JSX + Return read $6_@1 ``` ### CFG @@ -41,11 +41,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2 = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4 = Call mutate compute$3(read props$1.b) - [3] Const mutate $6 = JSX + [1] Const mutate a$2_@0 = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0 = Call mutate compute$3_@0(read props$1.b) + [3] Const mutate $6_@1 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $6"]) + bb0_instrs --> bb0_terminal(["Return read $6_@1"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md index f2b401f4bf..77555ebcba 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md @@ -115,17 +115,17 @@ function Foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:3] = Call mutate compute$3(read props$1.b) + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:3] = Call mutate compute$3_@0(read props$1.b) If (read props$1.c) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Call mutate foo$5(mutate a$2, mutate b$4) + [3] Call mutate foo$5_@0(mutate a$2_@0, mutate b$4_@0) Goto bb1 bb1: predecessor blocks: bb2 bb0 - [4] Const mutate $7 = JSX - Return read $7 + [4] Const mutate $7_@1 = JSX + Return read $7_@1 ``` ### CFG @@ -135,22 +135,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:3] = Call mutate compute$3(read props$1.b) + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:3] = Call mutate compute$3_@0(read props$1.b) "] bb0_instrs --> bb0_terminal(["If (read props$1.c)"]) end subgraph bb2 bb2_instrs[" - [3] Call mutate foo$5(mutate a$2, mutate b$4) + [3] Call mutate foo$5_@0(mutate a$2_@0, mutate b$4_@0) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [4] Const mutate $7 = JSX + [4] Const mutate $7_@1 = JSX "] - bb1_instrs --> bb1_terminal(["Return read $7"]) + bb1_instrs --> bb1_terminal(["Return read $7_@1"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md b/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md index 55b2e9637c..317a224450 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md @@ -28,11 +28,11 @@ function Foo() {} ``` bb0: - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:3] = Call mutate compute$3(read props$1.b) - [3] Call mutate foo$5(mutate a$2, mutate b$4) - [4] Const mutate $7 = JSX - Return read $7 + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:3] = Call mutate compute$3_@0(read props$1.b) + [3] Call mutate foo$5_@0(mutate a$2_@0, mutate b$4_@0) + [4] Const mutate $7_@1 = JSX + Return read $7_@1 ``` ### CFG @@ -42,12 +42,12 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Call mutate compute$3(read props$1.a) - [2] Const mutate b$4[2:3] = Call mutate compute$3(read props$1.b) - [3] Call mutate foo$5(mutate a$2, mutate b$4) - [4] Const mutate $7 = JSX + [1] Const mutate a$2_@0[1:3] = Call mutate compute$3_@0(read props$1.a) + [2] Const mutate b$4_@0[2:3] = Call mutate compute$3_@0(read props$1.b) + [3] Call mutate foo$5_@0(mutate a$2_@0, mutate b$4_@0) + [4] Const mutate $7_@1 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $7"]) + bb0_instrs --> bb0_terminal(["Return read $7_@1"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md index a118b840b7..e13d450eb3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md @@ -19,18 +19,18 @@ function Foo(props) { ``` bb0: - [1] Const mutate $2 = "\n Hello " - [2] Const mutate $3 = " " - [3] Const mutate $4 = "\n " - [4] Const mutate $5 = "div" - [5] Const mutate $6 = "\n " - [6] Const mutate $7 = "Text" - [7] Const mutate $8 = JsxFragment [read $7] - [8] Const mutate $9 = "\n " - [9] Const mutate $10 = JSX {read $6}{read $8}{read $9} - [10] Const mutate $11 = "\n " - [11] Const mutate $12 = JsxFragment [read $2, read props$1.greeting, read $3, read $4, read $10, read $11] - Return read $12 + [1] Const mutate $2_@0 = "\n Hello " + [2] Const mutate $3_@1 = " " + [3] Const mutate $4_@2 = "\n " + [4] Const mutate $5_@3 = "div" + [5] Const mutate $6_@4 = "\n " + [6] Const mutate $7_@5 = "Text" + [7] Const mutate $8_@6 = JsxFragment [read $7_@5] + [8] Const mutate $9_@7 = "\n " + [9] Const mutate $10_@8 = JSX {read $6_@4}{read $8_@6}{read $9_@7} + [10] Const mutate $11_@9 = "\n " + [11] Const mutate $12_@10 = JsxFragment [read $2_@0, read props$1.greeting, read $3_@1, read $4_@2, read $10_@8, read $11_@9] + Return read $12_@10 ``` ### CFG @@ -40,19 +40,19 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate $2 = '\n Hello ' - [2] Const mutate $3 = ' ' - [3] Const mutate $4 = '\n ' - [4] Const mutate $5 = 'div' - [5] Const mutate $6 = '\n ' - [6] Const mutate $7 = 'Text' - [7] Const mutate $8 = JsxFragment [read $7] - [8] Const mutate $9 = '\n ' - [9] Const mutate $10 = JSX {read $6}{read $8}{read $9} - [10] Const mutate $11 = '\n ' - [11] Const mutate $12 = JsxFragment [read $2, read props$1.greeting, read $3, read $4, read $10, read $11] + [1] Const mutate $2_@0 = '\n Hello ' + [2] Const mutate $3_@1 = ' ' + [3] Const mutate $4_@2 = '\n ' + [4] Const mutate $5_@3 = 'div' + [5] Const mutate $6_@4 = '\n ' + [6] Const mutate $7_@5 = 'Text' + [7] Const mutate $8_@6 = JsxFragment [read $7_@5] + [8] Const mutate $9_@7 = '\n ' + [9] Const mutate $10_@8 = JSX {read $6_@4}{read $8_@6}{read $9_@7} + [10] Const mutate $11_@9 = '\n ' + [11] Const mutate $12_@10 = JsxFragment [read $2_@0, read props$1.greeting, read $3_@1, read $4_@2, read $10_@8, read $11_@9] "] - bb0_instrs --> bb0_terminal(["Return read $12"]) + bb0_instrs --> bb0_terminal(["Return read $12_@10"]) end %% Jumps 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 add25da288..f1e37de67a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md @@ -23,15 +23,15 @@ function g() {} ``` bb0: - [1] Const mutate $2 = Call mutate f$1() - If (read $2) then:bb2 else:bb3 + [1] Const mutate $2_@0 = Call mutate f$1_@0() + If (read $2_@0) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [2] Const mutate $3 = Call mutate g$4() + [2] Const mutate $3_@1 = Call mutate g$4_@1() Goto bb1 bb3: predecessor blocks: bb0 - [3] Const mutate $3 = read $2 + [3] Const mutate $3_@2 = read $2_@0 Goto bb1 bb1: predecessor blocks: bb2 bb3 @@ -45,19 +45,19 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate $2 = Call mutate f$1() + [1] Const mutate $2_@0 = Call mutate f$1_@0() "] - bb0_instrs --> bb0_terminal(["If (read $2)"]) + bb0_instrs --> bb0_terminal(["If (read $2_@0)"]) end subgraph bb2 bb2_instrs[" - [2] Const mutate $3 = Call mutate g$4() + [2] Const mutate $3_@1 = Call mutate g$4_@1() "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [3] Const mutate $3 = read $2 + [3] Const mutate $3_@2 = read $2_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) end @@ -89,15 +89,15 @@ function And$0() { ``` bb0: - [1] Const mutate $2 = Call mutate f$1() - If (read $2) then:bb2 else:bb3 + [1] Const mutate $2_@0 = Call mutate f$1_@0() + If (read $2_@0) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [2] Const mutate $3 = read $2 + [2] Const mutate $3_@1 = read $2_@0 Goto bb1 bb3: predecessor blocks: bb0 - [3] Const mutate $3 = Call mutate g$4() + [3] Const mutate $3_@2 = Call mutate g$4_@2() Goto bb1 bb1: predecessor blocks: bb2 bb3 @@ -111,19 +111,19 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate $2 = Call mutate f$1() + [1] Const mutate $2_@0 = Call mutate f$1_@0() "] - bb0_instrs --> bb0_terminal(["If (read $2)"]) + bb0_instrs --> bb0_terminal(["If (read $2_@0)"]) end subgraph bb2 bb2_instrs[" - [2] Const mutate $3 = read $2 + [2] Const mutate $3_@1 = read $2_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [3] Const mutate $3 = Call mutate g$4() + [3] Const mutate $3_@2 = Call mutate g$4_@2() "] bb3_instrs --> bb3_terminal(["Goto"]) end @@ -155,17 +155,17 @@ function Or$0() { ``` bb0: - [1] Const mutate $3 = Call mutate f$2() - [2] Const mutate $4 = null - [3] Const mutate $5 = Binary read $3 != read $4 - If (read $5) then:bb2 else:bb3 + [1] Const mutate $3_@0 = Call mutate f$2_@0() + [2] Const mutate $4_@1 = null + [3] Const mutate $5_@2 = Binary read $3_@0 != read $4_@1 + If (read $5_@2) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [4] Const mutate $6 = read $3 + [4] Const mutate $6_@3 = read $3_@0 Goto bb1 bb3: predecessor blocks: bb0 - [5] Const mutate $6 = Call mutate g$7() + [5] Const mutate $6_@4 = Call mutate g$7_@4() Goto bb1 bb1: predecessor blocks: bb2 bb3 @@ -179,21 +179,21 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate $3 = Call mutate f$2() - [2] Const mutate $4 = null - [3] Const mutate $5 = Binary read $3 != read $4 + [1] Const mutate $3_@0 = Call mutate f$2_@0() + [2] Const mutate $4_@1 = null + [3] Const mutate $5_@2 = Binary read $3_@0 != read $4_@1 "] - bb0_instrs --> bb0_terminal(["If (read $5)"]) + bb0_instrs --> bb0_terminal(["If (read $5_@2)"]) end subgraph bb2 bb2_instrs[" - [4] Const mutate $6 = read $3 + [4] Const mutate $6_@3 = read $3_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Const mutate $6 = Call mutate g$7() + [5] Const mutate $6_@4 = Call mutate g$7_@4() "] bb3_instrs --> bb3_terminal(["Goto"]) end 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 9e22080770..a8d6b557a1 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 @@ -99,25 +99,25 @@ function cond$0(x$1) { ``` bb0: - [1] Let mutate a$2 = Object { } - [2] Let mutate b$3 = Object { } - [3] Let mutate c$4 = Object { } - [4] Let mutate d$5 = Object { } + [1] Let mutate a$2_@0 = Object { } + [2] Let mutate b$3_@1 = Object { } + [3] Let mutate c$4_@2 = Object { } + [4] Let mutate d$5_@3 = Object { } While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb4 - [5] Const mutate $10 = true - If (read $10) then:bb3 else:bb2 + [5] Const mutate $10_@4 = true + If (read $10_@4) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [6] Let mutate z$6 = read a$2 - [7] Reassign mutate a$2[7:12] = read b$3 - [8] Reassign mutate b$3[8:11] = read c$4 - [9] Reassign mutate c$4 = read d$5 - [10] Reassign mutate d$5 = read z$6 - [11] Call mutate mutate$7(mutate a$2, mutate b$3) - [12] Const mutate $9 = Call mutate cond$8(mutate a$2) - If (read $9) then:bb2 else:bb4 + [6] Let mutate z$6_@5 = read a$2 + [7] Reassign mutate a$2_@6[7:12] = read b$3 + [8] Reassign mutate b$3_@6[8:11] = read c$4 + [9] Reassign mutate c$4_@7 = read d$5 + [10] Reassign mutate d$5_@8 = read z$6_@5 + [11] Call mutate mutate$7_@6(mutate a$2_@6, mutate b$3_@6) + [12] Const mutate $9_@6 = Call mutate cond$8_@6(mutate a$2_@6) + If (read $9_@6) then:bb2 else:bb4 bb4: predecessor blocks: bb3 Goto(Continue) bb1 @@ -132,11 +132,11 @@ bb9: If (read c$4) then:bb11 else:bb11 bb11: predecessor blocks: bb9 - If (read d$5) then:bb13 else:bb13 + If (read d$5_@6) then:bb13 else:bb13 bb13: predecessor blocks: bb11 - [13] Const mutate $11 = null - [14] Call mutate mutate$7(mutate d$5, read $11) + [13] Const mutate $11_@9 = null + [14] Call mutate mutate$7_@6(mutate d$5_@6, read $11_@9) Return ``` @@ -147,30 +147,30 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate a$2 = Object { } - [2] Let mutate b$3 = Object { } - [3] Let mutate c$4 = Object { } - [4] Let mutate d$5 = Object { } + [1] Let mutate a$2_@0 = Object { } + [2] Let mutate b$3_@1 = Object { } + [3] Let mutate c$4_@2 = Object { } + [4] Let mutate d$5_@3 = Object { } "] bb0_instrs --> bb0_terminal(["While"]) end subgraph bb1 bb1_instrs[" - [5] Const mutate $10 = true + [5] Const mutate $10_@4 = true "] - bb1_instrs --> bb1_terminal(["If (read $10)"]) + bb1_instrs --> bb1_terminal(["If (read $10_@4)"]) end subgraph bb3 bb3_instrs[" - [6] Let mutate z$6 = read a$2 - [7] Reassign mutate a$2[7:12] = read b$3 - [8] Reassign mutate b$3[8:11] = read c$4 - [9] Reassign mutate c$4 = read d$5 - [10] Reassign mutate d$5 = read z$6 - [11] Call mutate mutate$7(mutate a$2, mutate b$3) - [12] Const mutate $9 = Call mutate cond$8(mutate a$2) + [6] Let mutate z$6_@5 = read a$2 + [7] Reassign mutate a$2_@6[7:12] = read b$3 + [8] Reassign mutate b$3_@6[8:11] = read c$4 + [9] Reassign mutate c$4_@7 = read d$5 + [10] Reassign mutate d$5_@8 = read z$6_@5 + [11] Call mutate mutate$7_@6(mutate a$2_@6, mutate b$3_@6) + [12] Const mutate $9_@6 = Call mutate cond$8_@6(mutate a$2_@6) "] - bb3_instrs --> bb3_terminal(["If (read $9)"]) + bb3_instrs --> bb3_terminal(["If (read $9_@6)"]) end subgraph bb4 bb4_terminal(["Goto"]) @@ -185,12 +185,12 @@ flowchart TB bb9_terminal(["If (read c$4)"]) end subgraph bb11 - bb11_terminal(["If (read d$5)"]) + bb11_terminal(["If (read d$5_@6)"]) end subgraph bb13 bb13_instrs[" - [13] Const mutate $11 = null - [14] Call mutate mutate$7(mutate d$5, read $11) + [13] Const mutate $11_@9 = null + [14] Call mutate mutate$7_@6(mutate d$5_@6, read $11_@9) "] bb13_instrs --> bb13_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md index 02328235f2..17edc95bcb 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md @@ -67,30 +67,30 @@ function mutate$0(x$1, y$2) { ``` bb0: - [1] Const mutate a$2 = Object { } - [2] Const mutate b$3 = Array [read a$2] - [3] Const mutate c$4 = Object { } - [4] Const mutate d$5[4:7] = Object { c: read c$4 } - [5] Const mutate x$6[5:9] = Object { } - [6] Reassign mutate x$6.b[5:9] = read b$3 - [7] Const mutate y$7 = Call mutate mutate$8(mutate x$6, mutate d$5) - If (read a$2) then:bb1 else:bb1 + [1] Const mutate a$2_@0 = Object { } + [2] Const mutate b$3_@1 = Array [read a$2_@0] + [3] Const mutate c$4_@2 = Object { } + [4] Const mutate d$5_@3[4:7] = Object { c: read c$4_@2 } + [5] Const mutate x$6_@3[5:9] = Object { } + [6] Reassign mutate x$6_@3.b[5:9] = read b$3_@1 + [7] Const mutate y$7_@3 = Call mutate mutate$8_@3(mutate x$6_@3, mutate d$5_@3) + If (read a$2_@0) then:bb1 else:bb1 bb1: predecessor blocks: bb0 - If (read b$3) then:bb3 else:bb3 + If (read b$3_@1) then:bb3 else:bb3 bb3: predecessor blocks: bb1 - If (read c$4) then:bb5 else:bb5 + If (read c$4_@2) then:bb5 else:bb5 bb5: predecessor blocks: bb3 - If (read d$5) then:bb7 else:bb7 + If (read d$5_@3) then:bb7 else:bb7 bb7: predecessor blocks: bb5 - If (read y$7) then:bb9 else:bb9 + If (read y$7_@3) then:bb9 else:bb9 bb9: predecessor blocks: bb7 - [8] Const mutate $9 = null - [9] Call mutate mutate$8(mutate x$6, read $9) + [8] Const mutate $9_@4 = null + [9] Call mutate mutate$8_@3(mutate x$6_@3, read $9_@4) Return ``` @@ -101,32 +101,32 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2 = Object { } - [2] Const mutate b$3 = Array [read a$2] - [3] Const mutate c$4 = Object { } - [4] Const mutate d$5[4:7] = Object { c: read c$4 } - [5] Const mutate x$6[5:9] = Object { } - [6] Reassign mutate x$6.b[5:9] = read b$3 - [7] Const mutate y$7 = Call mutate mutate$8(mutate x$6, mutate d$5) + [1] Const mutate a$2_@0 = Object { } + [2] Const mutate b$3_@1 = Array [read a$2_@0] + [3] Const mutate c$4_@2 = Object { } + [4] Const mutate d$5_@3[4:7] = Object { c: read c$4_@2 } + [5] Const mutate x$6_@3[5:9] = Object { } + [6] Reassign mutate x$6_@3.b[5:9] = read b$3_@1 + [7] Const mutate y$7_@3 = Call mutate mutate$8_@3(mutate x$6_@3, mutate d$5_@3) "] - bb0_instrs --> bb0_terminal(["If (read a$2)"]) + bb0_instrs --> bb0_terminal(["If (read a$2_@0)"]) end subgraph bb1 - bb1_terminal(["If (read b$3)"]) + bb1_terminal(["If (read b$3_@1)"]) end subgraph bb3 - bb3_terminal(["If (read c$4)"]) + bb3_terminal(["If (read c$4_@2)"]) end subgraph bb5 - bb5_terminal(["If (read d$5)"]) + bb5_terminal(["If (read d$5_@3)"]) end subgraph bb7 - bb7_terminal(["If (read y$7)"]) + bb7_terminal(["If (read y$7_@3)"]) end subgraph bb9 bb9_instrs[" - [8] Const mutate $9 = null - [9] Call mutate mutate$8(mutate x$6, read $9) + [8] Const mutate $9_@4 = null + [9] Call mutate mutate$8_@3(mutate x$6_@3, read $9_@4) "] bb9_instrs --> bb9_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 0a478d5240..f44edb3295 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 @@ -94,39 +94,39 @@ function cond$0() { ``` bb0: - [1] Let mutate a$2[1:7] = Object { } - [2] Let mutate b$3[2:6] = Object { } - [3] Let mutate c$4 = Object { } - [4] Let mutate d$5[4:9] = Object { } + [1] Let mutate a$2_@0[1:7] = Object { } + [2] Let mutate b$3_@0[2:6] = Object { } + [3] Let mutate c$4_@1 = Object { } + [4] Let mutate d$5_@0[4:9] = Object { } While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb4 - [5] Const mutate $9 = true - If (read $9) then:bb3 else:bb2 + [5] Const mutate $9_@2 = true + If (read $9_@2) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [6] Call mutate mutate$6(mutate a$2, mutate b$3) - [7] Const mutate $8 = Call mutate cond$7(mutate a$2) - If (read $8) then:bb2 else:bb4 + [6] Call mutate mutate$6_@0(mutate a$2_@0, mutate b$3_@0) + [7] Const mutate $8_@0 = Call mutate cond$7_@0(mutate a$2_@0) + If (read $8_@0) then:bb2 else:bb4 bb4: predecessor blocks: bb3 Goto(Continue) bb1 bb2: predecessor blocks: bb3 bb1 - If (read a$2) then:bb7 else:bb7 + If (read a$2_@0) then:bb7 else:bb7 bb7: predecessor blocks: bb2 - If (read b$3) then:bb9 else:bb9 + If (read b$3_@0) then:bb9 else:bb9 bb9: predecessor blocks: bb7 - If (read c$4) then:bb11 else:bb11 + If (read c$4_@1) then:bb11 else:bb11 bb11: predecessor blocks: bb9 - If (read d$5) then:bb13 else:bb13 + If (read d$5_@0) then:bb13 else:bb13 bb13: predecessor blocks: bb11 - [8] Const mutate $10 = null - [9] Call mutate mutate$6(mutate d$5, read $10) + [8] Const mutate $10_@3 = null + [9] Call mutate mutate$6_@0(mutate d$5_@0, read $10_@3) Return ``` @@ -137,45 +137,45 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate a$2[1:7] = Object { } - [2] Let mutate b$3[2:6] = Object { } - [3] Let mutate c$4 = Object { } - [4] Let mutate d$5[4:9] = Object { } + [1] Let mutate a$2_@0[1:7] = Object { } + [2] Let mutate b$3_@0[2:6] = Object { } + [3] Let mutate c$4_@1 = Object { } + [4] Let mutate d$5_@0[4:9] = Object { } "] bb0_instrs --> bb0_terminal(["While"]) end subgraph bb1 bb1_instrs[" - [5] Const mutate $9 = true + [5] Const mutate $9_@2 = true "] - bb1_instrs --> bb1_terminal(["If (read $9)"]) + bb1_instrs --> bb1_terminal(["If (read $9_@2)"]) end subgraph bb3 bb3_instrs[" - [6] Call mutate mutate$6(mutate a$2, mutate b$3) - [7] Const mutate $8 = Call mutate cond$7(mutate a$2) + [6] Call mutate mutate$6_@0(mutate a$2_@0, mutate b$3_@0) + [7] Const mutate $8_@0 = Call mutate cond$7_@0(mutate a$2_@0) "] - bb3_instrs --> bb3_terminal(["If (read $8)"]) + bb3_instrs --> bb3_terminal(["If (read $8_@0)"]) end subgraph bb4 bb4_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["If (read a$2)"]) + bb2_terminal(["If (read a$2_@0)"]) end subgraph bb7 - bb7_terminal(["If (read b$3)"]) + bb7_terminal(["If (read b$3_@0)"]) end subgraph bb9 - bb9_terminal(["If (read c$4)"]) + bb9_terminal(["If (read c$4_@1)"]) end subgraph bb11 - bb11_terminal(["If (read d$5)"]) + bb11_terminal(["If (read d$5_@0)"]) end subgraph bb13 bb13_instrs[" - [8] Const mutate $10 = null - [9] Call mutate mutate$6(mutate d$5, read $10) + [8] Const mutate $10_@3 = null + [9] Call mutate mutate$6_@0(mutate d$5_@0, read $10_@3) "] bb13_instrs --> bb13_terminal(["Return"]) end diff --git a/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md index 46d7b70553..d6e71bc48e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md @@ -17,13 +17,13 @@ function Component(props) { ``` bb0: - [1] Const mutate x$2[1:5] = Object { } - [2] Const mutate y$3 = Array [] - [3] Reassign mutate x$2.y[1:5] = read y$3 - [4] Const mutate child$4 = JSX - [5] Call mutate x$2.y.push(read props$1.p0) - [6] Const mutate $5 = JSX {read child$4} - Return read $5 + [1] Const mutate x$2_@0[1:5] = Object { } + [2] Const mutate y$3_@1 = Array [] + [3] Reassign mutate x$2_@0.y[1:5] = read y$3_@1 + [4] Const mutate child$4_@2 = JSX + [5] Call mutate x$2_@0.y.push(read props$1.p0) + [6] Const mutate $5_@3 = JSX {read child$4_@2} + Return read $5_@3 ``` ### CFG @@ -33,14 +33,14 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate x$2[1:5] = Object { } - [2] Const mutate y$3 = Array [] - [3] Reassign mutate x$2.y[1:5] = read y$3 - [4] Const mutate child$4 = JSX - [5] Call mutate x$2.y.push(read props$1.p0) - [6] Const mutate $5 = JSX {read child$4} + [1] Const mutate x$2_@0[1:5] = Object { } + [2] Const mutate y$3_@1 = Array [] + [3] Reassign mutate x$2_@0.y[1:5] = read y$3_@1 + [4] Const mutate child$4_@2 = JSX + [5] Call mutate x$2_@0.y.push(read props$1.p0) + [6] Const mutate $5_@3 = JSX {read child$4_@2} "] - bb0_instrs --> bb0_terminal(["Return read $5"]) + bb0_instrs --> bb0_terminal(["Return read $5_@3"]) end %% Jumps 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 new file mode 100644 index 0000000000..7864105d7b --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md @@ -0,0 +1,62 @@ + +## Input + +```javascript +function foo() { + let x = {}; + let y = []; + let z = {}; + y.push(z); + x.y = y; + + return x; +} + +``` + +## HIR + +``` +bb0: + [1] Let mutate x$1_@0[1:5] = Object { } + [2] Let mutate y$2_@1[2:4] = Array [] + [3] Let mutate z$3_@1[3:4] = Object { } + [4] Call mutate y$2_@1.push(mutate z$3_@1) + [5] Reassign mutate x$1_@0.y[1:5] = read y$2_@1 + Return freeze x$1_@0 +``` + +### CFG + +```mermaid +flowchart TB + %% Basic Blocks + subgraph bb0 + bb0_instrs[" + [1] Let mutate x$1_@0[1:5] = Object { } + [2] Let mutate y$2_@1[2:4] = Array [] + [3] Let mutate z$3_@1[3:4] = Object { } + [4] Call mutate y$2_@1.push(mutate z$3_@1) + [5] Reassign mutate x$1_@0.y[1:5] = read y$2_@1 + "] + bb0_instrs --> bb0_terminal(["Return freeze x$1_@0"]) + end + + %% Jumps + %% empty +``` + +## Code + +```javascript +function foo$0() { + let x$1 = {}; + let y$2 = []; + let z$3 = {}; + y$2.push(z$3); + x$1.y = y$2; + return x$1; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.js b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.js new file mode 100644 index 0000000000..c87c5f26ff --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.js @@ -0,0 +1,9 @@ +function foo() { + let x = {}; + let y = []; + let z = {}; + y.push(z); + x.y = y; + + return x; +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md new file mode 100644 index 0000000000..00d4ca0a29 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md @@ -0,0 +1,94 @@ + +## Input + +```javascript +function f(a, b) { + let x = []; // <- x starts being mutable here. + if (a.length === 1) { + if (b) { + x.push(b); // <- x stops being mutable here. + } + } + + return
{x}
; +} + +``` + +## HIR + +``` +bb0: + [1] Let mutate x$3_@0[1:4] = Array [] + [2] Const mutate $4_@1 = 1 + [3] Const mutate $5_@2 = Binary read a$1.length === read $4_@1 + If (read $5_@2) then:bb2 else:bb1 +bb2: + predecessor blocks: bb0 + If (read b$2) then:bb4 else:bb1 +bb4: + predecessor blocks: bb2 + [4] Call mutate x$3_@0.push(read b$2) + Goto bb1 +bb1: + predecessor blocks: bb4 bb2 bb0 + [5] Const mutate $6_@3 = "div" + [6] Const mutate $7_@4 = JSX {freeze x$3_@0} + Return read $7_@4 +``` + +### CFG + +```mermaid +flowchart TB + %% Basic Blocks + subgraph bb0 + bb0_instrs[" + [1] Let mutate x$3_@0[1:4] = Array [] + [2] Const mutate $4_@1 = 1 + [3] Const mutate $5_@2 = Binary read a$1.length === read $4_@1 + "] + bb0_instrs --> bb0_terminal(["If (read $5_@2)"]) + end + subgraph bb2 + bb2_terminal(["If (read b$2)"]) + end + subgraph bb4 + bb4_instrs[" + [4] Call mutate x$3_@0.push(read b$2) + "] + bb4_instrs --> bb4_terminal(["Goto"]) + end + subgraph bb1 + bb1_instrs[" + [5] Const mutate $6_@3 = 'div' + [6] Const mutate $7_@4 = JSX {freeze x$3_@0} + "] + bb1_instrs --> bb1_terminal(["Return read $7_@4"]) + end + + %% Jumps + bb0_terminal -- then --> bb2 + bb0_terminal -- else --> bb1 + bb2_terminal -- then --> bb4 + bb2_terminal -- else --> bb1 + bb4_terminal --> bb1 + +``` + +## Code + +```javascript +function f$0(a$1, b$2) { + let x$3 = []; + bb1: if (a$1.length === 1) { + if (b$2) { + x$3.push(b$2); + } + } + + return
{x$3}
; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.js b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.js new file mode 100644 index 0000000000..951732f898 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.js @@ -0,0 +1,10 @@ +function f(a, b) { + let x = []; // <- x starts being mutable here. + if (a.length === 1) { + if (b) { + x.push(b); // <- x stops being mutable here. + } + } + + return
{x}
; +} 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 03f7fdc23b..d58654d306 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md @@ -23,20 +23,20 @@ function Component(props) { ``` bb0: - [1] Let mutate x$2[1:2] = Array [] - [2] Call mutate x$2.push(read props$1.p0) - [3] Let mutate y$3 = read x$2 + [1] Let mutate x$2_@0[1:2] = Array [] + [2] Call mutate x$2_@0.push(read props$1.p0) + [3] Let mutate y$3_@1 = read x$2_@0 If (read props$1.p1) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [4] Reassign mutate x$2 = Array [] + [4] Reassign mutate x$2_@2 = Array [] Goto bb1 bb1: predecessor blocks: bb2 bb0 - [5] Let mutate _$4 = JSX - [6] Call read y$3.push(read props$1.p2) - [7] Const mutate $5 = JSX - Return read $5 + [5] Let mutate _$4_@3 = JSX + [6] Call read y$3_@1.push(read props$1.p2) + [7] Const mutate $5_@4 = JSX + Return read $5_@4 ``` ### CFG @@ -46,25 +46,25 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$2[1:2] = Array [] - [2] Call mutate x$2.push(read props$1.p0) - [3] Let mutate y$3 = read x$2 + [1] Let mutate x$2_@0[1:2] = Array [] + [2] Call mutate x$2_@0.push(read props$1.p0) + [3] Let mutate y$3_@1 = read x$2_@0 "] bb0_instrs --> bb0_terminal(["If (read props$1.p1)"]) end subgraph bb2 bb2_instrs[" - [4] Reassign mutate x$2 = Array [] + [4] Reassign mutate x$2_@2 = Array [] "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [5] Let mutate _$4 = JSX - [6] Call read y$3.push(read props$1.p2) - [7] Const mutate $5 = JSX + [5] Let mutate _$4_@3 = JSX + [6] Call read y$3_@1.push(read props$1.p2) + [7] Const mutate $5_@4 = JSX "] - bb1_instrs --> bb1_terminal(["Return read $5"]) + bb1_instrs --> bb1_terminal(["Return read $5_@4"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md index fa737cb3ae..abcea79bc7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md @@ -21,14 +21,14 @@ function Component(props) { ``` bb0: - [1] Let mutate x$2[1:2] = Array [] - [2] Call mutate x$2.push(read props$1.p0) - [3] Let mutate y$3[3:6] = read x$2 - [4] Reassign mutate x$2 = Array [] - [5] Let mutate _$4 = JSX - [6] Call mutate y$3.push(read props$1.p1) - [7] Const mutate $5 = JSX - Return read $5 + [1] Let mutate x$2_@0[1:2] = Array [] + [2] Call mutate x$2_@0.push(read props$1.p0) + [3] Let mutate y$3_@1[3:6] = read x$2_@0 + [4] Reassign mutate x$2_@2 = Array [] + [5] Let mutate _$4_@3 = JSX + [6] Call mutate y$3_@1.push(read props$1.p1) + [7] Const mutate $5_@4 = JSX + Return read $5_@4 ``` ### CFG @@ -38,15 +38,15 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$2[1:2] = Array [] - [2] Call mutate x$2.push(read props$1.p0) - [3] Let mutate y$3[3:6] = read x$2 - [4] Reassign mutate x$2 = Array [] - [5] Let mutate _$4 = JSX - [6] Call mutate y$3.push(read props$1.p1) - [7] Const mutate $5 = JSX + [1] Let mutate x$2_@0[1:2] = Array [] + [2] Call mutate x$2_@0.push(read props$1.p0) + [3] Let mutate y$3_@1[3:6] = read x$2_@0 + [4] Reassign mutate x$2_@2 = Array [] + [5] Let mutate _$4_@3 = JSX + [6] Call mutate y$3_@1.push(read props$1.p1) + [7] Const mutate $5_@4 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $5"]) + bb0_instrs --> bb0_terminal(["Return read $5_@4"]) end %% Jumps 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 2cffad9c4a..ddac8203b2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md @@ -36,40 +36,40 @@ function Component(props) { ``` bb0: - [1] Let mutate x$2 = undefined + [1] Let mutate x$2_@0 = undefined If (read props$1.cond) then:bb2 else:bb10 bb2: predecessor blocks: bb0 - [2] Const mutate $3 = 2 - [3] Const mutate $4 = 1 - [4] Const mutate $5 = 0 + [2] Const mutate $3_@1 = 2 + [3] Const mutate $4_@2 = 1 + [4] Const mutate $5_@3 = 0 Switch (read props$1.test) - Case read $5: bb8 - Case read $4: bb6 - Case read $3: bb4 + Case read $5_@3: bb8 + Case read $4_@2: bb6 + Case read $3_@1: bb4 Default: bb4 bb8: predecessor blocks: bb2 - [5] Reassign mutate x$2 = read props$1.v0 + [5] Reassign mutate x$2_@4 = read props$1.v0 Goto bb1 bb6: predecessor blocks: bb2 - [6] Reassign mutate x$2 = read props$1.v1 + [6] Reassign mutate x$2_@5 = read props$1.v1 Goto bb1 bb4: predecessor blocks: bb2 - [7] Reassign mutate x$2 = read props$1.v2 + [7] Reassign mutate x$2_@6 = read props$1.v2 Goto bb1 bb10: predecessor blocks: bb0 If (read props$1.cond2) then:bb12 else:bb13 bb12: predecessor blocks: bb10 - [8] Reassign mutate x$2 = read props$1.b + [8] Reassign mutate x$2_@7 = read props$1.b Goto bb1 bb13: predecessor blocks: bb10 - [9] Reassign mutate x$2 = read props$1.c + [9] Reassign mutate x$2_@8 = read props$1.c Goto bb1 bb1: predecessor blocks: bb8 bb6 bb4 bb12 bb13 @@ -84,33 +84,33 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$2 = undefined + [1] Let mutate x$2_@0 = undefined "] bb0_instrs --> bb0_terminal(["If (read props$1.cond)"]) end subgraph bb2 bb2_instrs[" - [2] Const mutate $3 = 2 - [3] Const mutate $4 = 1 - [4] Const mutate $5 = 0 + [2] Const mutate $3_@1 = 2 + [3] Const mutate $4_@2 = 1 + [4] Const mutate $5_@3 = 0 "] bb2_instrs --> bb2_terminal(["Switch (read props$1.test)"]) end subgraph bb8 bb8_instrs[" - [5] Reassign mutate x$2 = read props$1.v0 + [5] Reassign mutate x$2_@4 = read props$1.v0 "] bb8_instrs --> bb8_terminal(["Goto"]) end subgraph bb6 bb6_instrs[" - [6] Reassign mutate x$2 = read props$1.v1 + [6] Reassign mutate x$2_@5 = read props$1.v1 "] bb6_instrs --> bb6_terminal(["Goto"]) end subgraph bb4 bb4_instrs[" - [7] Reassign mutate x$2 = read props$1.v2 + [7] Reassign mutate x$2_@6 = read props$1.v2 "] bb4_instrs --> bb4_terminal(["Goto"]) end @@ -119,13 +119,13 @@ flowchart TB end subgraph bb12 bb12_instrs[" - [8] Reassign mutate x$2 = read props$1.b + [8] Reassign mutate x$2_@7 = read props$1.b "] bb12_instrs --> bb12_terminal(["Goto"]) end subgraph bb13 bb13_instrs[" - [9] Reassign mutate x$2 = read props$1.c + [9] Reassign mutate x$2_@8 = read props$1.c "] bb13_instrs --> bb13_terminal(["Goto"]) end @@ -140,9 +140,9 @@ flowchart TB bb0_terminal -- then --> bb2 bb0_terminal -- else --> bb10 bb0_terminal -- fallthrough --> bb1 - bb2_terminal -- read $5 --> bb8 - bb2_terminal -- read $4 --> bb6 - bb2_terminal -- read $3 --> bb4 + bb2_terminal -- read $5_@3 --> bb8 + bb2_terminal -- read $4_@2 --> bb6 + bb2_terminal -- read $3_@1 --> bb4 bb2_terminal -- default --> bb4 bb2_terminal -- fallthrough --> bb1 bb8_terminal --> bb1 diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md index 5d2d0bd3af..81cdf5ff13 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md @@ -18,15 +18,15 @@ bb0: If (read x$1) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [1] Const mutate $3 = false - [2] Const mutate $4 = Call read foo$0(read $3, read y$2) - Return freeze $4 + [1] Const mutate $3_@0 = false + [2] Const mutate $4_@1 = Call read foo$0(read $3_@0, read y$2) + Return freeze $4_@1 bb1: predecessor blocks: bb0 - [3] Const mutate $5 = 10 - [4] Const mutate $6 = Binary read y$2 * read $5 - [5] Const mutate $7 = Array [read $6] - Return freeze $7 + [3] Const mutate $5_@2 = 10 + [4] Const mutate $6_@3 = Binary read y$2 * read $5_@2 + [5] Const mutate $7_@4 = Array [read $6_@3] + Return freeze $7_@4 ``` ### CFG @@ -39,18 +39,18 @@ flowchart TB end subgraph bb2 bb2_instrs[" - [1] Const mutate $3 = false - [2] Const mutate $4 = Call read foo$0(read $3, read y$2) + [1] Const mutate $3_@0 = false + [2] Const mutate $4_@1 = Call read foo$0(read $3_@0, read y$2) "] - bb2_instrs --> bb2_terminal(["Return freeze $4"]) + bb2_instrs --> bb2_terminal(["Return freeze $4_@1"]) end subgraph bb1 bb1_instrs[" - [3] Const mutate $5 = 10 - [4] Const mutate $6 = Binary read y$2 * read $5 - [5] Const mutate $7 = Array [read $6] + [3] Const mutate $5_@2 = 10 + [4] Const mutate $6_@3 = Binary read y$2 * read $5_@2 + [5] Const mutate $7_@4 = Array [read $6_@3] "] - bb1_instrs --> bb1_terminal(["Return freeze $7"]) + bb1_instrs --> bb1_terminal(["Return freeze $7_@4"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md index 22243133bf..99312b133f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md @@ -15,10 +15,10 @@ function Component(props) { ``` bb0: - [1] Const mutate a$2 = 1 - [2] Const mutate b$3 = 2 - [3] Const mutate x$4 = Array [read a$2, read b$3] - Return freeze x$4 + [1] Const mutate a$2_@0 = 1 + [2] Const mutate b$3_@1 = 2 + [3] Const mutate x$4_@2 = Array [read a$2_@0, read b$3_@1] + Return freeze x$4_@2 ``` ### CFG @@ -28,11 +28,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2 = 1 - [2] Const mutate b$3 = 2 - [3] Const mutate x$4 = Array [read a$2, read b$3] + [1] Const mutate a$2_@0 = 1 + [2] Const mutate b$3_@1 = 2 + [3] Const mutate x$4_@2 = Array [read a$2_@0, read b$3_@1] "] - bb0_instrs --> bb0_terminal(["Return freeze x$4"]) + bb0_instrs --> bb0_terminal(["Return freeze x$4_@2"]) end %% Jumps 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 2b154a0cc0..3427e0efd4 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 @@ -50,22 +50,22 @@ function foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:7] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $7 = Call mutate foo$4() - If (read $7) then:bb2 else:bb1 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:7] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $7_@0 = Call mutate foo$4_@0() + If (read $7_@0) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [5] Const mutate $6 = "div" - [6] Let mutate _$5 = JSX + [5] Const mutate $6_@1 = "div" + [6] Let mutate _$5_@2 = JSX Goto bb1 bb1: predecessor blocks: bb2 bb0 - [7] Call mutate foo$4(read a$2, mutate b$3) - [8] Const mutate $8 = "div" - [9] Const mutate $9 = JSX - Return read $9 + [7] Call mutate foo$4_@0(read a$2_@0, mutate b$3_@0) + [8] Const mutate $8_@3 = "div" + [9] Const mutate $9_@4 = JSX + Return read $9_@4 ``` ### CFG @@ -75,27 +75,27 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:7] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $7 = Call mutate foo$4() + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:7] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $7_@0 = Call mutate foo$4_@0() "] - bb0_instrs --> bb0_terminal(["If (read $7)"]) + bb0_instrs --> bb0_terminal(["If (read $7_@0)"]) end subgraph bb2 bb2_instrs[" - [5] Const mutate $6 = 'div' - [6] Let mutate _$5 = JSX + [5] Const mutate $6_@1 = 'div' + [6] Let mutate _$5_@2 = JSX "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [7] Call mutate foo$4(read a$2, mutate b$3) - [8] Const mutate $8 = 'div' - [9] Const mutate $9 = JSX + [7] Call mutate foo$4_@0(read a$2_@0, mutate b$3_@0) + [8] Const mutate $8_@3 = 'div' + [9] Const mutate $9_@4 = JSX "] - bb1_instrs --> bb1_terminal(["Return read $9"]) + bb1_instrs --> bb1_terminal(["Return read $9_@4"]) end %% Jumps 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 cf106c6bd7..285a805d1a 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 @@ -47,15 +47,15 @@ function foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = "div" - [5] Let mutate _$5 = JSX - [6] Call mutate foo$4(read a$2, mutate b$3) - [7] Const mutate $7 = "div" - [8] Const mutate $8 = JSX - Return read $8 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = "div" + [5] Let mutate _$5_@2 = JSX + [6] Call mutate foo$4_@0(read a$2_@0, mutate b$3_@0) + [7] Const mutate $7_@3 = "div" + [8] Const mutate $8_@4 = JSX + Return read $8_@4 ``` ### CFG @@ -65,16 +65,16 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:6] = Object { } - [3] Call mutate foo$4(mutate a$2, mutate b$3) - [4] Const mutate $6 = 'div' - [5] Let mutate _$5 = JSX - [6] Call mutate foo$4(read a$2, mutate b$3) - [7] Const mutate $7 = 'div' - [8] Const mutate $8 = JSX + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:6] = Object { } + [3] Call mutate foo$4_@0(mutate a$2_@0, mutate b$3_@0) + [4] Const mutate $6_@1 = 'div' + [5] Let mutate _$5_@2 = JSX + [6] Call mutate foo$4_@0(read a$2_@0, mutate b$3_@0) + [7] Const mutate $7_@3 = 'div' + [8] Const mutate $8_@4 = JSX "] - bb0_instrs --> bb0_terminal(["Return read $8"]) + bb0_instrs --> bb0_terminal(["Return read $8_@4"]) end %% Jumps 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 89c4e4b769..7db6d70a6c 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,27 +21,27 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 2 - [4] Const mutate $4 = Binary read y$2 === read $3 - If (read $4) then:bb2 else:bb1 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 2 + [4] Const mutate $4_@3 = Binary read y$2_@1 === read $3_@2 + If (read $4_@3) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$1 = 3 + [5] Reassign mutate x$1_@4 = 3 Goto bb1 bb1: predecessor blocks: bb2 bb0 - [6] Const mutate $5 = 3 - [7] Const mutate $6 = Binary read y$2 === read $5 - If (read $6) then:bb4 else:bb3 + [6] Const mutate $5_@5 = 3 + [7] Const mutate $6_@6 = Binary read y$2_@1 === read $5_@5 + If (read $6_@6) then:bb4 else:bb3 bb4: predecessor blocks: bb1 - [8] Reassign mutate x$1 = 5 + [8] Reassign mutate x$1_@7 = 5 Goto bb3 bb3: predecessor blocks: bb4 bb1 - [9] Reassign mutate y$2 = read x$1 + [9] Reassign mutate y$2_@8 = read x$1 Return ``` @@ -52,35 +52,35 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 2 - [4] Const mutate $4 = Binary read y$2 === read $3 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 2 + [4] Const mutate $4_@3 = Binary read y$2_@1 === read $3_@2 "] - bb0_instrs --> bb0_terminal(["If (read $4)"]) + bb0_instrs --> bb0_terminal(["If (read $4_@3)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$1 = 3 + [5] Reassign mutate x$1_@4 = 3 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [6] Const mutate $5 = 3 - [7] Const mutate $6 = Binary read y$2 === read $5 + [6] Const mutate $5_@5 = 3 + [7] Const mutate $6_@6 = Binary read y$2_@1 === read $5_@5 "] - bb1_instrs --> bb1_terminal(["If (read $6)"]) + bb1_instrs --> bb1_terminal(["If (read $6_@6)"]) end subgraph bb4 bb4_instrs[" - [8] Reassign mutate x$1 = 5 + [8] Reassign mutate x$1_@7 = 5 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [9] Reassign mutate y$2 = read x$1 + [9] Reassign mutate y$2_@8 = read x$1 "] 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 1e06c49a7d..567d4d1781 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 @@ -18,18 +18,18 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 2 - [4] Const mutate $4 = Binary read y$2 === read $3 - If (read $4) then:bb2 else:bb1 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 2 + [4] Const mutate $4_@3 = Binary read y$2_@1 === read $3_@2 + If (read $4_@3) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$1 = 3 + [5] Reassign mutate x$1_@4 = 3 Goto bb1 bb1: predecessor blocks: bb2 bb0 - [6] Reassign mutate y$2 = read x$1 + [6] Reassign mutate y$2_@5 = read x$1 Return ``` @@ -40,22 +40,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 2 - [4] Const mutate $4 = Binary read y$2 === read $3 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 2 + [4] Const mutate $4_@3 = Binary read y$2_@1 === read $3_@2 "] - bb0_instrs --> bb0_terminal(["If (read $4)"]) + bb0_instrs --> bb0_terminal(["If (read $4_@3)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$1 = 3 + [5] Reassign mutate x$1_@4 = 3 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [6] Reassign mutate y$2 = read x$1 + [6] Reassign mutate y$2_@5 = read x$1 "] 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 87671b513a..6f0c2a00a6 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,25 +19,25 @@ function foo(cond) { ``` bb0: - [1] Let mutate items$2 = Array [] + [1] Let mutate items$2_@0 = Array [] Goto bb1 bb1: predecessor blocks: bb0 bb4 - If (read items$2) then:bb3 else:bb2 + If (read items$2_@0) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [2] Let mutate y$3 = 0 + [2] Let mutate y$3_@1 = 0 If (read cond$1) then:bb5 else:bb4 bb5: predecessor blocks: bb3 - [3] Reassign mutate y$3 = 1 + [3] Reassign mutate y$3_@2 = 1 Goto bb4 bb4: predecessor blocks: bb5 bb3 Goto(Continue) bb1 bb2: predecessor blocks: bb1 - Return freeze items$2 + Return freeze items$2_@0 ``` ### CFG @@ -47,22 +47,22 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate items$2 = Array [] + [1] Let mutate items$2_@0 = Array [] "] bb0_instrs --> bb0_terminal(["Goto"]) end subgraph bb1 - bb1_terminal(["If (read items$2)"]) + bb1_terminal(["If (read items$2_@0)"]) end subgraph bb3 bb3_instrs[" - [2] Let mutate y$3 = 0 + [2] Let mutate y$3_@1 = 0 "] bb3_instrs --> bb3_terminal(["If (read cond$1)"]) end subgraph bb5 bb5_instrs[" - [3] Reassign mutate y$3 = 1 + [3] Reassign mutate y$3_@2 = 1 "] bb5_instrs --> bb5_terminal(["Goto"]) end @@ -70,7 +70,7 @@ flowchart TB bb4_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["Return freeze items$2"]) + bb2_terminal(["Return freeze items$2_@0"]) end %% Jumps 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 75c07a099e..484fadebd0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md @@ -16,17 +16,17 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 0 + [1] Let mutate x$1_@0 = 0 Goto bb1 bb1: predecessor blocks: bb0 bb4 - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 - If (read $4) then:bb4 else:bb2 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1 + If (read $4_@2) then:bb4 else:bb2 bb4: predecessor blocks: bb1 - [4] Const mutate $2 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3 Goto(Continue) bb1 bb2: predecessor blocks: bb1 @@ -40,21 +40,21 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 0 + [1] Let mutate x$1_@0 = 0 "] bb0_instrs --> bb0_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1 "] - bb1_instrs --> bb1_terminal(["If (read $4)"]) + bb1_instrs --> bb1_terminal(["If (read $4_@2)"]) end subgraph bb4 bb4_instrs[" - [4] Const mutate $2 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3 "] bb4_instrs --> bb4_terminal(["Goto"]) end 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 69d450b899..68ad393d26 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$1 = 1 - [2] Let mutate y$2 = 2 - If (read y$2) then:bb2 else:bb3 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + If (read y$2_@1) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [3] Let mutate z$3 = Binary read x$1 + read y$2 + [3] Let mutate z$3_@2 = Binary read x$1_@0 + read y$2_@1 Goto bb1 bb3: predecessor blocks: bb0 - [4] Let mutate z$4 = read x$1 + [4] Let mutate z$4_@3 = read x$1_@0 Goto bb1 bb1: predecessor blocks: bb2 bb3 @@ -42,20 +42,20 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 "] - bb0_instrs --> bb0_terminal(["If (read y$2)"]) + bb0_instrs --> bb0_terminal(["If (read y$2_@1)"]) end subgraph bb2 bb2_instrs[" - [3] Let mutate z$3 = Binary read x$1 + read y$2 + [3] Let mutate z$3_@2 = Binary read x$1_@0 + read y$2_@1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [4] Let mutate z$4 = read x$1 + [4] Let mutate z$4_@3 = read x$1_@0 "] bb3_instrs --> bb3_terminal(["Goto"]) 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 c9bdd7b054..c1e8cb87ce 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$4 = 0 + [1] Let mutate x$4_@0 = 0 While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb5 @@ -40,8 +40,8 @@ bb7: If (read c$3) then:bb9 else:bb8 bb9: predecessor blocks: bb7 - [2] Const mutate $5 = 1 - [3] Binary read x$4 + read $5 + [2] Const mutate $5_@1 = 1 + [3] Binary read x$4_@0 + read $5_@1 Goto(Continue) bb7 bb8: predecessor blocks: bb7 @@ -51,7 +51,7 @@ bb5: Goto(Continue) bb1 bb2: predecessor blocks: bb1 - Return read x$4 + Return read x$4_@0 ``` ### CFG @@ -61,7 +61,7 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$4 = 0 + [1] Let mutate x$4_@0 = 0 "] bb0_instrs --> bb0_terminal(["While"]) end @@ -82,8 +82,8 @@ flowchart TB end subgraph bb9 bb9_instrs[" - [2] Const mutate $5 = 1 - [3] Binary read x$4 + read $5 + [2] Const mutate $5_@1 = 1 + [3] Binary read x$4_@0 + read $5_@1 "] bb9_instrs --> bb9_terminal(["Goto"]) end @@ -94,7 +94,7 @@ flowchart TB bb5_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["Return read x$4"]) + bb2_terminal(["Return read x$4_@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 764ec57497..40550e4071 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md @@ -45,10 +45,10 @@ function Foo$0() { ``` bb0: - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:3] = Object { } - [3] Let mutate c$4 = New mutate Foo$5(mutate a$2, mutate b$3) - Return freeze c$4 + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:3] = Object { } + [3] Let mutate c$4_@0 = New mutate Foo$5_@0(mutate a$2_@0, mutate b$3_@0) + Return freeze c$4_@0 ``` ### CFG @@ -58,11 +58,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2[1:3] = Array [] - [2] Const mutate b$3[2:3] = Object { } - [3] Let mutate c$4 = New mutate Foo$5(mutate a$2, mutate b$3) + [1] Const mutate a$2_@0[1:3] = Array [] + [2] Const mutate b$3_@0[2:3] = Object { } + [3] Let mutate c$4_@0 = New mutate Foo$5_@0(mutate a$2_@0, mutate b$3_@0) "] - bb0_instrs --> bb0_terminal(["Return freeze c$4"]) + bb0_instrs --> bb0_terminal(["Return freeze c$4_@0"]) end %% Jumps 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 1507607142..3ae6199c5b 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 @@ -22,23 +22,23 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 1 - [4] Const mutate $4 = Binary read x$1 > read $3 - If (read $4) then:bb2 else:bb3 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 1 + [4] Const mutate $4_@3 = Binary read x$1_@0 > read $3_@2 + If (read $4_@3) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [5] Reassign mutate x$1 = 2 + [5] Reassign mutate x$1_@4 = 2 Goto bb1 bb3: predecessor blocks: bb0 - [6] Reassign mutate y$2 = 3 + [6] Reassign mutate y$2_@5 = 3 Goto bb1 bb1: predecessor blocks: bb2 bb3 - [7] Let mutate t$5 = Object { x: read x$1, y: read y$2 } - Return freeze t$5 + [7] Let mutate t$5_@6 = Object { x: read x$1, y: read y$2 } + Return freeze t$5_@6 ``` ### CFG @@ -48,30 +48,30 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 - [3] Const mutate $3 = 1 - [4] Const mutate $4 = Binary read x$1 > read $3 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + [3] Const mutate $3_@2 = 1 + [4] Const mutate $4_@3 = Binary read x$1_@0 > read $3_@2 "] - bb0_instrs --> bb0_terminal(["If (read $4)"]) + bb0_instrs --> bb0_terminal(["If (read $4_@3)"]) end subgraph bb2 bb2_instrs[" - [5] Reassign mutate x$1 = 2 + [5] Reassign mutate x$1_@4 = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [6] Reassign mutate y$2 = 3 + [6] Reassign mutate y$2_@5 = 3 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [7] Let mutate t$5 = Object { x: read x$1, y: read y$2 } + [7] Let mutate t$5_@6 = Object { x: read x$1, y: read y$2 } "] - bb1_instrs --> bb1_terminal(["Return freeze t$5"]) + bb1_instrs --> bb1_terminal(["Return freeze t$5_@6"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md index 04834b81e4..2517930984 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md @@ -15,10 +15,10 @@ function Component(props) { ``` bb0: - [1] Const mutate a$2 = 1 - [2] Const mutate b$3 = 2 - [3] Const mutate x$4 = Object { a: read a$2, b: read b$3 } - Return freeze x$4 + [1] Const mutate a$2_@0 = 1 + [2] Const mutate b$3_@1 = 2 + [3] Const mutate x$4_@2 = Object { a: read a$2_@0, b: read b$3_@1 } + Return freeze x$4_@2 ``` ### CFG @@ -28,11 +28,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate a$2 = 1 - [2] Const mutate b$3 = 2 - [3] Const mutate x$4 = Object { a: read a$2, b: read b$3 } + [1] Const mutate a$2_@0 = 1 + [2] Const mutate b$3_@1 = 2 + [3] Const mutate x$4_@2 = Object { a: read a$2_@0, b: read b$3_@1 } "] - bb0_instrs --> bb0_terminal(["Return freeze x$4"]) + bb0_instrs --> bb0_terminal(["Return freeze x$4_@2"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md index f4cc112895..5aefad393a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md @@ -15,11 +15,11 @@ function foo() { ``` bb0: - [1] Const mutate x$1 = Array [] - [2] Const mutate y$2[2:4] = Object { x: read x$1 } - [3] Const mutate $3[3:4] = Array [] - [4] Call mutate y$2.x.push(mutate $3) - Return freeze y$2 + [1] Const mutate x$1_@0 = Array [] + [2] Const mutate y$2_@1[2:4] = Object { x: read x$1_@0 } + [3] Const mutate $3_@1[3:4] = Array [] + [4] Call mutate y$2_@1.x.push(mutate $3_@1) + Return freeze y$2_@1 ``` ### CFG @@ -29,12 +29,12 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate x$1 = Array [] - [2] Const mutate y$2[2:4] = Object { x: read x$1 } - [3] Const mutate $3[3:4] = Array [] - [4] Call mutate y$2.x.push(mutate $3) + [1] Const mutate x$1_@0 = Array [] + [2] Const mutate y$2_@1[2:4] = Object { x: read x$1_@0 } + [3] Const mutate $3_@1[3:4] = Array [] + [4] Call mutate y$2_@1.x.push(mutate $3_@1) "] - bb0_instrs --> bb0_terminal(["Return freeze y$2"]) + bb0_instrs --> bb0_terminal(["Return freeze y$2_@1"]) end %% Jumps diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md index 127644943a..90096384b1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md @@ -15,10 +15,10 @@ function foo() { ``` bb0: - [1] Const mutate x$1 = Array [] - [2] Const mutate y$2[2:3] = Object { } - [3] Reassign mutate y$2.x[2:3] = read x$1 - Return freeze y$2 + [1] Const mutate x$1_@0 = Array [] + [2] Const mutate y$2_@1[2:3] = Object { } + [3] Reassign mutate y$2_@1.x[2:3] = read x$1_@0 + Return freeze y$2_@1 ``` ### CFG @@ -28,11 +28,11 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Const mutate x$1 = Array [] - [2] Const mutate y$2[2:3] = Object { } - [3] Reassign mutate y$2.x[2:3] = read x$1 + [1] Const mutate x$1_@0 = Array [] + [2] Const mutate y$2_@1[2:3] = Object { } + [3] Reassign mutate y$2_@1.x[2:3] = read x$1_@0 "] - bb0_instrs --> bb0_terminal(["Return freeze y$2"]) + bb0_instrs --> bb0_terminal(["Return freeze y$2_@1"]) end %% Jumps 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 513043401f..24899b88b8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md @@ -17,13 +17,13 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read x$1 === read $2 - If (read $3) then:bb2 else:bb1 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read x$1_@0 === read $2_@1 + If (read $3_@2) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [4] Reassign mutate x$1 = 2 + [4] Reassign mutate x$1_@3 = 2 Goto bb1 bb1: predecessor blocks: bb2 bb0 @@ -37,15 +37,15 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read x$1 === read $2 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read x$1_@0 === read $2_@1 "] - bb0_instrs --> bb0_terminal(["If (read $3)"]) + bb0_instrs --> bb0_terminal(["If (read $3_@2)"]) end subgraph bb2 bb2_instrs[" - [4] Reassign mutate x$1 = 2 + [4] Reassign mutate x$1_@3 = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end 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 419e383d1d..884c435033 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md @@ -49,20 +49,20 @@ function log$0() { ``` bb0: - [1] Let mutate str$2 = "" + [1] Let mutate str$2_@0 = "" If (read cond$1) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [2] Let mutate str$3 = "other test" - [3] Call mutate log$4(read str$3) + [2] Let mutate str$3_@1 = "other test" + [3] Call mutate log$4_@2(read str$3_@1) Goto bb1 bb3: predecessor blocks: bb0 - [4] Reassign mutate str$2 = "fallthrough test" + [4] Reassign mutate str$2_@3 = "fallthrough test" Goto bb1 bb1: predecessor blocks: bb2 bb3 - [5] Call mutate log$4(read str$2) + [5] Call mutate log$4_@2(read str$2) Return ``` @@ -73,26 +73,26 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate str$2 = '' + [1] Let mutate str$2_@0 = '' "] bb0_instrs --> bb0_terminal(["If (read cond$1)"]) end subgraph bb2 bb2_instrs[" - [2] Let mutate str$3 = 'other test' - [3] Call mutate log$4(read str$3) + [2] Let mutate str$3_@1 = 'other test' + [3] Call mutate log$4_@2(read str$3_@1) "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [4] Reassign mutate str$2 = 'fallthrough test' + [4] Reassign mutate str$2_@3 = 'fallthrough test' "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [5] Call mutate log$4(read str$2) + [5] Call mutate log$4_@2(read str$2) "] bb1_instrs --> bb1_terminal(["Return"]) 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 6686c62833..8bf4a1c3ec 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,21 +20,21 @@ function foo() { ``` bb0: - [1] Let mutate y$1 = 2 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read y$1 > read $2 - If (read $3) then:bb2 else:bb3 + [1] Let mutate y$1_@0 = 2 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read y$1_@0 > read $2_@1 + If (read $3_@2) then:bb2 else:bb3 bb2: predecessor blocks: bb0 - [4] Reassign mutate y$1 = 1 + [4] Reassign mutate y$1_@3 = 1 Goto bb1 bb3: predecessor blocks: bb0 - [5] Reassign mutate y$1 = 2 + [5] Reassign mutate y$1_@4 = 2 Goto bb1 bb1: predecessor blocks: bb2 bb3 - [6] Let mutate x$4 = read y$1 + [6] Let mutate x$4_@5 = read y$1 Return ``` @@ -45,27 +45,27 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate y$1 = 2 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read y$1 > read $2 + [1] Let mutate y$1_@0 = 2 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read y$1_@0 > read $2_@1 "] - bb0_instrs --> bb0_terminal(["If (read $3)"]) + bb0_instrs --> bb0_terminal(["If (read $3_@2)"]) end subgraph bb2 bb2_instrs[" - [4] Reassign mutate y$1 = 1 + [4] Reassign mutate y$1_@3 = 1 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [5] Reassign mutate y$1 = 2 + [5] Reassign mutate y$1_@4 = 2 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [6] Let mutate x$4 = read y$1 + [6] Let mutate x$4_@5 = read y$1 "] 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 e666b101bb..1d96b42baf 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$1 = 1 - [2] Let mutate y$2 = 2 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 Return ``` @@ -25,8 +25,8 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@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 4d8456815c..8fb1a46207 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$1 = 1 - [2] Let mutate y$2 = 2 - If (read y$2) then:bb2 else:bb1 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 + If (read y$2_@1) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [3] Let mutate z$3 = Binary read x$1 + read y$2 + [3] Let mutate z$3_@2 = Binary read x$1_@0 + read y$2_@1 Goto bb1 bb1: predecessor blocks: bb2 bb0 @@ -36,14 +36,14 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Let mutate y$2 = 2 + [1] Let mutate x$1_@0 = 1 + [2] Let mutate y$2_@1 = 2 "] - bb0_instrs --> bb0_terminal(["If (read y$2)"]) + bb0_instrs --> bb0_terminal(["If (read y$2_@1)"]) end subgraph bb2 bb2_instrs[" - [3] Let mutate z$3 = Binary read x$1 + read y$2 + [3] Let mutate z$3_@2 = Binary read x$1_@0 + read y$2_@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 8ed1f4824c..0ec6feb787 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md @@ -28,33 +28,33 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Const mutate $4 = 2 - [3] Const mutate $5 = Binary read x$1 === read $4 - [4] Const mutate $7 = 1 - [5] Const mutate $8 = Binary read x$1 === read $7 - Switch (read x$1) - Case read $8: bb5 - Case read $5: bb3 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $4_@1 = 2 + [3] Const mutate $5_@2 = Binary read x$1_@0 === read $4_@1 + [4] Const mutate $7_@3 = 1 + [5] Const mutate $8_@4 = Binary read x$1_@0 === read $7_@3 + Switch (read x$1_@0) + Case read $8_@4: bb5 + Case read $5_@2: bb3 Default: bb2 bb5: predecessor blocks: bb0 - [6] Const mutate $6 = 1 - [7] Reassign mutate x$1 = Binary read x$1 + read $6 + [6] Const mutate $6_@5 = 1 + [7] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $6_@5 Goto bb1 bb3: predecessor blocks: bb0 - [8] Const mutate $3 = 2 - [9] Reassign mutate x$1 = Binary read x$1 + read $3 + [8] Const mutate $3_@7 = 2 + [9] Reassign mutate x$1_@8 = Binary read x$1_@0 + read $3_@7 Goto bb1 bb2: predecessor blocks: bb0 - [10] Const mutate $2 = 3 - [11] Reassign mutate x$1 = Binary read x$1 + read $2 + [10] Const mutate $2_@9 = 3 + [11] Reassign mutate x$1_@10 = Binary read x$1_@0 + read $2_@9 Goto bb1 bb1: predecessor blocks: bb5 bb3 bb2 - [12] Let mutate y$9 = read x$1 + [12] Let mutate y$9_@11 = read x$1 Return ``` @@ -65,45 +65,45 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Const mutate $4 = 2 - [3] Const mutate $5 = Binary read x$1 === read $4 - [4] Const mutate $7 = 1 - [5] Const mutate $8 = Binary read x$1 === read $7 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $4_@1 = 2 + [3] Const mutate $5_@2 = Binary read x$1_@0 === read $4_@1 + [4] Const mutate $7_@3 = 1 + [5] Const mutate $8_@4 = Binary read x$1_@0 === read $7_@3 "] - bb0_instrs --> bb0_terminal(["Switch (read x$1)"]) + bb0_instrs --> bb0_terminal(["Switch (read x$1_@0)"]) end subgraph bb5 bb5_instrs[" - [6] Const mutate $6 = 1 - [7] Reassign mutate x$1 = Binary read x$1 + read $6 + [6] Const mutate $6_@5 = 1 + [7] Reassign mutate x$1_@6 = Binary read x$1_@0 + read $6_@5 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [8] Const mutate $3 = 2 - [9] Reassign mutate x$1 = Binary read x$1 + read $3 + [8] Const mutate $3_@7 = 2 + [9] Reassign mutate x$1_@8 = Binary read x$1_@0 + read $3_@7 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [10] Const mutate $2 = 3 - [11] Reassign mutate x$1 = Binary read x$1 + read $2 + [10] Const mutate $2_@9 = 3 + [11] Reassign mutate x$1_@10 = Binary read x$1_@0 + read $2_@9 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [12] Let mutate y$9 = read x$1 + [12] Let mutate y$9_@11 = read x$1 "] bb1_instrs --> bb1_terminal(["Return"]) end %% Jumps - bb0_terminal -- read $8 --> bb5 - bb0_terminal -- read $5 --> bb3 + bb0_terminal -- read $8_@4 --> bb5 + bb0_terminal -- read $5_@2 --> bb3 bb0_terminal -- default --> bb2 bb0_terminal -- fallthrough --> bb1 bb5_terminal --> bb1 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 fb71e85088..76a5aff98a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md @@ -16,13 +16,13 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read x$1 === read $2 - If (read $3) then:bb2 else:bb1 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read x$1_@0 === read $2_@1 + If (read $3_@2) then:bb2 else:bb1 bb2: predecessor blocks: bb0 - [4] Reassign mutate x$1 = 2 + [4] Reassign mutate x$1_@3 = 2 Goto bb1 bb1: predecessor blocks: bb2 bb0 @@ -36,15 +36,15 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 - [2] Const mutate $2 = 1 - [3] Const mutate $3 = Binary read x$1 === read $2 + [1] Let mutate x$1_@0 = 1 + [2] Const mutate $2_@1 = 1 + [3] Const mutate $3_@2 = Binary read x$1_@0 === read $2_@1 "] - bb0_instrs --> bb0_terminal(["If (read $3)"]) + bb0_instrs --> bb0_terminal(["If (read $3_@2)"]) end subgraph bb2 bb2_instrs[" - [4] Reassign mutate x$1 = 2 + [4] Reassign mutate x$1_@3 = 2 "] bb2_instrs --> bb2_terminal(["Goto"]) end 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 a5b96aeb94..48f6500e1f 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,21 +17,21 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 + [1] Let mutate x$1_@0 = 1 While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 - If (read $4) then:bb3 else:bb2 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1 + If (read $4_@2) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [4] Const mutate $2 = 1 - [5] Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Binary read x$1_@0 + read $2_@3 Goto(Continue) bb1 bb2: predecessor blocks: bb1 - Return read x$1 + Return read x$1_@0 ``` ### CFG @@ -41,26 +41,26 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 + [1] Let mutate x$1_@0 = 1 "] bb0_instrs --> bb0_terminal(["While"]) end subgraph bb1 bb1_instrs[" - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1_@0 < read $3_@1 "] - bb1_instrs --> bb1_terminal(["If (read $4)"]) + bb1_instrs --> bb1_terminal(["If (read $4_@2)"]) end subgraph bb3 bb3_instrs[" - [4] Const mutate $2 = 1 - [5] Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Binary read x$1_@0 + read $2_@3 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 - bb2_terminal(["Return read x$1"]) + bb2_terminal(["Return read x$1_@0"]) end %% Jumps 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 2d7c781eca..16c2dce0b2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md @@ -17,17 +17,17 @@ function foo() { ``` bb0: - [1] Let mutate x$1 = 1 + [1] Let mutate x$1_@0 = 1 While test=bb1 loop=bb3 fallthrough=bb2 bb1: predecessor blocks: bb0 bb3 - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 - If (read $4) then:bb3 else:bb2 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1 + If (read $4_@2) then:bb3 else:bb2 bb3: predecessor blocks: bb1 - [4] Const mutate $2 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3 Goto(Continue) bb1 bb2: predecessor blocks: bb1 @@ -41,21 +41,21 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$1 = 1 + [1] Let mutate x$1_@0 = 1 "] bb0_instrs --> bb0_terminal(["While"]) end subgraph bb1 bb1_instrs[" - [2] Const mutate $3 = 10 - [3] Const mutate $4 = Binary read x$1 < read $3 + [2] Const mutate $3_@1 = 10 + [3] Const mutate $4_@2 = Binary read x$1 < read $3_@1 "] - bb1_instrs --> bb1_terminal(["If (read $4)"]) + bb1_instrs --> bb1_terminal(["If (read $4_@2)"]) end subgraph bb3 bb3_instrs[" - [4] Const mutate $2 = 1 - [5] Reassign mutate x$1 = Binary read x$1 + read $2 + [4] Const mutate $2_@3 = 1 + [5] Reassign mutate x$1_@4 = Binary read x$1 + read $2_@3 "] bb3_instrs --> bb3_terminal(["Goto"]) end 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 c692dcb362..1580e97f38 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,31 +32,31 @@ function Component(props) { ``` bb0: - [1] Let mutate x$2[1:6] = Array [] - [2] Let mutate y$3 = undefined - [3] Const mutate $4 = false - [4] Const mutate $5 = true - [5] Const mutate $6 = 1 + [1] Let mutate x$2_@0[1:6] = Array [] + [2] Let mutate y$3_@1 = undefined + [3] Const mutate $4_@2 = false + [4] Const mutate $5_@3 = true + [5] Const mutate $6_@4 = 1 Switch (read props$1.p0) - Case read $6: bb1 - Case read $5: bb6 + Case read $6_@4: bb1 + Case read $5_@3: bb6 Default: bb1 - Case read $4: bb2 + Case read $4_@2: bb2 bb6: predecessor blocks: bb0 - [6] Call mutate x$2.push(read props$1.p2) - [7] Reassign mutate y$3 = Array [] + [6] Call mutate x$2_@0.push(read props$1.p2) + [7] Reassign mutate y$3_@5 = Array [] Goto bb1 bb2: predecessor blocks: bb0 - [8] Reassign mutate y$3 = read x$2 + [8] Reassign mutate y$3_@6 = read x$2_@0 Goto bb1 bb1: predecessor blocks: bb0 bb6 bb2 - [9] Const mutate child$7 = JSX + [9] Const mutate child$7_@7 = JSX [10] Call read y$3.push(read props$1.p4) - [11] Const mutate $8 = JSX {read child$7} - Return read $8 + [11] Const mutate $8_@8 = JSX {read child$7_@7} + Return read $8_@8 ``` ### CFG @@ -66,41 +66,41 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$2[1:6] = Array [] - [2] Let mutate y$3 = undefined - [3] Const mutate $4 = false - [4] Const mutate $5 = true - [5] Const mutate $6 = 1 + [1] Let mutate x$2_@0[1:6] = Array [] + [2] Let mutate y$3_@1 = undefined + [3] Const mutate $4_@2 = false + [4] Const mutate $5_@3 = true + [5] Const mutate $6_@4 = 1 "] bb0_instrs --> bb0_terminal(["Switch (read props$1.p0)"]) end subgraph bb6 bb6_instrs[" - [6] Call mutate x$2.push(read props$1.p2) - [7] Reassign mutate y$3 = Array [] + [6] Call mutate x$2_@0.push(read props$1.p2) + [7] Reassign mutate y$3_@5 = Array [] "] bb6_instrs --> bb6_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [8] Reassign mutate y$3 = read x$2 + [8] Reassign mutate y$3_@6 = read x$2_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [9] Const mutate child$7 = JSX + [9] Const mutate child$7_@7 = JSX [10] Call read y$3.push(read props$1.p4) - [11] Const mutate $8 = JSX {read child$7} + [11] Const mutate $8_@8 = JSX {read child$7_@7} "] - bb1_instrs --> bb1_terminal(["Return read $8"]) + bb1_instrs --> bb1_terminal(["Return read $8_@8"]) end %% Jumps - bb0_terminal -- read $6 --> bb1 - bb0_terminal -- read $5 --> bb6 + bb0_terminal -- read $6_@4 --> bb1 + bb0_terminal -- read $5_@3 --> bb6 bb0_terminal -- default --> bb1 - bb0_terminal -- read $4 --> bb2 + bb0_terminal -- read $4_@2 --> bb2 bb0_terminal -- fallthrough --> bb1 bb6_terminal --> bb1 bb2_terminal --> bb1 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 1c86b31a27..fd252c33fd 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,44 +36,44 @@ function foo(x) { ``` bb0: - [1] Let mutate y$2 = undefined - [2] Const mutate $3 = 5 - [3] Const mutate $4 = 4 - [4] Const mutate $5 = 3 - [5] Const mutate $6 = 2 - [6] Const mutate $7 = 1 - [7] Const mutate $8 = 0 + [1] Let mutate y$2_@0 = undefined + [2] Const mutate $3_@1 = 5 + [3] Const mutate $4_@2 = 4 + [4] Const mutate $5_@3 = 3 + [5] Const mutate $6_@4 = 2 + [6] Const mutate $7_@5 = 1 + [7] Const mutate $8_@6 = 0 Switch (read x$1) - Case read $8: bb10 - Case read $7: bb9 - Case read $6: bb1 - Case read $5: bb5 - Case read $4: bb4 - Case read $3: bb3 + Case read $8_@6: bb10 + Case read $7_@5: bb9 + Case read $6_@4: bb1 + Case read $5_@3: bb5 + Case read $4_@2: bb4 + Case read $3_@1: bb3 Default: bb2 bb10: predecessor blocks: bb0 - [8] Reassign mutate y$2 = 0 + [8] Reassign mutate y$2_@7 = 0 Goto bb9 bb9: predecessor blocks: bb10 bb0 - [9] Reassign mutate y$2 = 1 + [9] Reassign mutate y$2_@8 = 1 Goto bb1 bb5: predecessor blocks: bb0 - [10] Reassign mutate y$2 = 3 + [10] Reassign mutate y$2_@9 = 3 Goto bb1 bb4: predecessor blocks: bb0 - [11] Reassign mutate y$2 = 4 + [11] Reassign mutate y$2_@10 = 4 Goto bb3 bb3: predecessor blocks: bb4 bb0 - [12] Reassign mutate y$2 = 5 + [12] Reassign mutate y$2_@11 = 5 Goto bb2 bb2: predecessor blocks: bb3 bb0 - [13] Reassign mutate y$2 = 0 + [13] Reassign mutate y$2_@12 = 0 Goto bb1 bb1: predecessor blocks: bb9 bb0 bb5 bb2 @@ -87,49 +87,49 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate y$2 = undefined - [2] Const mutate $3 = 5 - [3] Const mutate $4 = 4 - [4] Const mutate $5 = 3 - [5] Const mutate $6 = 2 - [6] Const mutate $7 = 1 - [7] Const mutate $8 = 0 + [1] Let mutate y$2_@0 = undefined + [2] Const mutate $3_@1 = 5 + [3] Const mutate $4_@2 = 4 + [4] Const mutate $5_@3 = 3 + [5] Const mutate $6_@4 = 2 + [6] Const mutate $7_@5 = 1 + [7] Const mutate $8_@6 = 0 "] bb0_instrs --> bb0_terminal(["Switch (read x$1)"]) end subgraph bb10 bb10_instrs[" - [8] Reassign mutate y$2 = 0 + [8] Reassign mutate y$2_@7 = 0 "] bb10_instrs --> bb10_terminal(["Goto"]) end subgraph bb9 bb9_instrs[" - [9] Reassign mutate y$2 = 1 + [9] Reassign mutate y$2_@8 = 1 "] bb9_instrs --> bb9_terminal(["Goto"]) end subgraph bb5 bb5_instrs[" - [10] Reassign mutate y$2 = 3 + [10] Reassign mutate y$2_@9 = 3 "] bb5_instrs --> bb5_terminal(["Goto"]) end subgraph bb4 bb4_instrs[" - [11] Reassign mutate y$2 = 4 + [11] Reassign mutate y$2_@10 = 4 "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb3 bb3_instrs[" - [12] Reassign mutate y$2 = 5 + [12] Reassign mutate y$2_@11 = 5 "] bb3_instrs --> bb3_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [13] Reassign mutate y$2 = 0 + [13] Reassign mutate y$2_@12 = 0 "] bb2_instrs --> bb2_terminal(["Goto"]) end @@ -138,12 +138,12 @@ flowchart TB end %% Jumps - bb0_terminal -- read $8 --> bb10 - bb0_terminal -- read $7 --> bb9 - bb0_terminal -- read $6 --> bb1 - bb0_terminal -- read $5 --> bb5 - bb0_terminal -- read $4 --> bb4 - bb0_terminal -- read $3 --> bb3 + bb0_terminal -- read $8_@6 --> bb10 + bb0_terminal -- read $7_@5 --> bb9 + bb0_terminal -- read $6_@4 --> bb1 + bb0_terminal -- read $5_@3 --> bb5 + bb0_terminal -- read $4_@2 --> bb4 + bb0_terminal -- read $3_@1 --> bb3 bb0_terminal -- default --> bb2 bb0_terminal -- fallthrough --> bb1 bb10_terminal --> bb9 diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md index 0f59348259..59793e9474 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md @@ -28,30 +28,30 @@ function Component(props) { ``` bb0: - [1] Let mutate x$2[1:6] = Array [] - [2] Let mutate y$3 = undefined - [3] Const mutate $4 = false - [4] Const mutate $5 = true + [1] Let mutate x$2_@0[1:6] = Array [] + [2] Let mutate y$3_@1 = undefined + [3] Const mutate $4_@2 = false + [4] Const mutate $5_@3 = true Switch (read props$1.p0) - Case read $5: bb4 - Case read $4: bb2 + Case read $5_@3: bb4 + Case read $4_@2: bb2 Default: bb1 bb4: predecessor blocks: bb0 - [5] Call mutate x$2.push(read props$1.p2) - [6] Call mutate x$2.push(read props$1.p3) - [7] Reassign mutate y$3 = Array [] + [5] Call mutate x$2_@0.push(read props$1.p2) + [6] Call mutate x$2_@0.push(read props$1.p3) + [7] Reassign mutate y$3_@4 = Array [] Goto bb2 bb2: predecessor blocks: bb4 bb0 - [8] Reassign mutate y$3 = read x$2 + [8] Reassign mutate y$3_@5 = read x$2_@0 Goto bb1 bb1: predecessor blocks: bb2 bb0 - [9] Const mutate child$6 = JSX + [9] Const mutate child$6_@6 = JSX [10] Call read y$3.push(read props$1.p4) - [11] Const mutate $7 = JSX {read child$6} - Return read $7 + [11] Const mutate $7_@7 = JSX {read child$6_@6} + Return read $7_@7 ``` ### CFG @@ -61,39 +61,39 @@ flowchart TB %% Basic Blocks subgraph bb0 bb0_instrs[" - [1] Let mutate x$2[1:6] = Array [] - [2] Let mutate y$3 = undefined - [3] Const mutate $4 = false - [4] Const mutate $5 = true + [1] Let mutate x$2_@0[1:6] = Array [] + [2] Let mutate y$3_@1 = undefined + [3] Const mutate $4_@2 = false + [4] Const mutate $5_@3 = true "] bb0_instrs --> bb0_terminal(["Switch (read props$1.p0)"]) end subgraph bb4 bb4_instrs[" - [5] Call mutate x$2.push(read props$1.p2) - [6] Call mutate x$2.push(read props$1.p3) - [7] Reassign mutate y$3 = Array [] + [5] Call mutate x$2_@0.push(read props$1.p2) + [6] Call mutate x$2_@0.push(read props$1.p3) + [7] Reassign mutate y$3_@4 = Array [] "] bb4_instrs --> bb4_terminal(["Goto"]) end subgraph bb2 bb2_instrs[" - [8] Reassign mutate y$3 = read x$2 + [8] Reassign mutate y$3_@5 = read x$2_@0 "] bb2_instrs --> bb2_terminal(["Goto"]) end subgraph bb1 bb1_instrs[" - [9] Const mutate child$6 = JSX + [9] Const mutate child$6_@6 = JSX [10] Call read y$3.push(read props$1.p4) - [11] Const mutate $7 = JSX {read child$6} + [11] Const mutate $7_@7 = JSX {read child$6_@6} "] - bb1_instrs --> bb1_terminal(["Return read $7"]) + bb1_instrs --> bb1_terminal(["Return read $7_@7"]) end %% Jumps - bb0_terminal -- read $5 --> bb4 - bb0_terminal -- read $4 --> bb2 + bb0_terminal -- read $5_@3 --> bb4 + bb0_terminal -- read $4_@2 --> bb2 bb0_terminal -- default --> bb1 bb0_terminal -- fallthrough --> bb1 bb4_terminal --> bb2 diff --git a/compiler/forget/src/__tests__/hir-test.ts b/compiler/forget/src/__tests__/hir-test.ts index ddeb359c35..dccc49c0ea 100644 --- a/compiler/forget/src/__tests__/hir-test.ts +++ b/compiler/forget/src/__tests__/hir-test.ts @@ -21,6 +21,7 @@ import enterSSA from "../HIR/EnterSSA"; import { HIRFunction } from "../HIR/HIR"; import { Environment } from "../HIR/HIRBuilder"; import { inferMutableRanges } from "../HIR/InferMutableLifetimes"; +import { inferReactiveScopeVariables } from "../HIR/InferReactiveScopeVariables"; import inferReferenceEffects from "../HIR/InferReferenceEffects"; import leaveSSA from "../HIR/LeaveSSA"; import printHIR from "../HIR/PrintHIR"; @@ -70,6 +71,7 @@ describe("React Forget (HIR version)", () => { eliminateRedundantPhi(ir); inferReferenceEffects(ir); inferMutableRanges(ir); + inferReactiveScopeVariables(ir); leaveSSA(ir); const textHIR = printHIR(ir.body); const visualization = visualizeHIRMermaid(ir);