Skip to content

[compiler] Propagate CreateFunction effects for functions that return functions#101

Draft
everettbu wants to merge 2 commits into
mainfrom
pr33642
Draft

[compiler] Propagate CreateFunction effects for functions that return functions#101
everettbu wants to merge 2 commits into
mainfrom
pr33642

Conversation

@everettbu

@everettbu everettbu commented Dec 12, 2025

Copy link
Copy Markdown

Mirror of facebook/react#33642
Original author: josephsavona


If you have a local helper function that itself returns a function (() => () => { ... }), we currently infer the return effect of the outer function as Create mutable. We correctly track the aliasing, but we lose some precision because we don't understand that a function specifically is being returned.

Here, we do some extra analysis of which values are returned in InferMutationAliasingRanges, and if the sole return value is a function we infer a CreateFunction effect. We also infer an Assign (instead of a Create) if the sole return value was one of the context variables or parameters.


Stack created with Sapling. Best reviewed with ReviewStack.

  • #33643
  • -> #33642
  • #33650

In InferReferenceEffects we used `InstructionValue` as the key to represent values, since each time we process an instruction this object will be the same. However this was always a bit of a hack, and in the new model and InferMutationAliasingEffects we can instead use the (creation) effect as the stable value. This avoids an extra layer of memoization since the effects are already interned anyway.
… functions

If you have a local helper function that itself returns a function (`() => () => { ... }`), we currently infer the return effect of the outer function as `Create mutable`. We correctly track the aliasing, but we lose some precision because we don't understand that a function specifically is being returned.

Here, we do some extra analysis of which values are returned in InferMutationAliasingRanges, and if the sole return value is a function we infer a `CreateFunction` effect. We also infer an `Assign` (instead of a Create) if the sole return value was one of the context variables or parameters.
@everettbu everettbu added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants