@samitouri / QOS-React / commits / 63fd00ab27

[hir] Remove unreachable fallthroughs after merging blocks

Fixes https://github.com/facebook/react-forget/issues/1141

Sathya Gunasekaran committed Mar 3, 2023 at 14:08 UTC 63fd00ab2773b0e92217b0df4452e002ead3e901
3 files changed +38
compiler/forget/src/HIR/MergeConsecutiveBlocks.ts
+2
@@ -13,6 +13,7 @@ import {
13 HIRFunction,
14 Instruction,
15 } from "./HIR";
16 +import { removeUnreachableFallthroughs } from "./HIRBuilder";
17
18 /**
19 * Merges sequences of blocks that will always execute consecutively —
@@ -84,6 +85,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
85 merged.merge(block.id, predecessorId);
86 fn.body.blocks.delete(block.id);
87 }
88 + removeUnreachableFallthroughs(fn.body);
89 }
90
91 class MergedBlocks {
compiler/forget/src/__tests__/fixtures/hir/early-return.expect.md new
+28
@@ -0,0 +1,28 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function MyApp(props) {
6 + let res;
7 + if (props.cond) {
8 + return;
9 + } else {
10 + res = 1;
11 + }
12 +}
13 +
14 +```
15 +
16 +## Code
17 +
18 +```javascript
19 +function MyApp(props) {
20 + if (props.cond) {
21 + return;
22 + } else {
23 + return;
24 + }
25 +}
26 +
27 +```
28 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/early-return.js new
+8
@@ -0,0 +1,8 @@
1 +function MyApp(props) {
2 + let res;
3 + if (props.cond) {
4 + return;
5 + } else {
6 + res = 1;
7 + }
8 +}