@samitouri / QOS-React-2 / commits / a1902b263d

Rename OptionalCall -> Optional for clarity

The previous OptionalCall terminal and reactive value kinds are now used not just for optional calls, but for optional member expressions that appear within an optional call. This PR renames those data types to OptionalTerminal and OptionalExpression for clarity.

Joe Savona committed May 2, 2023 at 16:31 UTC a1902b263d838fb6541837441fd8020ce23f2582
14 files changed +46 -45
compiler/forget/src/HIR/BuildHIR.ts
+2 -2
@@ -1815,7 +1815,7 @@ function lowerOptionalMemberExpression(
1815
1816 builder.terminateWithContinuation(
1817 {
1818 - kind: "optional-call",
1818 + kind: "optional",
1819 optional,
1820 test: testBlock,
1821 fallthrough: continuationBlock.id,
@@ -1966,7 +1966,7 @@ function lowerOptionalCallExpression(
1966
1967 builder.terminateWithContinuation(
1968 {
1969 - kind: "optional-call",
1969 + kind: "optional",
1970 optional,
1971 test: testBlock,
1972 fallthrough: continuationBlock.id,
compiler/forget/src/HIR/HIR.ts
+9 -8
@@ -118,9 +118,9 @@ export type ReactiveSequenceValue = {
118 };
119
120 export type ReactiveOptionalCallValue = {
121 - kind: "OptionalCall";
121 + kind: "OptionalExpression";
122 id: InstructionId;
123 - call: ReactiveValue;
123 + value: ReactiveValue;
124 optional: boolean;
125 loc: SourceLocation;
126 };
@@ -275,7 +275,7 @@ export type Terminal =
275 | WhileTerminal
276 | LogicalTerminal
277 | TernaryTerminal
278 - | OptionalCallTerminal
278 + | OptionalTerminal
279 | LabelTerminal;
280
281 function _staticInvariantTerminalHasLocation(
@@ -421,11 +421,12 @@ export type LabelTerminal = {
421 loc: SourceLocation;
422 };
423
424 -export type OptionalCallTerminal = {
425 - kind: "optional-call";
426 - // Whether the call itself is optional. If false, this means that the callee itself
427 - // is optionally evaluated (has some OptionalMemberExpresion) but the final call is
428 - // required (if the callee is not null/undefined).
424 +export type OptionalTerminal = {
425 + kind: "optional";
426 + // Specifies whether this node was optional. If false, it means that the original
427 + // node was part of an optional chain but this specific item was non-optional.
428 + // For example, in `a?.b.c?.()`, the `.b` access is non-optional but appears within
429 + // an optional chain.
430 optional: boolean;
431 test: BlockId;
432 fallthrough: BlockId;
compiler/forget/src/HIR/HIRBuilder.ts
+1 -1
@@ -652,7 +652,7 @@ export function reversePostorderBlocks(func: HIR): void {
652 }
653 break;
654 }
655 - case "optional-call":
655 + case "optional":
656 case "ternary":
657 case "logical": {
658 visit(terminal.test);
compiler/forget/src/HIR/PrintHIR.ts
+5 -5
@@ -80,7 +80,7 @@ export function printMixedHIR(
80 }
81 switch (value.kind) {
82 case "label":
83 - case "optional-call":
83 + case "optional":
84 case "branch":
85 case "if":
86 case "logical":
@@ -158,8 +158,8 @@ export function printTerminal(terminal: Terminal): Array<string> | string {
158 value = `[${terminal.id}] Ternary test:bb${terminal.test} fallthrough=bb${terminal.fallthrough}`;
159 break;
160 }
161 - case "optional-call": {
162 - value = `[${terminal.id}] OptionalCall test:bb${terminal.test} fallthrough=bb${terminal.fallthrough}`;
161 + case "optional": {
162 + value = `[${terminal.id}] Optional test:bb${terminal.test} fallthrough=bb${terminal.fallthrough}`;
163 break;
164 }
165 case "throw": {
@@ -458,8 +458,8 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
458 value = `Global ${instrValue.name}`;
459 break;
460 }
461 - case "OptionalCall": {
462 - value = `OptionalCall ${printInstructionValue(instrValue.call)}`;
461 + case "OptionalExpression": {
462 + value = `OptionalExpression ${printInstructionValue(instrValue.value)}`;
463 break;
464 }
465 case "RegExpLiteral": {
compiler/forget/src/HIR/visitors.ts
+7 -7
@@ -598,11 +598,11 @@ export function mapTerminalSuccessors(
598 loc: terminal.loc,
599 };
600 }
601 - case "optional-call": {
601 + case "optional": {
602 const test = fn(terminal.test);
603 const fallthrough = fn(terminal.fallthrough);
604 return {
605 - kind: "optional-call",
605 + kind: "optional",
606 optional: terminal.optional,
607 test,
608 fallthrough,
@@ -721,7 +721,7 @@ export function terminalFallthrough(terminal: Terminal): BlockId | null {
721 case "if":
722 case "label":
723 case "logical":
724 - case "optional-call":
724 + case "optional":
725 case "switch":
726 case "ternary":
727 case "while": {
@@ -768,7 +768,7 @@ export function mapOptionalFallthroughs(
768 const _: BlockId = terminal.fallthrough;
769 break;
770 }
771 - case "optional-call": {
771 + case "optional": {
772 const _: BlockId = terminal.fallthrough;
773 break;
774 }
@@ -834,7 +834,7 @@ export function* eachTerminalSuccessor(terminal: Terminal): Iterable<BlockId> {
834 }
835 break;
836 }
837 - case "optional-call":
837 + case "optional":
838 case "ternary":
839 case "logical": {
840 yield terminal.test;
@@ -906,7 +906,7 @@ export function mapTerminalOperands(
906 break;
907 }
908 case "label":
909 - case "optional-call":
909 + case "optional":
910 case "ternary":
911 case "logical":
912 case "do-while":
@@ -953,7 +953,7 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
953 break;
954 }
955 case "label":
956 - case "optional-call":
956 + case "optional":
957 case "ternary":
958 case "logical":
959 case "do-while":
compiler/forget/src/Inference/InlineUseMemo.ts
+2 -2
@@ -171,7 +171,7 @@ export function inlineUseMemo(fn: HIRFunction): void {
171 }
172 // These all have non-nullable fallthroughs: there is always some code in the
173 // CFG that succeeds them which we should find instead
174 - case "optional-call":
174 + case "optional":
175 case "ternary":
176 case "logical":
177 case "while":
@@ -282,7 +282,7 @@ function getTerminalBlock(cfg: HIR, start: BlockId): BasicBlock {
282 return current;
283 }
284 }
285 - case "optional-call":
285 + case "optional":
286 case "ternary":
287 case "logical":
288 case "while":
compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts
+4 -4
@@ -560,7 +560,7 @@ class Driver {
560
561 break;
562 }
563 - case "optional-call":
563 + case "optional":
564 case "ternary":
565 case "logical": {
566 const fallthroughId = terminal.fallthrough;
@@ -756,7 +756,7 @@ class Driver {
756 id: InstructionId;
757 } {
758 switch (terminal.kind) {
759 - case "optional-call": {
759 + case "optional": {
760 const test = this.visitValueBlock(terminal.test, terminal.loc);
761 const testBlock = this.cx.ir.blocks.get(test.block)!;
762 invariant(
@@ -785,9 +785,9 @@ class Driver {
785 return {
786 place: { ...consequent.place },
787 value: {
788 - kind: "OptionalCall",
788 + kind: "OptionalExpression",
789 optional: terminal.optional,
790 - call: call,
790 + value: call,
791 id: terminal.id,
792 loc: terminal.loc,
793 },
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2 -2
@@ -684,8 +684,8 @@ function codegenInstructionValue(
684 value = createCallExpression(instrValue.loc, callee, args);
685 break;
686 }
687 - case "OptionalCall": {
688 - const optionalValue = codegenInstructionValue(cx, instrValue.call);
687 + case "OptionalExpression": {
688 + const optionalValue = codegenInstructionValue(cx, instrValue.value);
689 switch (optionalValue.type) {
690 case "OptionalCallExpression":
691 case "CallExpression": {
compiler/forget/src/ReactiveScopes/MergeOverlappingReactiveScopes.ts
+1 -1
@@ -125,7 +125,7 @@ class Visitor extends ReactiveFunctionVisitor<Context> {
125 if (
126 instruction.value.kind === "ConditionalExpression" ||
127 instruction.value.kind === "LogicalExpression" ||
128 - instruction.value.kind === "OptionalCall"
128 + instruction.value.kind === "OptionalExpression"
129 ) {
130 state.enter(() => {
131 super.visitInstruction(instruction, state);
compiler/forget/src/ReactiveScopes/PrintReactiveFunction.ts
+3 -3
@@ -151,11 +151,11 @@ function printReactiveValue(writer: Writer, value: ReactiveValue): void {
151 });
152 break;
153 }
154 - case "OptionalCall": {
155 - writer.append(`OptionalCall optional=${value.optional}`);
154 + case "OptionalExpression": {
155 + writer.append(`OptionalExpression optional=${value.optional}`);
156 writer.newline();
157 writer.indented(() => {
158 - printReactiveValue(writer, value.call);
158 + printReactiveValue(writer, value.value);
159 });
160 break;
161 }
compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts
+2 -2
@@ -450,9 +450,9 @@ class PropagationVisitor extends ReactiveFunctionVisitor<Context> {
450 value: ReactiveValue
451 ): void {
452 switch (value.kind) {
453 - case "OptionalCall": {
453 + case "OptionalExpression": {
454 context.enterConditional(() => {
455 - this.visitReactiveValue(context, id, value.call);
455 + this.visitReactiveValue(context, id, value.value);
456 });
457 break;
458 }
compiler/forget/src/ReactiveScopes/PruneNonEscapingScopes.ts
+1 -1
@@ -525,7 +525,7 @@ function computeMemoizationInputs(
525 rvalues: [value.value],
526 };
527 }
528 - case "OptionalCall":
528 + case "OptionalExpression":
529 case "RegExpLiteral":
530 case "FunctionExpression":
531 case "TaggedTemplateExpression":
compiler/forget/src/ReactiveScopes/visitors.ts
+4 -4
@@ -41,8 +41,8 @@ export class ReactiveFunctionVisitor<TState = void> {
41 }
42 traverseValue(id: InstructionId, value: ReactiveValue, state: TState): void {
43 switch (value.kind) {
44 - case "OptionalCall": {
45 - this.visitValue(id, value.call, state);
44 + case "OptionalExpression": {
45 + this.visitValue(id, value.value, state);
46 break;
47 }
48 case "LogicalExpression": {
@@ -290,8 +290,8 @@ export function* eachReactiveValueOperand(
290 instrValue: ReactiveValue
291 ): Iterable<Place> {
292 switch (instrValue.kind) {
293 - case "OptionalCall": {
294 - yield* eachReactiveValueOperand(instrValue.call);
293 + case "OptionalExpression": {
294 + yield* eachReactiveValueOperand(instrValue.value);
295 break;
296 }
297 case "LogicalExpression": {
compiler/forget/src/Utils/VisualizeHIRMermaid.ts
+3 -3
@@ -114,8 +114,8 @@ function printTerminalLabel(terminal: Terminal): string {
114 buffer.push("Ternary");
115 break;
116 }
117 - case "optional-call": {
118 - buffer.push("OptionalCall");
117 + case "optional": {
118 + buffer.push("Optional");
119 break;
120 }
121 case "do-while": {
@@ -175,7 +175,7 @@ function printTerminalArrows(blockId: BlockId, terminal: Terminal): string {
175 buffer.push(printJumpArrow(blockId, terminal.fallthrough, "fallthrough"));
176 break;
177 }
178 - case "optional-call": {
178 + case "optional": {
179 buffer.push(printJumpArrow(blockId, terminal.test, "test"));
180 buffer.push(printJumpArrow(blockId, terminal.fallthrough, "fallthrough"));
181 break;