[valueblocks] Cleanup
Removes dead code related the now-unused old representation for value blocks.
Joe Savona committed
Jan 31, 2023 at 13:39 UTC
0c5176c61818779d97bc4ecfa8ac768519c3e89a
8 files changed
+16
-325
compiler/forget/src/HIR/HIR.ts
-9
@@ -59,15 +59,6 @@ export type ReactiveScopeBlock = {
59
60
export type ReactiveBlock = Array<ReactiveStatement>;
61
62
-export type ReactiveValueBlock = {
63
- kind: "value-block";
64
- instructions: ReactiveBlock;
65
- last: {
66
- value: Place;
67
- id: InstructionId;
68
- } | null;
69
-};
70
-
62
export type ReactiveStatement =
63
| ReactiveInstructionStatement
64
| ReactiveTerminalStatement
compiler/forget/src/ReactiveScopes/AlignReactiveScopesToBlockScopes.ts
-6
@@ -12,7 +12,6 @@ import {
12
ReactiveBlock,
13
ReactiveFunction,
14
ReactiveScope,
15
- ReactiveValueBlock,
15
ScopeId,
16
} from "../HIR/HIR";
17
import { getPlaceScope } from "./BuildReactiveBlocks";
@@ -90,11 +89,6 @@ class Visitor extends ReactiveFunctionVisitor<Context> {
89
this.traverseBlock(block, state);
90
}, "block");
91
}
93
- override visitValueBlock(block: ReactiveValueBlock, state: Context): void {
94
- state.enter(() => {
95
- super.visitValueBlock(block, state);
96
- }, "value");
97
- }
92
}
93
94
type PendingReactiveScope = { active: boolean; scope: ReactiveScope };
compiler/forget/src/ReactiveScopes/BuildReactiveBlocks.ts
+1
-34
@@ -16,15 +16,10 @@ import {
16
ReactiveScope,
17
ReactiveScopeBlock,
18
ReactiveStatement,
19
- ReactiveValueBlock,
19
ScopeId,
20
} from "../HIR";
21
import { assertExhaustive } from "../Utils/utils";
23
-import {
24
- eachReactiveValueOperand,
25
- eachTerminalBlock,
26
- mapTerminalBlocks,
27
-} from "./visitors";
22
+import { eachReactiveValueOperand, mapTerminalBlocks } from "./visitors";
23
24
/**
25
* 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 {
159
visitBlock(context, block);
160
});
161
});
167
- eachTerminalBlock(
168
- stmt.terminal,
169
- (_) => {},
170
- (valueBlock) => {
171
- visitValueBlock(context, valueBlock);
172
- }
173
- );
162
context.append(stmt, stmt.label);
163
break;
164
}
@@ -190,27 +178,6 @@ function visitBlock(context: Context, block: ReactiveBlock): void {
178
}
179
}
180
193
-function visitValueBlock(context: Context, block: ReactiveValueBlock): void {
194
- for (const stmt of block.instructions) {
195
- switch (stmt.kind) {
196
- case "instruction": {
197
- context.visitId(stmt.instruction.id);
198
- const scope = getInstructionScope(stmt.instruction);
199
- if (scope !== null) {
200
- context.visitScope(scope);
201
- }
202
- break;
203
- }
204
- default: {
205
- invariant(false, "Unexpected terminal or scope in value block");
206
- }
207
- }
208
- }
209
- if (block.last !== null) {
210
- context.visitId(block.last.id);
211
- }
212
-}
213
-
181
export function getInstructionScope({
182
id,
183
lvalue,
compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts
+15
-53
@@ -12,10 +12,8 @@ import {
12
GotoVariant,
13
HIR,
14
InstructionId,
15
- InstructionValue,
15
Place,
16
ReactiveBlock,
18
- ReactiveValueBlock,
17
SourceLocation,
18
} from "../HIR";
19
import {
@@ -253,7 +251,7 @@ class Driver {
251
);
252
scheduleIds.push(scheduleId);
253
256
- const testValue = this.visitValueBlockNew(
254
+ const testValue = this.visitValueBlock(
255
terminal.test,
256
terminal.loc
257
).value;
@@ -307,7 +305,7 @@ class Driver {
305
);
306
scheduleIds.push(scheduleId);
307
310
- const init = this.visitValueBlockNew(terminal.init, terminal.loc);
308
+ const init = this.visitValueBlock(terminal.init, terminal.loc);
309
const initBlock = this.cx.ir.blocks.get(init.block)!;
310
let initValue = init.value;
311
if (initValue.kind === "SequenceExpression") {
@@ -331,12 +329,12 @@ class Driver {
329
};
330
}
331
334
- const testValue = this.visitValueBlockNew(
332
+ const testValue = this.visitValueBlock(
333
terminal.test,
334
terminal.loc
335
).value;
336
339
- const updateValue = this.visitValueBlockNew(
337
+ const updateValue = this.visitValueBlock(
338
terminal.update,
339
terminal.loc
340
).value;
@@ -420,7 +418,7 @@ class Driver {
418
const scheduleId = this.cx.schedule(fallthroughId, "if");
419
scheduleIds.push(scheduleId);
420
423
- const { place, value } = this.visitValueTerminal(terminal);
421
+ const { place, value } = this.visitValueBlockTerminal(terminal);
422
blockValue.push({
423
kind: "instruction",
424
instruction: {
@@ -469,7 +467,7 @@ class Driver {
467
}
468
}
469
472
- visitValueBlockNew(
470
+ visitValueBlock(
471
id: BlockId,
472
loc: SourceLocation
473
): { block: BlockId; value: ReactiveValue; place: Place } {
@@ -483,7 +481,7 @@ class Driver {
481
) {
482
block = defaultBlock;
483
} else {
486
- const result = this.visitValueTerminal(defaultBlock.terminal);
484
+ const result = this.visitValueBlockTerminal(defaultBlock.terminal);
485
block = this.cx.ir.blocks.get(result.fallthrough)!;
486
place = result.place;
487
value = result.value;
@@ -531,7 +529,7 @@ class Driver {
529
}
530
}
531
534
- visitValueTerminal(terminal: Terminal): {
532
+ visitValueBlockTerminal(terminal: Terminal): {
533
value: ReactiveValue;
534
place: Place;
535
fallthrough: BlockId;
@@ -545,7 +543,9 @@ class Driver {
543
if (defaultTestBlock.terminal.kind === "branch") {
544
testBlock = defaultTestBlock;
545
} else {
548
- const leftResult = this.visitValueTerminal(defaultTestBlock.terminal);
546
+ const leftResult = this.visitValueBlockTerminal(
547
+ defaultTestBlock.terminal
548
+ );
549
testBlock = this.cx.ir.blocks.get(leftResult.fallthrough)!;
550
leftPlace = leftResult.place;
551
leftValue = leftResult.value;
@@ -583,7 +583,7 @@ class Driver {
583
};
584
left = sequence;
585
}
586
- const right = this.visitValueBlockNew(
586
+ const right = this.visitValueBlock(
587
testBlock.terminal.alternate,
588
terminal.loc
589
);
@@ -605,18 +605,18 @@ class Driver {
605
};
606
}
607
case "ternary": {
608
- const test = this.visitValueBlockNew(terminal.test, terminal.loc);
608
+ const test = this.visitValueBlock(terminal.test, terminal.loc);
609
const testBlock = this.cx.ir.blocks.get(test.block)!;
610
invariant(
611
testBlock.terminal.kind === "branch",
612
"Unexpected terminal kind '%s' for ternary test block",
613
testBlock.terminal.kind
614
);
615
- const consequent = this.visitValueBlockNew(
615
+ const consequent = this.visitValueBlock(
616
testBlock.terminal.consequent,
617
terminal.loc
618
);
619
- const alternate = this.visitValueBlockNew(
619
+ const alternate = this.visitValueBlock(
620
testBlock.terminal.alternate,
621
terminal.loc
622
);
@@ -647,44 +647,6 @@ class Driver {
647
}
648
}
649
650
- visitInitBlock(parent: ReactiveBlock, block: BasicBlock): ReactiveValueBlock {
651
- const initBlock: ReactiveValueBlock = {
652
- kind: "value-block",
653
- instructions: [],
654
- last: null,
655
- };
656
- for (const instruction of block.instructions) {
657
- initBlock.instructions.push({
658
- kind: "instruction",
659
- instruction,
660
- });
661
- }
662
- return initBlock;
663
- }
664
-
665
- visitValueBlock(
666
- parent: ReactiveBlock,
667
- block: BasicBlock,
668
- terminalValue?: { value: Place; id: InstructionId }
669
- ): ReactiveValueBlock {
670
- const valueBlock: ReactiveValueBlock = {
671
- kind: "value-block",
672
- instructions: [],
673
- last: terminalValue ?? null,
674
- };
675
- let lastValue: { value: InstructionValue; id: InstructionId } | null = null;
676
- if (terminalValue != null) {
677
- lastValue = terminalValue;
678
- }
679
- for (const instruction of block.instructions) {
680
- valueBlock.instructions.push({
681
- kind: "instruction",
682
- instruction,
683
- });
684
- }
685
- return valueBlock;
686
- }
687
-
650
emptyBlock(): ReactiveBlock {
651
return [];
652
}
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
-28
@@ -22,7 +22,6 @@ import {
22
ReactiveScopeDependency,
23
ReactiveTerminal,
24
ReactiveValue,
25
- ReactiveValueBlock,
25
SourceLocation,
26
} from "../HIR/HIR";
27
import { todoInvariant } from "../Utils/todo";
@@ -361,33 +360,6 @@ function codegenForInit(
360
}
361
}
362
364
-function codegenValueBlock(
365
- cx: Context,
366
- block: ReactiveValueBlock
367
-): t.Expression {
368
- const body = codegenBlock(cx, block.instructions).body;
369
- const expressions = body.map((stmt) => {
370
- if (stmt.type === "ExpressionStatement") {
371
- return stmt.expression;
372
- } else {
373
- todoInvariant(false, `Handle conversion of ${stmt.type} to expression`);
374
- }
375
- });
376
- if (block.last !== null) {
377
- const value = codegenInstructionValue(cx, block.last.value);
378
- expressions.push(value);
379
- }
380
- invariant(
381
- expressions.length !== 0,
382
- "Expected a value block to produce one or more expressions"
383
- );
384
- if (expressions.length === 1) {
385
- return expressions[0];
386
- } else {
387
- return t.sequenceExpression(expressions);
388
- }
389
-}
390
-
363
function codegenDependency(
364
cx: Context,
365
dependency: ReactiveScopeDependency
compiler/forget/src/ReactiveScopes/PrintReactiveFunction.ts
-12
@@ -13,7 +13,6 @@ import {
13
ReactiveStatement,
14
ReactiveTerminal,
15
ReactiveValue,
16
- ReactiveValueBlock,
16
} from "../HIR/HIR";
17
import {
18
printIdentifier,
@@ -111,17 +110,6 @@ function printReactiveInstruction(
110
}
111
}
112
114
-function printValueBlock(writer: Writer, block: ReactiveValueBlock): void {
115
- writer.indented(() => {
116
- for (const instr of block.instructions) {
117
- printReactiveInstruction(writer, instr);
118
- }
119
- if (block.last !== null) {
120
- writer.writeLine(printInstructionValue(block.last.value));
121
- }
122
- });
123
-}
124
-
113
function printReactiveValue(writer: Writer, value: ReactiveValue): void {
114
switch (value.kind) {
115
case "ConditionalExpression": {
compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts
-12
@@ -19,7 +19,6 @@ import {
19
ReactiveScope,
20
ReactiveScopeDependency,
21
ReactiveValue,
22
- ReactiveValueBlock,
22
} from "../HIR/HIR";
23
import { eachInstructionValueOperand } from "../HIR/visitors";
24
import { assertExhaustive } from "../Utils/utils";
@@ -274,17 +273,6 @@ function visit(context: Context, block: ReactiveBlock): void {
273
}
274
}
275
277
-function visitValueBlock(context: Context, block: ReactiveValueBlock): void {
278
- for (const initItem of block.instructions) {
279
- if (initItem.kind === "instruction") {
280
- visitInstruction(context, initItem.instruction);
281
- }
282
- }
283
- if (block.last !== null) {
284
- visitInstructionValue(context, block.last.value, null);
285
- }
286
-}
287
-
276
function visitReactiveValue(context: Context, value: ReactiveValue): void {
277
switch (value.kind) {
278
case "LogicalExpression": {
compiler/forget/src/ReactiveScopes/visitors.ts
-171
@@ -7,18 +7,15 @@
7
8
import {
9
InstructionId,
10
- InstructionValue,
10
LValue,
11
Place,
12
ReactiveBlock,
13
ReactiveFunction,
14
ReactiveInstruction,
16
- ReactiveScope,
15
ReactiveScopeBlock,
16
ReactiveTerminal,
17
ReactiveTerminalStatement,
18
ReactiveValue,
21
- ReactiveValueBlock,
19
} from "../HIR/HIR";
20
import { eachInstructionValueOperand } from "../HIR/visitors";
21
import { assertExhaustive } from "../Utils/utils";
@@ -142,14 +139,6 @@ export class ReactiveFunctionVisitor<TState = void> {
139
}
140
}
141
145
- visitValueBlock(block: ReactiveValueBlock, state: TState): void {
146
- // NOTE: intentionally bypass calling visitBlock
147
- this.traverseBlock(block.instructions, state);
148
- if (block.last !== null) {
149
- this.visitPlace(block.last.id, block.last.value, state);
150
- }
151
- }
152
-
142
visitScope(scope: ReactiveScopeBlock, state: TState): void {
143
this.traverseScope(scope, state);
144
}
@@ -186,69 +175,6 @@ export class ReactiveFunctionVisitor<TState = void> {
175
}
176
}
177
189
-export function visitFunction(
190
- fn: ReactiveFunction,
191
- visitors: {
192
- visitValue?: (value: InstructionValue) => void;
193
- visitInstruction?: (instr: ReactiveInstruction) => void;
194
- visitTerminal?: (terminal: ReactiveTerminal) => void;
195
- visitScope?: (scope: ReactiveScope) => void;
196
- }
197
-): void {
198
- const { visitValue, visitInstruction, visitTerminal, visitScope } = visitors;
199
- function visitBlock(block: ReactiveBlock): void {
200
- for (const item of block) {
201
- switch (item.kind) {
202
- case "instruction": {
203
- if (visitValue) {
204
- for (const operand of eachReactiveValueOperand(
205
- item.instruction.value
206
- )) {
207
- visitValue(operand);
208
- }
209
- }
210
- if (visitInstruction) {
211
- visitInstruction(item.instruction);
212
- }
213
- break;
214
- }
215
- case "terminal": {
216
- if (visitValue) {
217
- eachTerminalOperand(item.terminal, (operand) => {
218
- visitValue(operand);
219
- });
220
- }
221
- if (visitTerminal) {
222
- visitTerminal(item.terminal);
223
- }
224
- eachTerminalBlock(item.terminal, visitBlock, visitValueBlock);
225
- break;
226
- }
227
- case "scope": {
228
- if (visitScope) {
229
- visitScope(item.scope);
230
- }
231
- visitBlock(item.instructions);
232
- break;
233
- }
234
- default: {
235
- assertExhaustive(
236
- item,
237
- `Unexpected item kind '${(item as any).kind}'`
238
- );
239
- }
240
- }
241
- }
242
- }
243
- function visitValueBlock(block: ReactiveValueBlock): void {
244
- visitBlock(block.instructions);
245
- if (block.last !== null && visitValue) {
246
- visitValue(block.last.value);
247
- }
248
- }
249
- visitBlock(fn.body);
250
-}
251
-
178
export function* eachReactiveValueOperand(
179
instrValue: ReactiveValue
180
): Iterable<Place> {
@@ -319,100 +245,3 @@ export function mapTerminalBlocks(
245
}
246
}
247
}
322
-
323
-export function eachTerminalBlock(
324
- terminal: ReactiveTerminal,
325
- visitBlock: (block: ReactiveBlock) => void,
326
- visitValueBlock: (block: ReactiveValueBlock) => void
327
-): void {
328
- switch (terminal.kind) {
329
- case "break":
330
- case "continue":
331
- case "return":
332
- case "throw": {
333
- break;
334
- }
335
- case "for": {
336
- // TODO
337
- // visitValueBlock(terminal.init);
338
- // visitValueBlock(terminal.test);
339
- // visitValueBlock(terminal.update);
340
- visitBlock(terminal.loop);
341
- break;
342
- }
343
- case "while": {
344
- // TODO
345
- // visitValueBlock(terminal.test);
346
- visitBlock(terminal.loop);
347
- break;
348
- }
349
- case "if": {
350
- visitBlock(terminal.consequent);
351
- if (terminal.alternate !== null) {
352
- visitBlock(terminal.alternate);
353
- }
354
- break;
355
- }
356
- case "switch": {
357
- for (const case_ of terminal.cases) {
358
- if (case_.block !== undefined) {
359
- visitBlock(case_.block);
360
- }
361
- }
362
- break;
363
- }
364
- default: {
365
- assertExhaustive(
366
- terminal,
367
- `Unexpected terminal kind '${(terminal as any).kind}'`
368
- );
369
- }
370
- }
371
-}
372
-
373
-export function eachTerminalOperand(
374
- terminal: ReactiveTerminal,
375
- fn: (place: Place) => void
376
-): void {
377
- switch (terminal.kind) {
378
- case "break":
379
- case "continue": {
380
- break;
381
- }
382
- case "return": {
383
- if (terminal.value !== null) {
384
- fn(terminal.value);
385
- }
386
- break;
387
- }
388
- case "throw": {
389
- fn(terminal.value);
390
- break;
391
- }
392
- case "for": {
393
- break;
394
- }
395
- case "while": {
396
- break;
397
- }
398
- case "if": {
399
- fn(terminal.test);
400
- break;
401
- }
402
- case "switch": {
403
- fn(terminal.test);
404
- for (const case_ of terminal.cases) {
405
- if (case_.test !== null) {
406
- fn(case_.test);
407
- }
408
- }
409
- break;
410
- }
411
- default: {
412
- assertExhaustive(
413
- terminal,
414
- `Unexpected terminal kind '${(terminal as any).kind}'`
415
- );
416
- }
417
- }
418
-}