-
Notifications
You must be signed in to change notification settings - Fork 49.7k
[compiler] Avoid bailouts when inserting gating #32598
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
Conversation
a02fdbd to
216068c
Compare
| CompilerError.throwTodo({ | ||
| reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`, | ||
| description: `Rewrite the reference to ${fnPath.node.id?.name ?? 'this function'} to not rely on hoisting to fix this issue`, | ||
| if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this changes us to only bail out for function declarations which are referenced before declaration.
See invalid-fnexpr-reference and reassigned-fnexpr-variable fixtures for examples why we don't need special handling for other function kinds.
This should be correct as other referenced-before-declaration identifiers are handled by directly replacing ast nodes. This may error at runtime, but still preserves source semantics (e.g. compiler-optimized code errors if and only if source code errors)
| @@ -0,0 +1,62 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixture no longer bails out (component syntax refs produce a hoisted React.forwardRef)
| @@ -0,0 +1,61 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixture also no longer bails out (renamed from error.gating-hoisting)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice find!
…2597) Some code movement for the next PR --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32597). * #32598 * __->__ #32597
This change fixes a coverage hole in rolling out with `gating`. Prior to this PR, configuring `gating` causes React Compiler to bail out of optimizing some functions. This means that it's not entirely safe to cutover from `gating` enabled for all users (i.e. rolled out 100%) to removing the `gating` config altogether, as new functions may be opted into compilation when they stop bailing out due to gating-specific logic. This is technically slightly slower due to the additional function indirection. An alternative approach is to recommend running a codemod to insert `use no memo`s on currently-bailing out functions before removing the`gating` config. --- Tested [internally]( https://fburl.com/diff/q982ovua) by enabling on a page that previously had a few hundred bailouts due to gating + hoisted function declarations and (1) clicking around locally and (2) running a bunch of e2e tests
This change fixes a coverage hole in rolling out with `gating`. Prior to this PR, configuring `gating` causes React Compiler to bail out of optimizing some functions. This means that it's not entirely safe to cutover from `gating` enabled for all users (i.e. rolled out 100%) to removing the `gating` config altogether, as new functions may be opted into compilation when they stop bailing out due to gating-specific logic. This is technically slightly slower due to the additional function indirection. An alternative approach is to recommend running a codemod to insert `use no memo`s on currently-bailing out functions before removing the`gating` config. --- Tested [internally]( https://fburl.com/diff/q982ovua) by enabling on a page that previously had a few hundred bailouts due to gating + hoisted function declarations and (1) clicking around locally and (2) running a bunch of e2e tests DiffTrain build for [d92e571](d92e571)
This change fixes a coverage hole in rolling out with
gating. Prior to this PR, configuringgatingcauses React Compiler to bail out of optimizing some functions.This means that it's not entirely safe to cutover from
gatingenabled for all users (i.e. rolled out 100%) to removing thegatingconfig altogether, as new functions may be opted into compilation when they stop bailing out due to gating-specific logic.This is technically slightly slower due to the additional function indirection. An alternative approach is to recommend running a codemod to insert
use no memos on currently-bailing out functions before removing thegatingconfig.Tested internally by enabling on a page that previously had a few hundred bailouts due to gating + hoisted function declarations and (1) clicking around locally and (2) running a bunch of e2e tests