@samitouri / QOS-React-2 / commits / 1a3e269274

Rename InstructionValue.OtherStatement to UnsupportedNode

As discussed, this repurposes OtherStatement as a catch all variant for unsupported syntax or errors in the source. This also renames the previously added ErrorTerminal to UnsupportedTerminal for consistency (plus makes it a little bit less confusing that it's not an actual terminal representing an Error). Not loving the name but couldn't think of anything better, open to suggestions!

Lauren Tan committed Jan 20, 2023 at 11:47 UTC 1a3e269274ac941ad05fb9d0364c2320e98ec89b
10 files changed +29 -33
compiler/forget/src/HIR/BuildHIR.ts
+6 -6
@@ -336,7 +336,7 @@ function lowerStatement(
336 severity: ErrorSeverity.Todo,
337 nodePath: stmt,
338 });
339 - return { kind: "error", id: makeInstructionId(0) };
339 + return { kind: "unsupported", id: makeInstructionId(0) };
340 }
341 lowerStatement(builder, init);
342 return {
@@ -355,7 +355,7 @@ function lowerStatement(
355 severity: ErrorSeverity.Todo,
356 nodePath: stmt,
357 });
358 - return { kind: "error", id: makeInstructionId(0) };
358 + return { kind: "unsupported", id: makeInstructionId(0) };
359 }
360 lowerExpressionToVoid(builder, update);
361 return {
@@ -758,7 +758,7 @@ function lowerStatement(
758 },
759 loc: stmtPath.node.loc ?? GeneratedSource,
760 value: {
761 - kind: "OtherStatement",
761 + kind: "UnsupportedNode",
762 loc: stmtPath.node.loc ?? GeneratedSource,
763 node: stmtPath.node,
764 },
@@ -1221,8 +1221,8 @@ function lowerExpression(
1221 if (lowering.isErr()) {
1222 lowering.unwrapErr().forEach((e) => builder.pushError(e));
1223 return {
1224 - kind: "OtherStatement",
1225 - node: expr.node,
1224 + kind: "UnsupportedNode",
1225 + node: exprNode,
1226 loc: exprLoc,
1227 };
1228 }
@@ -1413,7 +1413,7 @@ function lowerJsxElement(
1413 builder.push({
1414 id: makeInstructionId(0),
1415 value: {
1416 - kind: "OtherStatement",
1416 + kind: "UnsupportedNode",
1417 node: exprNode,
1418 loc: exprLoc,
1419 },
compiler/forget/src/HIR/HIR.ts
+4 -8
@@ -209,7 +209,7 @@ export type BasicBlock = {
209 * for-of, if-else, return, etc.
210 */
211 export type Terminal =
212 - | ErrorTerminal
212 + | UnsupportedTerminal
213 | ThrowTerminal
214 | ReturnTerminal
215 | GotoTerminal
@@ -224,7 +224,7 @@ export type Terminal =
224 */
225 export type ValueTerminal = IfTerminal | GotoTerminal;
226 // A terminal that couldn't be lowered correctly.
227 -export type ErrorTerminal = { kind: "error"; id: InstructionId };
227 +export type UnsupportedTerminal = { kind: "unsupported"; id: InstructionId };
228 export type ThrowTerminal = { kind: "throw"; value: Place; id: InstructionId };
229 export type Case = { test: Place | null; block: BlockId };
230
@@ -416,12 +416,8 @@ export type InstructionData =
416 * passing through in codegen.
417 */
418 | {
419 - kind: "OtherStatement";
420 - node:
421 - | t.Statement
422 - | t.JSXSpreadChild
423 - | t.JSXFragment
424 - | t.FunctionExpression;
419 + kind: "UnsupportedNode";
420 + node: t.Node;
421 };
422
423 /**
compiler/forget/src/HIR/HIRBuilder.ts
+1 -1
@@ -574,7 +574,7 @@ export function reversePostorderBlocks(func: HIR): void {
574 visit(terminal.init);
575 break;
576 }
577 - case "error": {
577 + case "unsupported": {
578 break;
579 }
580 default: {
compiler/forget/src/HIR/PrintHIR.ts
+5 -5
@@ -82,7 +82,7 @@ export function printMixedHIR(
82 case "throw":
83 case "while":
84 case "for":
85 - case "error":
85 + case "unsupported":
86 case "goto": {
87 const terminal = printTerminal(value);
88 if (Array.isArray(terminal)) {
@@ -180,8 +180,8 @@ export function printTerminal(terminal: Terminal): Array<string> | string {
180 value = `[${terminal.id}] For init=bb${terminal.init} test=bb${terminal.test} loop=bb${terminal.loop} update=bb${terminal.update} fallthrough=bb${terminal.fallthrough}`;
181 break;
182 }
183 - case "error": {
184 - value = `Error`;
183 + case "unsupported": {
184 + value = `Unsupported`;
185 break;
186 }
187 default: {
@@ -278,8 +278,8 @@ export function printInstructionValue(instrValue: InstructionValue): string {
278 .join(", ")})`;
279 break;
280 }
281 - case "OtherStatement": {
282 - value = `OtherStatement(${generate(instrValue.node).code})`;
281 + case "UnsupportedNode": {
282 + value = `UnsupportedNode(${generate(instrValue.node).code})`;
283 break;
284 }
285 case "Identifier": {
compiler/forget/src/HIR/visitors.ts
+6 -6
@@ -102,7 +102,7 @@ export function* eachInstructionValueOperand(
102 yield* instrValue.dependencies;
103 break;
104 }
105 - case "OtherStatement":
105 + case "UnsupportedNode":
106 case "Primitive":
107 case "JSXText": {
108 break;
@@ -203,7 +203,7 @@ export function mapInstructionOperands(
203 instrValue.dependencies = instrValue.dependencies.map((d) => fn(d));
204 break;
205 }
206 - case "OtherStatement":
206 + case "UnsupportedNode":
207 case "Primitive":
208 case "JSXText": {
209 break;
@@ -314,7 +314,7 @@ export function mapTerminalSuccessors(
314 id: makeInstructionId(0),
315 };
316 }
317 - case "error": {
317 + case "unsupported": {
318 return terminal;
319 }
320 default: {
@@ -366,7 +366,7 @@ export function* eachTerminalSuccessor(terminal: Terminal): Iterable<BlockId> {
366 yield terminal.init;
367 break;
368 }
369 - case "error":
369 + case "unsupported":
370 break;
371 default: {
372 assertExhaustive(
@@ -407,7 +407,7 @@ export function mapTerminalOperands(
407 case "while":
408 case "for":
409 case "goto":
410 - case "error": {
410 + case "unsupported": {
411 // no-op
412 break;
413 }
@@ -447,7 +447,7 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
447 case "while":
448 case "for":
449 case "goto":
450 - case "error": {
450 + case "unsupported": {
451 // no-op
452 break;
453 }
compiler/forget/src/Inference/InferReferenceEffects.ts
+1 -1
@@ -564,7 +564,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
564 effectKind = Effect.Read;
565 break;
566 }
567 - case "OtherStatement": {
567 + case "UnsupportedNode": {
568 // TODO: handle other statement kinds
569 valueKind = ValueKind.Mutable;
570 break;
compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts
+2 -2
@@ -388,8 +388,8 @@ class Driver {
388 }
389 break;
390 }
391 - case "error": {
392 - invariant(false, "Unexpected error terminal");
391 + case "unsupported": {
392 + invariant(false, "Unexpected unsupported terminal");
393 }
394 default: {
395 assertExhaustive(terminal, "Unexpected terminal");
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+1 -1
@@ -608,7 +608,7 @@ function codegenInstructionValue(
608 );
609 break;
610 }
611 - case "OtherStatement": {
611 + case "UnsupportedNode": {
612 const node = instrValue.node;
613 if (!t.isExpression(node)) {
614 return node as any; // TODO handle statements, jsx fragments
compiler/forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+1 -1
@@ -185,7 +185,7 @@ function mayAllocate(value: InstructionValue): boolean {
185 case "JsxFragment":
186 case "NewExpression":
187 case "ObjectExpression":
188 - case "OtherStatement":
188 + case "UnsupportedNode":
189 case "FunctionExpression":
190 case "UnaryExpression": {
191 return true;
compiler/forget/src/Utils/VisualizeHIRMermaid.ts
+2 -2
@@ -105,7 +105,7 @@ function printTerminalLabel(terminal: Terminal): string {
105 case "for":
106 buffer.push("For");
107 break;
108 - case "error": {
108 + case "unsupported": {
109 break;
110 }
111 default:
@@ -172,7 +172,7 @@ function printTerminalArrows(blockId: BlockId, terminal: Terminal): string {
172 }
173 case "throw":
174 case "return":
175 - case "error": {
175 + case "unsupported": {
176 break;
177 }
178 default: