Cleanup from non-nullable return value
Now that ReturnTerminal.value is non-nullable we can make ReactiveReturnTerminal.value also non-nullable, and remove a bunch of null checks.
Joe Savona committed
Apr 18, 2023 at 11:12 UTC
b10f60f2b93466f289d38f8723d40452e8c3ef67
7 files changed
+9
-24
compiler/forget/src/HIR/HIR.ts
+1
-1
@@ -152,7 +152,7 @@ export type ReactiveContinueTerminal = {
152
};
153
export type ReactiveReturnTerminal = {
154
kind: "return";
155
- value: Place | null;
155
+ value: Place;
156
id: InstructionId;
157
};
158
export type ReactiveThrowTerminal = {
compiler/forget/src/HIR/visitors.ts
+2
-6
@@ -782,9 +782,7 @@ export function mapTerminalOperands(
782
}
783
case "return":
784
case "throw": {
785
- if (terminal.value !== null) {
786
- terminal.value = fn(terminal.value);
787
- }
785
+ terminal.value = fn(terminal.value);
786
break;
787
}
788
case "label":
@@ -831,9 +829,7 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
829
}
830
case "return":
831
case "throw": {
834
- if (terminal.value !== null) {
835
- yield terminal.value;
836
- }
832
+ yield terminal.value;
833
break;
834
}
835
case "label":
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2
-3
@@ -387,9 +387,8 @@ function codegenTerminal(
387
);
388
}
389
case "return": {
390
- return t.returnStatement(
391
- terminal.value !== null ? codegenPlace(cx, terminal.value) : null
392
- );
390
+ const value = codegenPlace(cx, terminal.value);
391
+ return t.returnStatement(value);
392
}
393
case "switch": {
394
return t.switchStatement(
compiler/forget/src/ReactiveScopes/PrintReactiveFunction.ts
+1
-7
@@ -249,13 +249,7 @@ function printTerminal(writer: Writer, terminal: ReactiveTerminal): void {
249
break;
250
}
251
case "return": {
252
- if (terminal.value !== null) {
253
- writer.writeLine(
254
- `[${terminal.id}] return ${printPlace(terminal.value)}`
255
- );
256
- } else {
257
- writer.writeLine(`[${terminal.id}] return`);
258
- }
252
+ writer.writeLine(`[${terminal.id}] return ${printPlace(terminal.value)}`);
253
break;
254
}
255
case "label": {
compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts
+1
-3
@@ -361,9 +361,7 @@ function visit(context: Context, block: ReactiveBlock): void {
361
break;
362
}
363
case "return": {
364
- if (terminal.value !== null) {
365
- context.visitOperand(terminal.value);
366
- }
364
+ context.visitOperand(terminal.value);
365
break;
366
}
367
case "throw": {
compiler/forget/src/ReactiveScopes/PruneNonEscapingScopes.ts
+1
-1
@@ -673,7 +673,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<State> {
673
): void {
674
this.traverseTerminal(stmt, state);
675
676
- if (stmt.terminal.kind === "return" && stmt.terminal.value !== null) {
676
+ if (stmt.terminal.kind === "return") {
677
state.escapingValues.add(stmt.terminal.value.identifier.id);
678
}
679
}
compiler/forget/src/ReactiveScopes/visitors.ts
+1
-3
@@ -96,9 +96,7 @@ export class ReactiveFunctionVisitor<TState = void> {
96
break;
97
}
98
case "return": {
99
- if (terminal.value !== null) {
100
- this.visitPlace(terminal.id, terminal.value, state);
101
- }
99
+ this.visitPlace(terminal.id, terminal.value, state);
100
break;
101
}
102
case "throw": {