Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Add pruned-scope terminal in HIR #29837

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ export type Terminal =
| SequenceTerminal
| MaybeThrowTerminal
| TryTerminal
| ReactiveScopeTerminal;
| ReactiveScopeTerminal
| PrunedScopeTerminal;

export type TerminalWithFallthrough = Terminal & { fallthrough: BlockId };

Expand Down Expand Up @@ -603,6 +604,15 @@ export type ReactiveScopeTerminal = {
loc: SourceLocation;
};

export type PrunedScopeTerminal = {
kind: "pruned-scope";
fallthrough: BlockId;
block: BlockId;
scope: ReactiveScope;
id: InstructionId;
loc: SourceLocation;
};

/*
* Instructions generally represent expressions but with all nesting flattened away,
* such that all operands to each instruction are either primitive values OR are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export function printMixedHIR(
case "do-while":
case "for-in":
case "for-of":
case "scope": {
case "scope":
case "pruned-scope": {
const terminal = printTerminal(value);
if (Array.isArray(terminal)) {
return terminal.join("; ");
Expand Down Expand Up @@ -280,6 +281,12 @@ export function printTerminal(terminal: Terminal): Array<string> | string {
} fallthrough=bb${terminal.fallthrough}`;
break;
}
case "pruned-scope": {
value = `<pruned> Scope ${printReactiveScopeSummary(terminal.scope)} block=bb${
terminal.block
} fallthrough=bb${terminal.fallthrough}`;
break;
}
case "try": {
value = `Try block=bb${terminal.block} handler=bb${terminal.handler}${
terminal.handlerBinding !== null
Expand Down
15 changes: 10 additions & 5 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ export function mapTerminalSuccessors(
loc: terminal.loc,
};
}
case "scope": {
case "scope":
case "pruned-scope": {
const block = fn(terminal.block);
const fallthrough = fn(terminal.fallthrough);
return {
Copy link
Contributor

@TrickyPi TrickyPi Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down Expand Up @@ -904,7 +905,8 @@ export function terminalHasFallthrough<
case "switch":
case "ternary":
case "while":
case "scope": {
case "scope":
case "pruned-scope": {
const _: BlockId = terminal.fallthrough;
return true;
}
Expand Down Expand Up @@ -1006,7 +1008,8 @@ export function* eachTerminalSuccessor(terminal: Terminal): Iterable<BlockId> {
yield terminal.block;
break;
}
case "scope": {
case "scope":
case "pruned-scope": {
yield terminal.block;
break;
}
Expand Down Expand Up @@ -1072,7 +1075,8 @@ export function mapTerminalOperands(
case "goto":
case "unreachable":
case "unsupported":
case "scope": {
case "scope":
case "pruned-scope": {
// no-op
break;
}
Expand Down Expand Up @@ -1130,7 +1134,8 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
case "goto":
case "unreachable":
case "unsupported":
case "scope": {
case "scope":
case "pruned-scope": {
// no-op
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ class Driver {
}
break;
}
case "pruned-scope":
case "scope": {
const fallthroughId = !this.cx.isScheduled(terminal.fallthrough)
? terminal.fallthrough
Expand All @@ -828,7 +829,7 @@ class Driver {

this.cx.unscheduleAll(scheduleIds);
blockValue.push({
kind: "scope",
kind: terminal.kind,
instructions: block,
scope: terminal.scope,
});
Expand Down