Skip to content

Enable regenerator transform for hermes-canary - #44668

Closed
dannysu wants to merge 2 commits into
react:mainfrom
dannysu:export-D57742907
Closed

dannysu wants to merge 2 commits into
react:mainfrom
dannysu:export-D57742907

Conversation

@dannysu

@dannysu dannysu commented May 23, 2024

Copy link
Copy Markdown

Summary: Enables regenerator for hermes-canary. Along with the previous diff, regenerator is the only difference between hermes-stable and hermes-canary`.

Differential Revision: D57742907

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 23, 2024
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D57742907

@analysis-bot

analysis-bot commented May 23, 2024 •

Copy link
Copy Markdown
Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,559,084 +12
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,912,777 -13
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: b2ced62
Branch: main

Danny Su added 2 commits May 23, 2024 15:56
Summary:

This diff makes the `hermes-canary` transform profile identical to `hermes-stable` by enabling destructuring.

Differential Revision: D57738865
Summary:

Enables regenerator for `hermes-canary`. Along with the previous diff, regenerator is the only difference between `hermes-stable` and `hermes-canary`.

Differential Revision: D57742907
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D57742907

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label May 31, 2024
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in a0237e9.

kosmydel pushed a commit to kosmydel/react-native that referenced this pull request Jun 11, 2024
Summary:
Pull Request resolved: react#44668

Enables regenerator for `hermes-canary`. Along with the previous diff, regenerator is the only difference between `hermes-stable` and `hermes-canary`.

Reviewed By: motiz88

Differential Revision: D57742907

fbshipit-source-id: ca14cb50fe976744c7fa2c0b3397e81661359f15
meta-codesync Bot pushed a commit that referenced this pull request Oct 22, 2026
Summary:
## Motivation

 - Dev/release consistency in correctness and performance shape.
 - ~10% faster dev cold builds
 - More responsive dev apps (~2x faster promise handling)
 - Improved debugging support

Since #52651, Hermes profiles have lowered generators (with `enableBabelRuntime: false`), `for...of`, `?.`, `??` and optional catch binding in dev builds only, because Hermes couldn't show local variables when paused on a breakpoint in a native generator.

That turned out to be a Hermes bug: a breakpoint on that a `yield` line resolved to scope-less entry code before the body had even run. It was fixed in facebook/hermes@d1238c8 (hermes-v260318099.0.2), which main has used since #58397.

This removes `enableRegenerator`, so Hermes-profile dev output matches release. It also fixes a dev-only divergence - loose `for-of` never calls `iterator.return()`, so breaking out of a `for...of` over a generator skipped its `finally` in dev but not release.

Note that with the default `enableBabelRuntime`, generators were already native in dev, so in practice the generator change mostly affects `enableBabelRuntime: false` setups, including RN's own Jest. (There's no good reason generator was ever conditional on `enableBabelRuntime === false` - it seems to date from #44668 and probably a misunderstanding of what the `regenerator` argument to `babel/plugin-transform-runtime` did - it doesn't make that plugin transform generators, it just rewrites the helper import.)

Native generator debugging still isn't perfect on .0.2 - stepping through `try`/`catch` can stop on a `catch` line that doesn't run, and breakpoints on `yield*` lines or on a `throw` after a resume don't fire. Those already affect every default config though, so there's no regression in most cases. Regenerator has its own problems, eg breakpoints often stop a line early because statements merge into its `case` blocks. Overall, native is now a better experience.

Detailed comparison in https://robhogan.github.io/reports/react-native-regenerator-removal/

## Changelog

[GENERAL] [FIXED] - Babel preset: Hermes profiles no longer lower generators, `for...of`, optional chaining, nullish coalescing or optional catch binding in dev, matching release

Pull Request resolved: #59303

Test Plan:
Reproduced the original bug through Hermes's `CDPAgent` test harness with `Debugger.setBreakpointByUrl`. On hermes-v250829098.0.16 and v260318099.0.1, a breakpoint on a generator's last `yield` line pauses at the generator call with only the global scope, and every local evaluates to `undefined`. On v260318099.0.2 and .0.4 it pauses at the real code with all locals.

AI-driven breakpoint sweep: this preset with `dev: true, enableBabelRuntime: false`, before and after this change, over 248 source lines of generator, async function, async generator, exception and loop fixtures. A breakpoint was set on every line, each pause was mapped back through the source map, and every local was evaluated. Same results with eager and lazy compilation.

| Hermes | Identical | Different, equivalent | Native better | Native worse | Mixed (loop headers) | Total |
| --- | --- | --- | --- | --- | --- | --- |
| 250829098.0.16 | 164 | 10 | 49 | 22 | 3 | 248 |
| 260318099.0.2 | 183 | 11 | 47 | 3 | 3 | 247 |
| 260318099.0.4 | 184 | 11 | 47 | 3 | 3 | 248 |

Reviewed By: christophpurrer

Differential Revision: D126904757

Pulled By: javache

fbshipit-source-id: f2d492ec6c326b9ec8b8101832c85b921836f5ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants