From 7c5e5eb30c996a72d3fa45b4d2b8cd2c321c5e63 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Mon, 17 Apr 2023 21:11:44 +0100 Subject: [PATCH] [hir] Make return.value non nullable --- compiler/forget/src/HIR/HIR.ts | 2 +- .../forget/src/Inference/InlineUseMemo.ts | 48 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index 48845b7605..ef59058383 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -313,7 +313,7 @@ export type Case = { test: Place | null; block: BlockId }; export type ReturnTerminal = { kind: "return"; loc: SourceLocation; - value: Place | null; + value: Place; id: InstructionId; }; diff --git a/compiler/forget/src/Inference/InlineUseMemo.ts b/compiler/forget/src/Inference/InlineUseMemo.ts index 2ac3e7a242..ad0d78943d 100644 --- a/compiler/forget/src/Inference/InlineUseMemo.ts +++ b/compiler/forget/src/Inference/InlineUseMemo.ts @@ -332,33 +332,31 @@ function rewriteBlock( if (terminal.kind !== "return") { return; } - if (terminal.value !== null) { - block.instructions.push({ - id: makeInstructionId(0), - loc: terminal.loc, - lvalue: { - effect: Effect.Unknown, - identifier: { - id: env.nextIdentifierId, - mutableRange: { - start: makeInstructionId(0), - end: makeInstructionId(0), - }, - name: null, - scope: null, - type: makeType(), + block.instructions.push({ + id: makeInstructionId(0), + loc: terminal.loc, + lvalue: { + effect: Effect.Unknown, + identifier: { + id: env.nextIdentifierId, + mutableRange: { + start: makeInstructionId(0), + end: makeInstructionId(0), }, - kind: "Identifier", - loc: terminal.loc, + name: null, + scope: null, + type: makeType(), }, - value: { - kind: "StoreLocal", - lvalue: { kind: InstructionKind.Reassign, place: { ...returnValue } }, - value: terminal.value, - loc: terminal.loc, - }, - }); - } + kind: "Identifier", + loc: terminal.loc, + }, + value: { + kind: "StoreLocal", + lvalue: { kind: InstructionKind.Reassign, place: { ...returnValue } }, + value: terminal.value, + loc: terminal.loc, + }, + }); block.terminal = { kind: "goto", block: returnTarget,