feat(react_compiler): implement enableEmitHookGuards codegen#24329
Merged
Conversation
Boshen
force-pushed
the
react-compiler-hook-guards
branch
from
July 9, 2026 13:04
ff3ba18 to
99b5879
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
Boshen
marked this pull request as ready for review
July 10, 2026 04:35
Member
Author
Merge activity
|
Implements the last `unimplemented`-flagged codegen path, porting TS `createHookGuard`/`createCallExpression` exactly:
- **Whole-body wrap**: with `enableEmitHookGuards` in client mode, the compiled function body becomes `try { $dispatcherGuard(0); … } finally { $dispatcherGuard(1); }`, applied before the memo-cache preface is unshifted so `const $ = _c(n)` stays outside the guard.
- **Per-hook-call wrap**: hook calls (`getHookKind != null`, for both `CallExpression` and `MethodCall`) are wrapped in `(function () { try { $dispatcherGuard(2); return useHook(…); } finally { $dispatcherGuard(3); } })()`. Non-hook calls are untouched — the previous stub errored on *every* call when guards were enabled.
- The guard import was already resolved by the existing `hook_guard_name` plumbing; codegen just references it.
Since this was the only producer of `CompilerError::unimplemented`, the flag and the empty-body fallback in `codegen_function` are removed — codegen errors now always propagate as diagnostics.
Output verified against the upstream fixture: `flag-enable-emit-hook-guards` previously fell back to an **empty function body**; it now matches `flag-enable-emit-hook-guards.expect.md` node-for-node (same 4 memo slots, same guard kinds, hooks-only wrapping including the nested `useContext` and the `ObjectWithHooks.useIdentity` method call), differing only in oxc_codegen paren style for IIFEs in expression position. The remaining 1735 fixture snapshots are unchanged.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
graphite-app
Bot
force-pushed
the
react-compiler-hook-guards
branch
from
July 10, 2026 04:38
99b5879 to
a3a39f9
Compare
Boshen
added a commit
that referenced
this pull request
Jul 14, 2026
### 🚀 Features - 616bfa2 minifier: Remove unreachable code after terminating statements (#24441) (Dunqing) - ddab89a data_structures: Add `likely` and `unlikely` functions (#24368) (overlookmotel) - a3a39f9 react_compiler: Implement enableEmitHookGuards codegen (#24329) (Boshen) - b79eef7 minifier: Apply De Morgan's law to negated comparison chains in jump guards and loop tests (#24279) (Dunqing) - 34ff7b4 minifier: Drop write-only property assignments to unused local bindings by default (#24112) (Dunqing) - 1b829d8 semantic: Record const enums in EnumData (#24268) (Dunqing) - ba0944c semantic: Add `Scoping::set_symbol_span` (#24221) (camc314) ### 🐛 Bug Fixes - 7d33363 minifier: Preserve guaranteed throws from class heritage evaluation (#24349) (Dunqing) - 058a62f semantic: Track ambient contexts in `SemanticBuilder` (#24327) (camc314) - 721eb0b transformer/decorator: Scope accessor class binding (#24330) (camc314) - 1ebdce3 semantic: Allow reserved keywords in ambient declaration types (#24325) (camc314) - 460176a track-memory-allocations: Exclude arena chunks from Sys allocs (#24292) (Dunqing) - af4922b transformer: Clear lowered namespace redeclarations (#24300) (camc314) - ffd2765 semantic: Mark declared computed `MethodDefinition`s as type references (#24296) (camc314) - f17514b isolated-declarations: Emit const readonly fields as types (#24288) (camc314) - 40f769d minifier: Make `__proto__` write tracking execution-order independent (#24280) (Dunqing) - 6371fed transformer: Remove stale enum member bindings (#24272) (camc314) - f05dfab transformer: Correct symbol flags for lowered namespaces (#24271) (Dunqing) - 84eeb55 transformer: Correct symbol flags for lowered enums (#24269) (Dunqing) - c3057da transformer: Preserve generated class binding spans (#24220) (camc314) - 8260096 transformer: Correct span for lowered namespace symbol (#24222) (camc314) - 42d00d3 semantic: Mark declared class heritage as type references (#24237) (camc314) - 588d997 semantic: Mark TS `PropertyDefinition`s computed fields as type references (#24233) (camc314) - 9b95632 semantic: Mark computed method keys in `TSMethodSignature`s as type references (#24232) (camc314) ### ⚡ Performance - 5b26643 transformer_plugins: Dispatch global defines by trailing name (#23666) (Boshen) - dce0f29 react_compiler: Replace all compiled functions in a single AST walk (#24403) (Boshen) - f85f0d8 ast: Delegate inherited enum variants in clone_in and estree derives (#23555) (Boshen) - 3ff0234 allocator: Remove `unwrap` from `ReplaceWith` (#24365) (overlookmotel) - ab22e80 transformer: Fix Rust 1.97 performance regression (#24354) (camc314) - b47585c parser: Use `ReplaceWith` instead of `TakeIn` (#24018) (overlookmotel) - b227a06 minifier: Use `ReplaceWith` instead of `TakeIn` (#24017) (overlookmotel) Co-authored-by: Boshen <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the last
unimplemented-flagged codegen path, porting TScreateHookGuard/createCallExpressionexactly:enableEmitHookGuardsin client mode, the compiled function body becomestry { $dispatcherGuard(0); … } finally { $dispatcherGuard(1); }, applied before the memo-cache preface is unshifted soconst $ = _c(n)stays outside the guard.getHookKind != null, for bothCallExpressionandMethodCall) are wrapped in(function () { try { $dispatcherGuard(2); return useHook(…); } finally { $dispatcherGuard(3); } })(). Non-hook calls are untouched — the previous stub errored on every call when guards were enabled.hook_guard_nameplumbing; codegen just references it.Since this was the only producer of
CompilerError::unimplemented, the flag and the empty-body fallback incodegen_functionare removed — codegen errors now always propagate as diagnostics.Output verified against the upstream fixture:
flag-enable-emit-hook-guardspreviously fell back to an empty function body; it now matchesflag-enable-emit-hook-guards.expect.mdnode-for-node (same 4 memo slots, same guard kinds, hooks-only wrapping including the nesteduseContextand theObjectWithHooks.useIdentitymethod call), differing only in oxc_codegen paren style for IIFEs in expression position. The remaining 1735 fixture snapshots are unchanged.🤖 Generated with Claude Code