@samitouri / QOS-React-1 / commits / 748859a00e

Add `reactive` flag to Place

This is part of a stack for inferring variables which are reactive via *control dependencies* as opposed to a data dependency. In compiler engineering, a statement S2 is control-dependent on statement S1 if S1 is in the post-dominance frontier of S2. Stated more intuitively: if S1 decides whether or not S2 is reached, then S1 is a control dependency of S2. As a start, we add `Place.reactive: boolean` so that individual places can track whether they are reactive or not. This lets us do fine-grained reactivity inference on the control-flow graph, even taking into account different SSA instances of a variable, so that we can say that a particular SSA version of `x` is reactive, while other "versions" of x (due to reassignment) are not.

Joe Savona committed Nov 1, 2023 at 17:13 UTC 748859a00e5658c953c6732051ac374ba2bf39da
5 files changed +16
compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts
+10
@@ -76,6 +76,7 @@ export function lower(
76 kind: "Identifier",
77 identifier: builder.resolveBinding(ref),
78 effect: Effect.Unknown,
79 + reactive: false,
80 loc: ref.loc ?? GeneratedSource,
81 });
82 }
@@ -106,6 +107,7 @@ export function lower(
107 kind: "Identifier",
108 identifier,
109 effect: Effect.Unknown,
110 + reactive: false,
111 loc: param.node.loc ?? GeneratedSource,
112 };
113 params.push(place);
@@ -118,6 +120,7 @@ export function lower(
120 kind: "Identifier",
121 identifier: builder.makeTemporary(),
122 effect: Effect.Unknown,
123 + reactive: false,
124 loc: param.node.loc ?? GeneratedSource,
125 };
126 params.push(place);
@@ -133,6 +136,7 @@ export function lower(
136 kind: "Identifier",
137 identifier: builder.makeTemporary(),
138 effect: Effect.Unknown,
139 + reactive: false,
140 loc: param.node.loc ?? GeneratedSource,
141 };
142 params.push({
@@ -403,6 +407,7 @@ function lowerStatement(
407 effect: Effect.Unknown,
408 identifier,
409 kind: "Identifier",
410 + reactive: false,
411 loc: id.node.loc ?? GeneratedSource,
412 };
413 lowerValueToTemporary(builder, {
@@ -790,6 +795,7 @@ function lowerStatement(
795 effect: Effect.Unknown,
796 identifier,
797 kind: "Identifier",
798 + reactive: false,
799 loc: id.node.loc ?? GeneratedSource,
800 };
801 if (builder.isContextIdentifier(id)) {
@@ -1158,6 +1164,7 @@ function lowerStatement(
1164 kind: "Identifier",
1165 identifier: builder.makeTemporary(),
1166 effect: Effect.Unknown,
1167 + reactive: false,
1168 loc: handlerBindingPath.node.loc ?? GeneratedSource,
1169 };
1170 lowerValueToTemporary(builder, {
@@ -3021,6 +3028,7 @@ function lowerIdentifier(
3028 kind: "Identifier",
3029 identifier: identifier,
3030 effect: Effect.Unknown,
3031 + reactive: false,
3032 loc: exprLoc,
3033 };
3034 return place;
@@ -3034,6 +3042,7 @@ function buildTemporaryPlace(builder: HIRBuilder, loc: SourceLocation): Place {
3042 kind: "Identifier",
3043 identifier: builder.makeTemporary(),
3044 effect: Effect.Unknown,
3045 + reactive: false,
3046 loc,
3047 };
3048 return place;
@@ -3087,6 +3096,7 @@ function lowerIdentifierForAssignment(
3096 kind: "Identifier",
3097 identifier: identifier,
3098 effect: Effect.Unknown,
3099 + reactive: false,
3100 loc,
3101 };
3102 return place;
compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+1
@@ -877,6 +877,7 @@ export type Place = {
877 kind: "Identifier";
878 identifier: Identifier;
879 effect: Effect;
880 + reactive: boolean;
881 loc: SourceLocation;
882 };
883
compiler/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts
+2
@@ -75,6 +75,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
75 kind: "Identifier",
76 identifier: phi.id,
77 effect: Effect.ConditionallyMutate,
78 + reactive: false,
79 loc: GeneratedSource,
80 },
81 value: {
@@ -83,6 +84,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
84 kind: "Identifier",
85 identifier: operand,
86 effect: Effect.Read,
87 + reactive: false,
88 loc: GeneratedSource,
89 },
90 loc: GeneratedSource,
compiler/packages/babel-plugin-react-forget/src/Inference/DropManualMemoization.ts
+1
@@ -58,6 +58,7 @@ export function dropManualMemoization(func: HIRFunction): void {
58 kind: "Identifier",
59 identifier: fn.identifier,
60 effect: Effect.Unknown,
61 + reactive: false,
62 loc: instr.value.loc,
63 },
64 loc: instr.value.loc,
compiler/packages/babel-plugin-react-forget/src/Inference/InlineImmediatelyInvokedFunctionExpressions.ts
+2
@@ -226,6 +226,7 @@ function rewriteBlock(
226 type: makeType(),
227 },
228 kind: "Identifier",
229 + reactive: false,
230 loc: terminal.loc,
231 },
232 value: {
@@ -265,6 +266,7 @@ function declareTemporary(
266 type: makeType(),
267 },
268 kind: "Identifier",
269 + reactive: false,
270 loc: GeneratedSource,
271 },
272 value: {