Skip to content
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] Don't include current field accesses in auto-deps #31652

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

jbrown215
Copy link
Contributor

@jbrown215 jbrown215 commented Dec 2, 2024

Summary

Drops .current field accesses in inferred dep arrays

Stack created with Sapling. Best reviewed with ReviewStack.

Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 11:54pm

Copy link
Contributor

@mofeiZ mofeiZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Comment on lines 226 to 230
/*
* Prune ref.current accesses. This may over-capture for non-ref values with
* a current property, but that's fine.
*/
currValue.effect = Effect.Freeze;
break;
Copy link
Contributor

@josephsavona josephsavona Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't followed the implementation of auto-deps, but why are we changing the effects here? if we're pruning i'd expect that to be operating on the dependency path but not changing effects, which should have already been inferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just unnecessary and I have no idea how that line ended up here
you're fast on draft diffs :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephsavona The freeze here is redundant with a later freeze (before the function return). The reason we're manually setting a Effect.Freeze is because this pass inserts new instructions with new Places.

We could set the effect to be Effect.ConditionallyMutate, but inserted auto-deps really has freeze effects. This really should be a no-op with enableTransitivelyFreezeFunctionExpressions, which already freezes captured dependencies. One thing we could do is validate enableTransitivelyFreezeFunctionExpressions is set with inferEffectDependencies.

@jbrown215 jbrown215 changed the title Don't include current field accesses in auto-deps [compiler] Don't include current field accesses in auto-deps Dec 2, 2024
@jbrown215 jbrown215 changed the title [compiler] Don't include current field accesses in auto-deps Don't include current field accesses in auto-deps Dec 2, 2024
@jbrown215 jbrown215 marked this pull request as ready for review December 2, 2024 20:52
@jbrown215 jbrown215 changed the title Don't include current field accesses in auto-deps [compiler] Don't include current field accesses in auto-deps Dec 2, 2024
Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just using .current feels pretty sketchy, vs for example looking at -Ref.current. But let's experiment.

@jbrown215
Copy link
Contributor Author

just using .current feels pretty sketchy, vs for example looking at -Ref.current. But let's experiment.

Unfortunately I saw multiple cases in my first experiment where the -Ref suffix naming convention was not followed :\

This is the more conservative approach for sure. We can use types to get more precise and error when people use React.RefObjects without a ref suffix in a component/hook

@jbrown215 jbrown215 changed the title [compiler] Don't include current field accesses in auto-deps Don't include current field accesses in auto-deps Dec 2, 2024
@jbrown215 jbrown215 changed the title Don't include current field accesses in auto-deps [compiler] Don't include current field accesses in auto-deps Dec 2, 2024
@jbrown215 jbrown215 changed the title [compiler] Don't include current field accesses in auto-deps Don't include current field accesses in auto-deps Dec 2, 2024
@jbrown215 jbrown215 changed the title Don't include current field accesses in auto-deps [compiler] Don't include current field accesses in auto-deps Dec 2, 2024
## Summary

Drops .current field accesses in inferred dep arrays
@jbrown215 jbrown215 merged commit 2ab471c into facebook:main Dec 3, 2024
19 checks passed
@jbrown215 jbrown215 deleted the pr31652 branch December 3, 2024 12:42
jbrown215 added a commit that referenced this pull request Dec 3, 2024
## Summary

Allows us to add deps for things like `import useWrapperEffect from
'useWrapperEffect'`

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31657).
* __->__ #31657
* #31652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants