mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Retain original structure of labeled blocks
Handles some edge-cases where we previously flattened away some of the structure of a labeled block, instead ensuring that we retain the original shape. See the output. ## Test Plan Tested on the internal app we're focused on (w useMemo inlining enabled), it works fine.
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
Instruction,
|
||||
} from "./HIR";
|
||||
import { markPredecessors, removeUnreachableFallthroughs } from "./HIRBuilder";
|
||||
import { mapOptionalFallthroughs } from "./visitors";
|
||||
|
||||
/**
|
||||
* Merges sequences of blocks that will always execute consecutively —
|
||||
@@ -86,6 +87,9 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
|
||||
fn.body.blocks.delete(block.id);
|
||||
}
|
||||
markPredecessors(fn.body);
|
||||
for (const [, block] of fn.body.blocks) {
|
||||
mapOptionalFallthroughs(block.terminal, (blockId) => merged.get(blockId));
|
||||
}
|
||||
removeUnreachableFallthroughs(fn.body);
|
||||
}
|
||||
|
||||
|
||||
@@ -573,15 +573,18 @@ class Driver {
|
||||
case "optional":
|
||||
case "ternary":
|
||||
case "logical": {
|
||||
const fallthroughId = terminal.fallthrough;
|
||||
invariant(
|
||||
!this.cx.isScheduled(fallthroughId),
|
||||
"Logical terminal fallthrough cannot have been scheduled"
|
||||
);
|
||||
const scheduleId = this.cx.schedule(fallthroughId, "if");
|
||||
scheduleIds.push(scheduleId);
|
||||
const fallthroughId =
|
||||
terminal.fallthrough !== null &&
|
||||
!this.cx.isScheduled(terminal.fallthrough)
|
||||
? terminal.fallthrough
|
||||
: null;
|
||||
if (fallthroughId !== null) {
|
||||
const scheduleId = this.cx.schedule(fallthroughId, "if");
|
||||
scheduleIds.push(scheduleId);
|
||||
}
|
||||
|
||||
const { place, value } = this.visitValueBlockTerminal(terminal);
|
||||
this.cx.unscheduleAll(scheduleIds);
|
||||
blockValue.push({
|
||||
kind: "instruction",
|
||||
instruction: {
|
||||
@@ -592,8 +595,9 @@ class Driver {
|
||||
},
|
||||
});
|
||||
|
||||
this.cx.unschedule(scheduleId);
|
||||
this.visitBlock(this.cx.ir.blocks.get(fallthroughId)!, blockValue);
|
||||
if (fallthroughId !== null) {
|
||||
this.visitBlock(this.cx.ir.blocks.get(fallthroughId)!, blockValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "goto": {
|
||||
|
||||
@@ -47,10 +47,11 @@ function Component(props) {
|
||||
x = 1;
|
||||
} else {
|
||||
if (props.b) {
|
||||
x = 3;
|
||||
} else {
|
||||
break bb1;
|
||||
}
|
||||
|
||||
x = 3;
|
||||
}
|
||||
bb10: bb12: switch (props.c) {
|
||||
case "a": {
|
||||
|
||||
@@ -19,8 +19,6 @@ function MyApp(props) {
|
||||
function MyApp(props) {
|
||||
if (props.cond) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,16 @@ function Component(props) {
|
||||
function Component(props) {
|
||||
let t17 = undefined;
|
||||
bb10: {
|
||||
if (props.cond) {
|
||||
t17 = props.b;
|
||||
bb5: {
|
||||
if (props.cond) {
|
||||
break bb5;
|
||||
}
|
||||
|
||||
t17 = props.a;
|
||||
break bb10;
|
||||
}
|
||||
t17 = props.a;
|
||||
|
||||
t17 = props.b;
|
||||
}
|
||||
const x = t17;
|
||||
return x;
|
||||
|
||||
Reference in New Issue
Block a user