[hir] Make return.value non nullable

This commit is contained in:
Sathya Gunasekaran
2023-04-17 21:11:44 +01:00
parent 42459f579f
commit 7c5e5eb30c
2 changed files with 24 additions and 26 deletions
+1 -1
View File
@@ -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;
};
+23 -25
View File
@@ -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,