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.
This commit is contained in:
Joe Savona
2023-11-01 17:13:01 -07:00
parent 5cdfa7cdc4
commit 748859a00e
5 changed files with 16 additions and 0 deletions
@@ -76,6 +76,7 @@ export function lower(
kind: "Identifier",
identifier: builder.resolveBinding(ref),
effect: Effect.Unknown,
reactive: false,
loc: ref.loc ?? GeneratedSource,
});
}
@@ -106,6 +107,7 @@ export function lower(
kind: "Identifier",
identifier,
effect: Effect.Unknown,
reactive: false,
loc: param.node.loc ?? GeneratedSource,
};
params.push(place);
@@ -118,6 +120,7 @@ export function lower(
kind: "Identifier",
identifier: builder.makeTemporary(),
effect: Effect.Unknown,
reactive: false,
loc: param.node.loc ?? GeneratedSource,
};
params.push(place);
@@ -133,6 +136,7 @@ export function lower(
kind: "Identifier",
identifier: builder.makeTemporary(),
effect: Effect.Unknown,
reactive: false,
loc: param.node.loc ?? GeneratedSource,
};
params.push({
@@ -403,6 +407,7 @@ function lowerStatement(
effect: Effect.Unknown,
identifier,
kind: "Identifier",
reactive: false,
loc: id.node.loc ?? GeneratedSource,
};
lowerValueToTemporary(builder, {
@@ -790,6 +795,7 @@ function lowerStatement(
effect: Effect.Unknown,
identifier,
kind: "Identifier",
reactive: false,
loc: id.node.loc ?? GeneratedSource,
};
if (builder.isContextIdentifier(id)) {
@@ -1158,6 +1164,7 @@ function lowerStatement(
kind: "Identifier",
identifier: builder.makeTemporary(),
effect: Effect.Unknown,
reactive: false,
loc: handlerBindingPath.node.loc ?? GeneratedSource,
};
lowerValueToTemporary(builder, {
@@ -3021,6 +3028,7 @@ function lowerIdentifier(
kind: "Identifier",
identifier: identifier,
effect: Effect.Unknown,
reactive: false,
loc: exprLoc,
};
return place;
@@ -3034,6 +3042,7 @@ function buildTemporaryPlace(builder: HIRBuilder, loc: SourceLocation): Place {
kind: "Identifier",
identifier: builder.makeTemporary(),
effect: Effect.Unknown,
reactive: false,
loc,
};
return place;
@@ -3087,6 +3096,7 @@ function lowerIdentifierForAssignment(
kind: "Identifier",
identifier: identifier,
effect: Effect.Unknown,
reactive: false,
loc,
};
return place;
@@ -877,6 +877,7 @@ export type Place = {
kind: "Identifier";
identifier: Identifier;
effect: Effect;
reactive: boolean;
loc: SourceLocation;
};
@@ -75,6 +75,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
kind: "Identifier",
identifier: phi.id,
effect: Effect.ConditionallyMutate,
reactive: false,
loc: GeneratedSource,
},
value: {
@@ -83,6 +84,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
kind: "Identifier",
identifier: operand,
effect: Effect.Read,
reactive: false,
loc: GeneratedSource,
},
loc: GeneratedSource,
@@ -58,6 +58,7 @@ export function dropManualMemoization(func: HIRFunction): void {
kind: "Identifier",
identifier: fn.identifier,
effect: Effect.Unknown,
reactive: false,
loc: instr.value.loc,
},
loc: instr.value.loc,
@@ -226,6 +226,7 @@ function rewriteBlock(
type: makeType(),
},
kind: "Identifier",
reactive: false,
loc: terminal.loc,
},
value: {
@@ -265,6 +266,7 @@ function declareTemporary(
type: makeType(),
},
kind: "Identifier",
reactive: false,
loc: GeneratedSource,
},
value: {