Skip to content

[compiler] Fix for loops in try/catch#35686

Merged
josephsavona merged 4 commits intofacebook:mainfrom
josephsavona:bug-investigator-agent-2
Feb 3, 2026
Merged

[compiler] Fix for loops in try/catch#35686
josephsavona merged 4 commits intofacebook:mainfrom
josephsavona:bug-investigator-agent-2

Conversation

@josephsavona
Copy link
Member

This is a combination of a) a subagent for investigating compiler errors and b) testing that agent by fixing bugs with for loops within try/catch. My recent diffs to support maybe-throw within value blocks was incomplete and handled many cases, like optionals/logicals/etc within try/catch. However, the handling for for loops was making more assumptions and needed additional fixes.

Key changes:

  • maybe-throw terminal handler is now nullable. PruneMaybeThrows nulls the handler for blocks that cannot throw, rather than changing to a goto. This preserves more information, and makes it easier for BuildReactiveFunction's visitValueBlock() to reconstruct the value blocks
  • Updates BuildReactiveFunction's handling of for init/test/update (and similar for for..of and for..in) to correctly extract value blocks. The previous logic made assumptions about the shape of the SequenceExpression which were incorrect in some cases within try/catch. The new helper extracts a flattened SequenceExpression.

Supporting changes:

  • The agent itself (tested via this diff)
  • Updated the script for invoking snap to keep compiler/ as the working directory, allowing relative paths to work more easily
  • Add an --update (-u) flag to yarn snap minimize, which updates the fixture in place w the minimized version

Fix for for..in and for..of within try/catch. The logic to extract the init/test values didn't work in the presence of maybe-throw terminals. We fix that with more robust extraction of the value block values for this case, consistently flattening nested sequence expressions into a single ReactiveValue.
@josephsavona josephsavona requested a review from mofeiZ February 3, 2026 20:20
@meta-cla meta-cla bot added the CLA Signed label Feb 3, 2026
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Feb 3, 2026
@josephsavona josephsavona force-pushed the bug-investigator-agent-2 branch from 0c7b7ca to f09e434 Compare February 3, 2026 20:37
@@ -0,0 +1,113 @@
---
name: compiler-bug-investigator
description: "Use this agent when the developer asks to 'investigate a bug', 'debug why this fixture errors', 'understand why the compiler is failing', 'find the root cause of a compiler issue', or when they provide a code snippet that the React Compiler handles incorrectly and want to understand why. This agent is specifically for React Compiler bugs, not general React bugs.\\n\\n<example>\\nContext: User provides a code snippet that causes the compiler to error unexpectedly.\\nuser: \"Can you investigate why this code errors? function Component() { const x = a?.b; return <div>{x}</div> }\"\\nassistant: \"I'll use the compiler-bug-investigator agent to investigate this bug and find the root cause.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>\\n\\n<example>\\nContext: User asks to debug a fixture that's producing incorrect output.\\nuser: \"Debug why the fixture error.invalid-optional-chain.js is failing\"\\nassistant: \"Let me launch the compiler-bug-investigator agent to analyze this fixture and identify the problematic compiler pass.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>\\n\\n<example>\\nContext: User wants to understand unexpected compiler behavior.\\nuser: \"Investigate a bug - the compiler is generating wrong code for ternary expressions with side effects\"\\nassistant: \"I'll use the compiler-bug-investigator agent to systematically investigate this issue and identify the faulty compiler logic.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>"
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to move the example out of the description, as it might throw off the search: https://platform.claude.com/docs/en/agents-and-tools/agent-skills/best-practices#writing-effective-descriptions

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. I used /agents to create this, i didn't decide specifically what to put here

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to shrink down the description

@josephsavona josephsavona force-pushed the bug-investigator-agent-2 branch from f09e434 to ec8e4c8 Compare February 3, 2026 21:21
@josephsavona josephsavona force-pushed the bug-investigator-agent-2 branch from ec8e4c8 to 7e8ae2d Compare February 3, 2026 21:57
@josephsavona josephsavona changed the title [compiler] Fixes for for loops in try/catch [compiler] Fix for loops in try/catch Feb 3, 2026
@josephsavona josephsavona merged commit cd0c487 into facebook:main Feb 3, 2026
18 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 3, 2026
This is a combination of a) a subagent for investigating compiler errors
and b) testing that agent by fixing bugs with for loops within
try/catch. My recent diffs to support maybe-throw within value blocks
was incomplete and handled many cases, like optionals/logicals/etc
within try/catch. However, the handling for for loops was making more
assumptions and needed additional fixes.

Key changes:
* `maybe-throw` terminal `handler` is now nullable. PruneMaybeThrows
nulls the handler for blocks that cannot throw, rather than changing to
a `goto`. This preserves more information, and makes it easier for
BuildReactiveFunction's visitValueBlock() to reconstruct the value
blocks
* Updates BuildReactiveFunction's handling of `for` init/test/update
(and similar for `for..of` and `for..in`) to correctly extract value
blocks. The previous logic made assumptions about the shape of the
SequenceExpression which were incorrect in some cases within try/catch.
The new helper extracts a flattened SequenceExpression.

Supporting changes:
* The agent itself (tested via this diff)
* Updated the script for invoking snap to keep `compiler/` as the
working directory, allowing relative paths to work more easily
* Add an `--update` (`-u`) flag to `yarn snap minimize`, which updates
the fixture in place w the minimized version

DiffTrain build for [cd0c487](cd0c487)
github-actions bot pushed a commit that referenced this pull request Feb 3, 2026
This is a combination of a) a subagent for investigating compiler errors
and b) testing that agent by fixing bugs with for loops within
try/catch. My recent diffs to support maybe-throw within value blocks
was incomplete and handled many cases, like optionals/logicals/etc
within try/catch. However, the handling for for loops was making more
assumptions and needed additional fixes.

Key changes:
* `maybe-throw` terminal `handler` is now nullable. PruneMaybeThrows
nulls the handler for blocks that cannot throw, rather than changing to
a `goto`. This preserves more information, and makes it easier for
BuildReactiveFunction's visitValueBlock() to reconstruct the value
blocks
* Updates BuildReactiveFunction's handling of `for` init/test/update
(and similar for `for..of` and `for..in`) to correctly extract value
blocks. The previous logic made assumptions about the shape of the
SequenceExpression which were incorrect in some cases within try/catch.
The new helper extracts a flattened SequenceExpression.

Supporting changes:
* The agent itself (tested via this diff)
* Updated the script for invoking snap to keep `compiler/` as the
working directory, allowing relative paths to work more easily
* Add an `--update` (`-u`) flag to `yarn snap minimize`, which updates
the fixture in place w the minimized version

DiffTrain build for [cd0c487](cd0c487)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants