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] Context variables as dependencies #31582

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

[compiler] Context variables as dependencies #31582

wants to merge 2 commits into from

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Nov 19, 2024

We previously didn't track context variables in the hoistable values sidemap of propagateScopeDependencies. This was overly conservative as we do track the mutable range of context variables, and it is safe to hoist accesses to context variables after their last direct / aliased maybe-assignment.

function Component({value}) {
  // start of mutable range for `x`
  let x = DEFAULT;
  const setX = () => x = value;
  const aliasedSet = maybeAlias(setX);
  maybeCall(aliasedSet);
  // end of mutable range for `x`

  // here, we should be able to take x (and property reads
  // off of x) as dependencies
  return <Jsx value={x} />
}

Stack created with Sapling. Best reviewed with ReviewStack.

Clean up duplicate checks for when to skip processing values as dependencies / hoistable temporaries.
We previously didn't track context variables in the hoistable values sidemap of `propagateScopeDependencies`. This was overly conservative as we *do*  track the mutable range of context variables, and it is safe to hoist accesses to context variables after their last direct / aliased maybe-assignment.

```js
function Component({value}) {
  // start of mutable range for `x`
  let x = DEFAULT;
  const setX = () => x = value;
  const aliasedSet = maybeAlias(setX);
  maybeCall(aliasedSet);
  // end of mutable range for `x`

  // here, we should be able to take x (and property reads
  // off of x) as dependencies
  return <Jsx value={x} />
}
```
Copy link

vercel bot commented Nov 19, 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 Nov 19, 2024 2:55pm

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