GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [compiler] Improve handling of refs by mvitousek · Pull Request #30902 · react/react

Conversation

@mvitousek

@mvitousek mvitousek commented Sep 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

  • [compiler] Allow all hooks to take callbacks which access refs, but ban hooks from taking direct ref value arguments #30917
  • -> [compiler] Improve handling of refs #30902
  • [compiler] Fix issue where second argument of all functions was considered to be a ref #30912

Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if ref has type Ref, then { x: ref } and [ref] have type Structural(value=Ref) and {x: ref}.anything and [ref][anything] have type Ref).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like

let x = ref;
while (condition) {
  x = [x]
}

we end up giving x the type Structural(value=Ref).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

josephsavona reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@mvitousek
[compiler] Improve handling of refs
bdba7db
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

[ghstack-poisoned]
@vercel

vercel Bot commented Sep 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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 Sep 16, 2024 6:03pm
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mvitousek added a commit that referenced this pull request Sep 7, 2024
@mvitousek
[compiler] Improve handling of refs
789a584
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

ghstack-source-id: 7904093
Pull Request resolved: #30902
@facebook-github-bot facebook-github-bot added the CLA Signed label Sep 7, 2024
@vercel
vercel Bot deployed to Preview September 7, 2024 01:11
View deployment
@mvitousek
Update on "[compiler] Improve handling of refs"
06058d3
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

[ghstack-poisoned]
@mvitousek mvitousek mentioned this pull request Sep 7, 2024
[compiler] Allow ref access in useImperativeHandle #30904
Closed
@vercel
vercel Bot deployed to Preview September 7, 2024 03:50
View deployment
@mvitousek
Update on "[compiler] Improve handling of refs"
4ebea58
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

[ghstack-poisoned]
This was referenced Sep 8, 2024
[compiler] Fix issue where second argument of all functions was considered to be a ref #30912
Merged
[compiler] Allow ref access in useImperativeHandle #30913
Closed
@vercel
vercel Bot deployed to Preview September 8, 2024 00:54
View deployment
@mvitousek

mvitousek commented Sep 8, 2024

Copy link
Copy Markdown
Contributor Author

Internal sync results

A few runtime errors that need to be addressed before this can land but a significant reduction in bailouts

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mvitousek
Update on "[compiler] Improve handling of refs"
37bbb75
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

[ghstack-poisoned]
@mvitousek mvitousek mentioned this pull request Sep 8, 2024
[compiler] Allow all hooks to take callbacks which access refs, but ban hooks from taking direct ref value arguments #30917
Merged
@vercel
vercel Bot deployed to Preview September 8, 2024 18:49
View deployment
@mvitousek

mvitousek commented Sep 8, 2024

Copy link
Copy Markdown
Contributor Author

Updated sync results from the top of this stack at #30917 (including some unrelated PRs), looks good

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mvitousek
mvitousek requested review from josephsavona and mofeiZ September 8, 2024 21:09
josephsavona
josephsavona approved these changes Sep 9, 2024
View reviewed changes

@josephsavona josephsavona left a comment

Copy link
Copy Markdown
Contributor

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.

so good

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts Outdated
}

function joinRefTypes(...types: Array<RefAccessType>): RefAccessType {
function joinRefRefTypes(

@josephsavona josephsavona Sep 9, 2024

Copy link
Copy Markdown
Contributor

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.

naming is hard

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mvitousek reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccesInRender.ts Outdated
}

override set(key: IdentifierId, value: RefAccessType): this {
function tyEqual(a: RefAccessType, b: RefAccessType): boolean {

@josephsavona josephsavona Sep 9, 2024

Copy link
Copy Markdown
Contributor

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.

extract into a static function?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mvitousek
Update on "[compiler] Improve handling of refs"
4c07998
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

[ghstack-poisoned]
@mvitousek
mvitousek merged commit 4c07998 into gh/mvitousek/23/base Sep 16, 2024
mvitousek added a commit that referenced this pull request Sep 16, 2024
@mvitousek
[compiler] Improve handling of refs
1e68a0a
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

ghstack-source-id: afb0b0c
Pull Request resolved: #30902
@mvitousek
mvitousek deleted the gh/mvitousek/23/head branch September 16, 2024 17:57
@vercel
vercel Bot deployed to Preview September 16, 2024 18:03
View deployment
@vercel-release-bot vercel-release-bot mentioned this pull request Sep 17, 2024
Upgrade React from 206df66e-20240912 to a99d8e8d-20240916 vercel/next.js#70190
Merged
eps1lon pushed a commit to vercel/next.js that referenced this pull request Sep 18, 2024
@vercel-release-bot
Upgrade React from 206df66e-20240912 to a99d8e8d-20240916 (#70190)
5791706
**breaking change for canary users: Bumps peer dependency of React from
`19.0.0-rc-206df66e-20240912` to `19.0.0-rc-a99d8e8d-20240916`**

[diff
react/react@206df66e...a99d8e8d](react/react@206df66...a99d8e8)

<details>
<summary>React upstream changes</summary>

- react/react#30977
- react/react#30971
- react/react#30922
- react/react#30917
- react/react#30902
- react/react#30912
- react/react#30970
- react/react#30969
- react/react#30967
- react/react#30966
- react/react#30960
- react/react#30968
- react/react#30961
- react/react#28255
- react/react#30957
- react/react#30958
- react/react#30959
- react/react#30951
- react/react#30954
- react/react#30920
- react/react#30942

</details>
@coderabbitai coderabbitai Bot mentioned this pull request Jul 20, 2026
feat(daily): week calendar strip — switch days from the subheader cameronapak/dotflowy#301
Merged
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
@mvitousek
[compiler] Improve handling of refs
f7209bf
Summary:
This change expands our handling of refs to build an understanding of nested refs within objects and functions that may return refs. It builds a special-purpose type system within the ref analysis that gives a very lightweight structural type to objects and array expressions (merging the types of all their members), and then propagating those types throughout the analysis (e.g., if `ref` has type `Ref`, then `{ x: ref }` and `[ref]` have type `Structural(value=Ref)` and `{x: ref}.anything` and `[ref][anything]` have type `Ref`).

This allows us to support structures that contain refs, and functions that operate over them, being created and passed around during rendering without at runtime accessing a ref value.

The analysis here uses a fixpoint to allow types to be fully propagated through the system, and we defend against diverging by widening the type of a variable if it could grow infinitely: so, in something like
```
let x = ref;
while (condition) {
  x = [x]
}
```
we end up giving `x` the type `Structural(value=Ref)`.

ghstack-source-id: afb0b0c
Pull Request resolved: react#30902

This branch was successfully deployed

1 active deployment
Preview — 4c07998e Deployed Sep 16, 2024 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mofeiZ mofeiZ Awaiting requested review from mofeiZ
1 more reviewer
@josephsavona josephsavona josephsavona approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CLA Signed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mvitousek @josephsavona @facebook-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.