@samitouri / QOS-React / commits / 1efb3cae0a

[HIR] Add new unreachable terminal

ghstack-source-id: cffdbbbd78a0aa7e1587a234ce27366ea626ee5e Pull Request resolved: https://github.com/facebook/react-forget/pull/2864

Mofei Zhang committed Apr 23, 2024 at 10:18 UTC 1efb3cae0aac523064ed5ea649651eb1ab03fae2
5 files changed +29
compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+13
@@ -341,6 +341,7 @@ export type BasicBlock = {
341 */
342 export type Terminal =
343 | UnsupportedTerminal
344 + | UnreachableTerminal
345 | ThrowTerminal
346 | ReturnTerminal
347 | GotoTerminal
@@ -384,6 +385,18 @@ export type UnsupportedTerminal = {
385 id: InstructionId;
386 loc: SourceLocation;
387 };
388 +
389 +/**
390 + * Terminal for an unreachable block.
391 + * Unreachable blocks are emitted when all control flow paths of a if/switch/try block diverge
392 + * before reaching the fallthrough.
393 + */
394 +export type UnreachableTerminal = {
395 + kind: "unreachable";
396 + id: InstructionId;
397 + loc: SourceLocation;
398 +};
399 +
400 export type ThrowTerminal = {
401 kind: "throw";
402 value: Place;
compiler/packages/babel-plugin-react-forget/src/HIR/HIRBuilder.ts
+1
@@ -799,6 +799,7 @@ function getReversePostorderedBlocks(func: HIR): HIR["blocks"] {
799 visit(terminal.block);
800 break;
801 }
802 + case "unreachable":
803 case "unsupported": {
804 break;
805 }
compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts
+5
@@ -121,6 +121,7 @@ export function printMixedHIR(
121 case "throw":
122 case "while":
123 case "for":
124 + case "unreachable":
125 case "unsupported":
126 case "goto":
127 case "do-while":
@@ -261,6 +262,10 @@ export function printTerminal(terminal: Terminal): Array<string> | string {
262 value = `[${terminal.id}] Sequence block=bb${terminal.block} fallthrough=bb${terminal.fallthrough}`;
263 break;
264 }
265 + case "unreachable": {
266 + value = `[${terminal.id}] Unreachable`;
267 + break;
268 + }
269 case "unsupported": {
270 value = `Unsupported`;
271 break;
compiler/packages/babel-plugin-react-forget/src/HIR/visitors.ts
+6
@@ -853,6 +853,7 @@ export function mapTerminalSuccessors(
853 loc: terminal.loc,
854 };
855 }
856 + case "unreachable":
857 case "unsupported": {
858 return terminal;
859 }
@@ -877,6 +878,7 @@ export function terminalFallthrough(terminal: Terminal): BlockId | null {
878 case "goto":
879 case "return":
880 case "throw":
881 + case "unreachable":
882 case "unsupported": {
883 return null;
884 }
@@ -915,6 +917,7 @@ export function mapOptionalFallthroughs(
917 case "goto":
918 case "return":
919 case "throw":
920 + case "unreachable":
921 case "unsupported": {
922 return;
923 }
@@ -1085,6 +1088,7 @@ export function* eachTerminalSuccessor(terminal: Terminal): Iterable<BlockId> {
1088 yield terminal.block;
1089 break;
1090 }
1091 + case "unreachable":
1092 case "unsupported":
1093 break;
1094 default: {
@@ -1144,6 +1148,7 @@ export function mapTerminalOperands(
1148 case "for-of":
1149 case "for-in":
1150 case "goto":
1151 + case "unreachable":
1152 case "unsupported":
1153 case "scope": {
1154 // no-op
@@ -1201,6 +1206,7 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
1206 case "for-of":
1207 case "for-in":
1208 case "goto":
1209 + case "unreachable":
1210 case "unsupported":
1211 case "scope": {
1212 // no-op
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/BuildReactiveFunction.ts
+4
@@ -817,6 +817,10 @@ class Driver {
817
818 break;
819 }
820 + case "unreachable": {
821 + // noop
822 + break;
823 + }
824 case "unsupported": {
825 CompilerError.invariant(false, {
826 reason: "Unexpected unsupported terminal",