diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index 23eb0885fd..0b00e12ed9 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -13,6 +13,7 @@ import { Err, Ok, Result } from "../lib/Result"; import { assertExhaustive } from "../Utils/utils"; import { BlockId, + BranchTerminal, Case, Effect, GeneratedSource, @@ -411,14 +412,13 @@ function lowerStatement( } else { builder.terminateWithContinuation( { - kind: "if", + kind: "branch", test: lowerExpressionToPlace( builder, test as NodePath ), consequent: bodyBlock, alternate: continuationBlock.id, - fallthrough: continuationBlock.id, id: makeInstructionId(0), }, continuationBlock @@ -489,37 +489,28 @@ function lowerStatement( * The code leading up to the loop must jump to the conditional block, * to evaluate whether to enter the loop or bypass to the continuation. */ - const loc = stmt.node.loc; - if (loc == null) { - builder.pushError({ - reason: `(BuildHIR::lowerStatement) Expected WhileStatement to have a location, got ${loc}`, - severity: ErrorSeverity.InvalidInput, - nodePath: stmt, - }); - } else { - builder.terminateWithContinuation( - { - kind: "while", - loc, - test: conditionalBlock.id, - loop: loopBlock, - fallthrough: continuationBlock.id, - id: makeInstructionId(0), - }, - conditionalBlock - ); - } + const loc = stmt.node.loc ?? GeneratedSource; + builder.terminateWithContinuation( + { + kind: "while", + loc, + test: conditionalBlock.id, + loop: loopBlock, + fallthrough: continuationBlock.id, + id: makeInstructionId(0), + }, + conditionalBlock + ); /** * The conditional block is empty and exists solely as conditional for * (re)entering or exiting the loop */ const test = lowerExpressionToPlace(builder, stmt.get("test")); - const terminal: IfTerminal = { - kind: "if", + const terminal: BranchTerminal = { + kind: "branch", test, consequent: loopBlock, alternate: continuationBlock.id, - fallthrough: continuationBlock.id, id: makeInstructionId(0), }; // Complete the conditional and continue with code after the loop diff --git a/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts b/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts index f3741fc73f..77bb7ebab6 100644 --- a/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts +++ b/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts @@ -247,7 +247,7 @@ class Driver { const testBlock = this.cx.ir.blocks.get(terminal.test)!; const testTerminal = testBlock.terminal; invariant( - testTerminal.kind === "if", + testTerminal.kind === "branch", "Expected while loop test block to end in an if" ); const testValue = this.visitValueBlock(blockValue, testBlock, { @@ -314,7 +314,7 @@ class Driver { const testBlock = this.cx.ir.blocks.get(terminal.test)!; const testTerminal = testBlock.terminal; invariant( - testTerminal.kind === "if", + testTerminal.kind === "branch", "Expected for loop test block to end in an if" ); const testValue = this.visitValueBlock(blockValue, testBlock, {