-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[compiler][ez] Stop bailing out early for hoisted gated functions #32597
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
| 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`, | ||
| loc: fnPath.node.loc ?? null, | ||
| suggestions: null, | ||
| }); |
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.
#32598 replaces this bailout with special handling
| }); | ||
| } else { | ||
| fnPath.replaceWith(gatingExpression); | ||
| const gatingExpression = t.conditionalExpression( |
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.
(unchanged)
| parsedOptions[key] = parseTargetConfig(value); | ||
| break; | ||
| } | ||
| case 'gating': { |
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.
Moved gating config parsing to BabelPlugin entrypoint -- now it's unconditional and eager like the rest of our config parsing / validation. Previously, we only tried to parse gating if we had successful compilation events.
| return; | ||
| } | ||
|
|
||
| let gating: null | { |
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.
Changes in this file are all code movement.
- tryParseExternalFunction is moved to
parsePluginOptions, which runs before this function - collect
referencedBeforeDeclaredset here instead eagerly bailing out. This is to prepare for the next PR [compiler] Avoid bailouts when inserting gating #32598. (Also happy to merge these into a single changeset if that's easier to review)
| if (referencedBeforeDeclaration) { | ||
| 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`, | ||
| loc: fnPath.node.loc ?? null, | ||
| suggestions: null, | ||
| }); |
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.
Small nit; what do you think about moving the throw to the callsite instead of having the boolean arg?
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.
#32511 replaces this throw, so this is very temporary
Some code movement for the next PR
Some code movement for the next PR
Stack created with Sapling. Best reviewed with ReviewStack.