-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
[compiler] First cut at dep inference #31386
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Ahh I think what you might be observing is that we create scopes for hook calls, but then flatten them away. And so either you’re looking at the pre-flattened state or you’re looking at a later pass after we flatten to a labeled block. We want to get rid of the labeled block and truly flatten it as if there had never been a scope, though. So I would definitely code as if there could be other instructions in the block w the effect. |
No, that should only happen if there wasn’t an inline function expression. |
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
Outdated
Show resolved
Hide resolved
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.
Exciting! A bunch of smaller feedback, we should discuss the strategy (given the need for guaranteed compilation) in our compiler design sync
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
Show resolved
Hide resolved
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
Outdated
Show resolved
Hide resolved
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
Outdated
Show resolved
Hide resolved
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
Outdated
Show resolved
Hide resolved
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
Outdated
Show resolved
Hide resolved
...ges/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies.js
Outdated
Show resolved
Hide resolved
@mofeiZ mentioned that it would be good to promote effect lambdas to their own scope before running |
Hmmm given that effect lambdas are immediately frozen and also transitively freeze their dependencies, they should already be in their own scope anyway. Do you have a specific example where that isn't the case now? |
I don't have a specific example, but we were talking about this in the context of a reduced pipeline that may not be running all of the phases. For example, we may not freeze functions in the re-run because it relies on certain Rules of React not to be violated. In that context it seems possible? In any case, it doesn't need to block this PR and I can wait until I produce that issue! |
Ahhh i see. Yeah, in the reduced pipeline you could just force-creates scopes around the lambdas passed to useEffect and run propagateScopeDeps to get the deps. |
This is for researching/prototyping, not a feature we are releasing imminently.
Putting up an early version of inferring effect dependencies to get feedback on the approach. We do not plan to ship this as-is, and may not start by going after direct
useEffect
calls. Until we make that decision, the heuristic I use to detect when to insert effect deps will suffice for testing.The approach is simple: when we see a useEffect call with no dep array we insert the deps inferred for the lambda passed in. If the first argument is not a lambda then we do not do anything.
This diff is the easy part. I think the harder part will be ensuring that we can infer the deps even when we have to bail out of memoization. We have no other features that must run regardless of rules of react violations. Does anyone foresee any issues using the compiler passes to infer reactive deps when there may be violations?
I have a few questions:
addedInstrs
variable that I use to make sure I insert the effect deps array temp creation at the right spot.