@samitouri / QOS-React-2 / commits / 6ce4cd0898

[rhir] Revert logic that dedupes inlined temporaries

Reverts #1199, which was added before we properly supported destructuring assignment. Next PR (changes to PropertyCall in #1384) will lower two references to the same named identifier (the property call receiver)

Mofei Zhang committed Mar 21, 2023 at 14:57 UTC 6ce4cd089842f9f96068e362503c469aaf727f46
4 files changed +4 -36
compiler/forget/src/ReactiveScopes/PromoteUsedTemporaries.ts
-27
@@ -6,9 +6,6 @@
6 */
7
8 import {
9 - Identifier,
10 - InstructionId,
11 - Place,
9 ReactiveFunction,
10 ReactiveInstruction,
11 ReactiveScopeBlock,
@@ -16,7 +13,6 @@ import {
13 import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
14
15 type VisitorState = {
19 - temporaries: Map<Identifier, number>;
16 nextId: number;
17 };
18 class Visitor extends ReactiveFunctionVisitor<VisitorState> {
@@ -39,39 +35,16 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
35 }
36 }
37 }
42 - override visitPlace(
43 - id: InstructionId,
44 - place: Place,
45 - state: VisitorState
46 - ): void {
47 - let count = state.temporaries.get(place.identifier);
48 - if (count !== undefined) {
49 - state.temporaries.set(place.identifier, count + 1);
50 - }
51 - }
38 override visitInstruction(
39 instruction: ReactiveInstruction,
40 state: VisitorState
41 ): void {
42 this.traverseInstruction(instruction, state);
57 - if (
58 - instruction.lvalue !== null &&
59 - instruction.lvalue.identifier.name === null &&
60 - instruction.value.kind !== "LoadLocal"
61 - ) {
62 - state.temporaries.set(instruction.lvalue.identifier, 0);
63 - }
43 }
44 }
45 export function promoteUsedTemporaries(fn: ReactiveFunction): void {
46 const state: VisitorState = {
47 nextId: 0,
69 - temporaries: new Map(),
48 };
49 visitReactiveFunction(fn, new Visitor(), state);
72 - for (const [identifier, count] of state.temporaries) {
73 - if (count > 1) {
74 - identifier.name = `t${state.nextId++}`;
75 - }
76 - }
50 }
compiler/forget/src/__tests__/fixtures/compiler/assignment-expression-computed.expect.md
+2 -5
@@ -21,11 +21,8 @@ function Component(props) {
21 let x;
22 if (c_0) {
23 x = [props.x];
24 -
25 - const t0 = 0;
26 - x[t0] = x[t0] * 2;
27 - const t1 = "0";
28 - x[t1] = x[t1] + 3;
24 + x[0] = x[0] * 2;
25 + x["0"] = x["0"] + 3;
26 $[0] = props.x;
27 $[1] = x;
28 } else {
compiler/forget/src/__tests__/fixtures/compiler/assignment-expression-nested-path.expect.md
+1 -2
@@ -21,8 +21,7 @@ function g(props) {
21 if (c_0) {
22 a = { b: { c: props.c } };
23 a.b.c = a.b.c + 1;
24 - const t0 = a.b;
25 - t0.c = t0.c * 2;
24 + a.b.c = a.b.c * 2;
25 $[0] = props.c;
26 $[1] = a;
27 } else {
compiler/forget/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue.expect.md
+1 -2
@@ -20,8 +20,7 @@ function g() {
20 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21 x = { y: { z: 1 } };
22 x.y.z = x.y.z + 1;
23 - const t0 = x.y;
24 - t0.z = t0.z * 2;
23 + x.y.z = x.y.z * 2;
24 $[0] = x;
25 } else {
26 x = $[0];