mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[valueblocks] Cleanup
Removes dead code related the now-unused old representation for value blocks.
This commit is contained in:
@@ -59,15 +59,6 @@ export type ReactiveScopeBlock = {
|
||||
|
||||
export type ReactiveBlock = Array<ReactiveStatement>;
|
||||
|
||||
export type ReactiveValueBlock = {
|
||||
kind: "value-block";
|
||||
instructions: ReactiveBlock;
|
||||
last: {
|
||||
value: Place;
|
||||
id: InstructionId;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export type ReactiveStatement =
|
||||
| ReactiveInstructionStatement
|
||||
| ReactiveTerminalStatement
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
ReactiveBlock,
|
||||
ReactiveFunction,
|
||||
ReactiveScope,
|
||||
ReactiveValueBlock,
|
||||
ScopeId,
|
||||
} from "../HIR/HIR";
|
||||
import { getPlaceScope } from "./BuildReactiveBlocks";
|
||||
@@ -90,11 +89,6 @@ class Visitor extends ReactiveFunctionVisitor<Context> {
|
||||
this.traverseBlock(block, state);
|
||||
}, "block");
|
||||
}
|
||||
override visitValueBlock(block: ReactiveValueBlock, state: Context): void {
|
||||
state.enter(() => {
|
||||
super.visitValueBlock(block, state);
|
||||
}, "value");
|
||||
}
|
||||
}
|
||||
|
||||
type PendingReactiveScope = { active: boolean; scope: ReactiveScope };
|
||||
|
||||
@@ -16,15 +16,10 @@ import {
|
||||
ReactiveScope,
|
||||
ReactiveScopeBlock,
|
||||
ReactiveStatement,
|
||||
ReactiveValueBlock,
|
||||
ScopeId,
|
||||
} from "../HIR";
|
||||
import { assertExhaustive } from "../Utils/utils";
|
||||
import {
|
||||
eachReactiveValueOperand,
|
||||
eachTerminalBlock,
|
||||
mapTerminalBlocks,
|
||||
} from "./visitors";
|
||||
import { eachReactiveValueOperand, mapTerminalBlocks } from "./visitors";
|
||||
|
||||
/**
|
||||
* Note: this is the 4th of 4 passes that determine how to break a function into discrete
|
||||
@@ -164,13 +159,6 @@ function visitBlock(context: Context, block: ReactiveBlock): void {
|
||||
visitBlock(context, block);
|
||||
});
|
||||
});
|
||||
eachTerminalBlock(
|
||||
stmt.terminal,
|
||||
(_) => {},
|
||||
(valueBlock) => {
|
||||
visitValueBlock(context, valueBlock);
|
||||
}
|
||||
);
|
||||
context.append(stmt, stmt.label);
|
||||
break;
|
||||
}
|
||||
@@ -190,27 +178,6 @@ function visitBlock(context: Context, block: ReactiveBlock): void {
|
||||
}
|
||||
}
|
||||
|
||||
function visitValueBlock(context: Context, block: ReactiveValueBlock): void {
|
||||
for (const stmt of block.instructions) {
|
||||
switch (stmt.kind) {
|
||||
case "instruction": {
|
||||
context.visitId(stmt.instruction.id);
|
||||
const scope = getInstructionScope(stmt.instruction);
|
||||
if (scope !== null) {
|
||||
context.visitScope(scope);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
invariant(false, "Unexpected terminal or scope in value block");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (block.last !== null) {
|
||||
context.visitId(block.last.id);
|
||||
}
|
||||
}
|
||||
|
||||
export function getInstructionScope({
|
||||
id,
|
||||
lvalue,
|
||||
|
||||
@@ -12,10 +12,8 @@ import {
|
||||
GotoVariant,
|
||||
HIR,
|
||||
InstructionId,
|
||||
InstructionValue,
|
||||
Place,
|
||||
ReactiveBlock,
|
||||
ReactiveValueBlock,
|
||||
SourceLocation,
|
||||
} from "../HIR";
|
||||
import {
|
||||
@@ -253,7 +251,7 @@ class Driver {
|
||||
);
|
||||
scheduleIds.push(scheduleId);
|
||||
|
||||
const testValue = this.visitValueBlockNew(
|
||||
const testValue = this.visitValueBlock(
|
||||
terminal.test,
|
||||
terminal.loc
|
||||
).value;
|
||||
@@ -307,7 +305,7 @@ class Driver {
|
||||
);
|
||||
scheduleIds.push(scheduleId);
|
||||
|
||||
const init = this.visitValueBlockNew(terminal.init, terminal.loc);
|
||||
const init = this.visitValueBlock(terminal.init, terminal.loc);
|
||||
const initBlock = this.cx.ir.blocks.get(init.block)!;
|
||||
let initValue = init.value;
|
||||
if (initValue.kind === "SequenceExpression") {
|
||||
@@ -331,12 +329,12 @@ class Driver {
|
||||
};
|
||||
}
|
||||
|
||||
const testValue = this.visitValueBlockNew(
|
||||
const testValue = this.visitValueBlock(
|
||||
terminal.test,
|
||||
terminal.loc
|
||||
).value;
|
||||
|
||||
const updateValue = this.visitValueBlockNew(
|
||||
const updateValue = this.visitValueBlock(
|
||||
terminal.update,
|
||||
terminal.loc
|
||||
).value;
|
||||
@@ -420,7 +418,7 @@ class Driver {
|
||||
const scheduleId = this.cx.schedule(fallthroughId, "if");
|
||||
scheduleIds.push(scheduleId);
|
||||
|
||||
const { place, value } = this.visitValueTerminal(terminal);
|
||||
const { place, value } = this.visitValueBlockTerminal(terminal);
|
||||
blockValue.push({
|
||||
kind: "instruction",
|
||||
instruction: {
|
||||
@@ -469,7 +467,7 @@ class Driver {
|
||||
}
|
||||
}
|
||||
|
||||
visitValueBlockNew(
|
||||
visitValueBlock(
|
||||
id: BlockId,
|
||||
loc: SourceLocation
|
||||
): { block: BlockId; value: ReactiveValue; place: Place } {
|
||||
@@ -483,7 +481,7 @@ class Driver {
|
||||
) {
|
||||
block = defaultBlock;
|
||||
} else {
|
||||
const result = this.visitValueTerminal(defaultBlock.terminal);
|
||||
const result = this.visitValueBlockTerminal(defaultBlock.terminal);
|
||||
block = this.cx.ir.blocks.get(result.fallthrough)!;
|
||||
place = result.place;
|
||||
value = result.value;
|
||||
@@ -531,7 +529,7 @@ class Driver {
|
||||
}
|
||||
}
|
||||
|
||||
visitValueTerminal(terminal: Terminal): {
|
||||
visitValueBlockTerminal(terminal: Terminal): {
|
||||
value: ReactiveValue;
|
||||
place: Place;
|
||||
fallthrough: BlockId;
|
||||
@@ -545,7 +543,9 @@ class Driver {
|
||||
if (defaultTestBlock.terminal.kind === "branch") {
|
||||
testBlock = defaultTestBlock;
|
||||
} else {
|
||||
const leftResult = this.visitValueTerminal(defaultTestBlock.terminal);
|
||||
const leftResult = this.visitValueBlockTerminal(
|
||||
defaultTestBlock.terminal
|
||||
);
|
||||
testBlock = this.cx.ir.blocks.get(leftResult.fallthrough)!;
|
||||
leftPlace = leftResult.place;
|
||||
leftValue = leftResult.value;
|
||||
@@ -583,7 +583,7 @@ class Driver {
|
||||
};
|
||||
left = sequence;
|
||||
}
|
||||
const right = this.visitValueBlockNew(
|
||||
const right = this.visitValueBlock(
|
||||
testBlock.terminal.alternate,
|
||||
terminal.loc
|
||||
);
|
||||
@@ -605,18 +605,18 @@ class Driver {
|
||||
};
|
||||
}
|
||||
case "ternary": {
|
||||
const test = this.visitValueBlockNew(terminal.test, terminal.loc);
|
||||
const test = this.visitValueBlock(terminal.test, terminal.loc);
|
||||
const testBlock = this.cx.ir.blocks.get(test.block)!;
|
||||
invariant(
|
||||
testBlock.terminal.kind === "branch",
|
||||
"Unexpected terminal kind '%s' for ternary test block",
|
||||
testBlock.terminal.kind
|
||||
);
|
||||
const consequent = this.visitValueBlockNew(
|
||||
const consequent = this.visitValueBlock(
|
||||
testBlock.terminal.consequent,
|
||||
terminal.loc
|
||||
);
|
||||
const alternate = this.visitValueBlockNew(
|
||||
const alternate = this.visitValueBlock(
|
||||
testBlock.terminal.alternate,
|
||||
terminal.loc
|
||||
);
|
||||
@@ -647,44 +647,6 @@ class Driver {
|
||||
}
|
||||
}
|
||||
|
||||
visitInitBlock(parent: ReactiveBlock, block: BasicBlock): ReactiveValueBlock {
|
||||
const initBlock: ReactiveValueBlock = {
|
||||
kind: "value-block",
|
||||
instructions: [],
|
||||
last: null,
|
||||
};
|
||||
for (const instruction of block.instructions) {
|
||||
initBlock.instructions.push({
|
||||
kind: "instruction",
|
||||
instruction,
|
||||
});
|
||||
}
|
||||
return initBlock;
|
||||
}
|
||||
|
||||
visitValueBlock(
|
||||
parent: ReactiveBlock,
|
||||
block: BasicBlock,
|
||||
terminalValue?: { value: Place; id: InstructionId }
|
||||
): ReactiveValueBlock {
|
||||
const valueBlock: ReactiveValueBlock = {
|
||||
kind: "value-block",
|
||||
instructions: [],
|
||||
last: terminalValue ?? null,
|
||||
};
|
||||
let lastValue: { value: InstructionValue; id: InstructionId } | null = null;
|
||||
if (terminalValue != null) {
|
||||
lastValue = terminalValue;
|
||||
}
|
||||
for (const instruction of block.instructions) {
|
||||
valueBlock.instructions.push({
|
||||
kind: "instruction",
|
||||
instruction,
|
||||
});
|
||||
}
|
||||
return valueBlock;
|
||||
}
|
||||
|
||||
emptyBlock(): ReactiveBlock {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
ReactiveScopeDependency,
|
||||
ReactiveTerminal,
|
||||
ReactiveValue,
|
||||
ReactiveValueBlock,
|
||||
SourceLocation,
|
||||
} from "../HIR/HIR";
|
||||
import { todoInvariant } from "../Utils/todo";
|
||||
@@ -361,33 +360,6 @@ function codegenForInit(
|
||||
}
|
||||
}
|
||||
|
||||
function codegenValueBlock(
|
||||
cx: Context,
|
||||
block: ReactiveValueBlock
|
||||
): t.Expression {
|
||||
const body = codegenBlock(cx, block.instructions).body;
|
||||
const expressions = body.map((stmt) => {
|
||||
if (stmt.type === "ExpressionStatement") {
|
||||
return stmt.expression;
|
||||
} else {
|
||||
todoInvariant(false, `Handle conversion of ${stmt.type} to expression`);
|
||||
}
|
||||
});
|
||||
if (block.last !== null) {
|
||||
const value = codegenInstructionValue(cx, block.last.value);
|
||||
expressions.push(value);
|
||||
}
|
||||
invariant(
|
||||
expressions.length !== 0,
|
||||
"Expected a value block to produce one or more expressions"
|
||||
);
|
||||
if (expressions.length === 1) {
|
||||
return expressions[0];
|
||||
} else {
|
||||
return t.sequenceExpression(expressions);
|
||||
}
|
||||
}
|
||||
|
||||
function codegenDependency(
|
||||
cx: Context,
|
||||
dependency: ReactiveScopeDependency
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
ReactiveStatement,
|
||||
ReactiveTerminal,
|
||||
ReactiveValue,
|
||||
ReactiveValueBlock,
|
||||
} from "../HIR/HIR";
|
||||
import {
|
||||
printIdentifier,
|
||||
@@ -111,17 +110,6 @@ function printReactiveInstruction(
|
||||
}
|
||||
}
|
||||
|
||||
function printValueBlock(writer: Writer, block: ReactiveValueBlock): void {
|
||||
writer.indented(() => {
|
||||
for (const instr of block.instructions) {
|
||||
printReactiveInstruction(writer, instr);
|
||||
}
|
||||
if (block.last !== null) {
|
||||
writer.writeLine(printInstructionValue(block.last.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function printReactiveValue(writer: Writer, value: ReactiveValue): void {
|
||||
switch (value.kind) {
|
||||
case "ConditionalExpression": {
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
ReactiveScope,
|
||||
ReactiveScopeDependency,
|
||||
ReactiveValue,
|
||||
ReactiveValueBlock,
|
||||
} from "../HIR/HIR";
|
||||
import { eachInstructionValueOperand } from "../HIR/visitors";
|
||||
import { assertExhaustive } from "../Utils/utils";
|
||||
@@ -274,17 +273,6 @@ function visit(context: Context, block: ReactiveBlock): void {
|
||||
}
|
||||
}
|
||||
|
||||
function visitValueBlock(context: Context, block: ReactiveValueBlock): void {
|
||||
for (const initItem of block.instructions) {
|
||||
if (initItem.kind === "instruction") {
|
||||
visitInstruction(context, initItem.instruction);
|
||||
}
|
||||
}
|
||||
if (block.last !== null) {
|
||||
visitInstructionValue(context, block.last.value, null);
|
||||
}
|
||||
}
|
||||
|
||||
function visitReactiveValue(context: Context, value: ReactiveValue): void {
|
||||
switch (value.kind) {
|
||||
case "LogicalExpression": {
|
||||
|
||||
@@ -7,18 +7,15 @@
|
||||
|
||||
import {
|
||||
InstructionId,
|
||||
InstructionValue,
|
||||
LValue,
|
||||
Place,
|
||||
ReactiveBlock,
|
||||
ReactiveFunction,
|
||||
ReactiveInstruction,
|
||||
ReactiveScope,
|
||||
ReactiveScopeBlock,
|
||||
ReactiveTerminal,
|
||||
ReactiveTerminalStatement,
|
||||
ReactiveValue,
|
||||
ReactiveValueBlock,
|
||||
} from "../HIR/HIR";
|
||||
import { eachInstructionValueOperand } from "../HIR/visitors";
|
||||
import { assertExhaustive } from "../Utils/utils";
|
||||
@@ -142,14 +139,6 @@ export class ReactiveFunctionVisitor<TState = void> {
|
||||
}
|
||||
}
|
||||
|
||||
visitValueBlock(block: ReactiveValueBlock, state: TState): void {
|
||||
// NOTE: intentionally bypass calling visitBlock
|
||||
this.traverseBlock(block.instructions, state);
|
||||
if (block.last !== null) {
|
||||
this.visitPlace(block.last.id, block.last.value, state);
|
||||
}
|
||||
}
|
||||
|
||||
visitScope(scope: ReactiveScopeBlock, state: TState): void {
|
||||
this.traverseScope(scope, state);
|
||||
}
|
||||
@@ -186,69 +175,6 @@ export class ReactiveFunctionVisitor<TState = void> {
|
||||
}
|
||||
}
|
||||
|
||||
export function visitFunction(
|
||||
fn: ReactiveFunction,
|
||||
visitors: {
|
||||
visitValue?: (value: InstructionValue) => void;
|
||||
visitInstruction?: (instr: ReactiveInstruction) => void;
|
||||
visitTerminal?: (terminal: ReactiveTerminal) => void;
|
||||
visitScope?: (scope: ReactiveScope) => void;
|
||||
}
|
||||
): void {
|
||||
const { visitValue, visitInstruction, visitTerminal, visitScope } = visitors;
|
||||
function visitBlock(block: ReactiveBlock): void {
|
||||
for (const item of block) {
|
||||
switch (item.kind) {
|
||||
case "instruction": {
|
||||
if (visitValue) {
|
||||
for (const operand of eachReactiveValueOperand(
|
||||
item.instruction.value
|
||||
)) {
|
||||
visitValue(operand);
|
||||
}
|
||||
}
|
||||
if (visitInstruction) {
|
||||
visitInstruction(item.instruction);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "terminal": {
|
||||
if (visitValue) {
|
||||
eachTerminalOperand(item.terminal, (operand) => {
|
||||
visitValue(operand);
|
||||
});
|
||||
}
|
||||
if (visitTerminal) {
|
||||
visitTerminal(item.terminal);
|
||||
}
|
||||
eachTerminalBlock(item.terminal, visitBlock, visitValueBlock);
|
||||
break;
|
||||
}
|
||||
case "scope": {
|
||||
if (visitScope) {
|
||||
visitScope(item.scope);
|
||||
}
|
||||
visitBlock(item.instructions);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assertExhaustive(
|
||||
item,
|
||||
`Unexpected item kind '${(item as any).kind}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function visitValueBlock(block: ReactiveValueBlock): void {
|
||||
visitBlock(block.instructions);
|
||||
if (block.last !== null && visitValue) {
|
||||
visitValue(block.last.value);
|
||||
}
|
||||
}
|
||||
visitBlock(fn.body);
|
||||
}
|
||||
|
||||
export function* eachReactiveValueOperand(
|
||||
instrValue: ReactiveValue
|
||||
): Iterable<Place> {
|
||||
@@ -319,100 +245,3 @@ export function mapTerminalBlocks(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function eachTerminalBlock(
|
||||
terminal: ReactiveTerminal,
|
||||
visitBlock: (block: ReactiveBlock) => void,
|
||||
visitValueBlock: (block: ReactiveValueBlock) => void
|
||||
): void {
|
||||
switch (terminal.kind) {
|
||||
case "break":
|
||||
case "continue":
|
||||
case "return":
|
||||
case "throw": {
|
||||
break;
|
||||
}
|
||||
case "for": {
|
||||
// TODO
|
||||
// visitValueBlock(terminal.init);
|
||||
// visitValueBlock(terminal.test);
|
||||
// visitValueBlock(terminal.update);
|
||||
visitBlock(terminal.loop);
|
||||
break;
|
||||
}
|
||||
case "while": {
|
||||
// TODO
|
||||
// visitValueBlock(terminal.test);
|
||||
visitBlock(terminal.loop);
|
||||
break;
|
||||
}
|
||||
case "if": {
|
||||
visitBlock(terminal.consequent);
|
||||
if (terminal.alternate !== null) {
|
||||
visitBlock(terminal.alternate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "switch": {
|
||||
for (const case_ of terminal.cases) {
|
||||
if (case_.block !== undefined) {
|
||||
visitBlock(case_.block);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assertExhaustive(
|
||||
terminal,
|
||||
`Unexpected terminal kind '${(terminal as any).kind}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function eachTerminalOperand(
|
||||
terminal: ReactiveTerminal,
|
||||
fn: (place: Place) => void
|
||||
): void {
|
||||
switch (terminal.kind) {
|
||||
case "break":
|
||||
case "continue": {
|
||||
break;
|
||||
}
|
||||
case "return": {
|
||||
if (terminal.value !== null) {
|
||||
fn(terminal.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "throw": {
|
||||
fn(terminal.value);
|
||||
break;
|
||||
}
|
||||
case "for": {
|
||||
break;
|
||||
}
|
||||
case "while": {
|
||||
break;
|
||||
}
|
||||
case "if": {
|
||||
fn(terminal.test);
|
||||
break;
|
||||
}
|
||||
case "switch": {
|
||||
fn(terminal.test);
|
||||
for (const case_ of terminal.cases) {
|
||||
if (case_.test !== null) {
|
||||
fn(case_.test);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
assertExhaustive(
|
||||
terminal,
|
||||
`Unexpected terminal kind '${(terminal as any).kind}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user