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][be] Playground now compiles entire program #31774

Merged
merged 1 commit into from
Dec 16, 2024
Merged

[compiler][be] Playground now compiles entire program #31774

merged 1 commit into from
Dec 16, 2024

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Dec 14, 2024

Compiler playground now runs the entire program through babel-plugin-react-compiler instead of a custom pipeline which previously duplicated function inference logic from Program.ts. In addition, the playground output reflects the tranformed file (instead of a "virtual file" of manually concatenated functions).

This helps with the following:

  • Reduce potential discrepencies between playground and babel plugin behavior. See attached fixture output for an example where we previously diverged.
  • Let playground users see compiler-inserted imports (e.g. _c or useFire)

This also helps us repurpose playground into a more general tool for compiler-users instead of just for compiler engineers.

  • imports and other functions are preserved.
    We differentiate between imports and globals in many cases (e.g. inferEffectDeps), so it may be misleading to omit imports in printed output
  • playground now shows other program-changing behavior like position of outlined functions and hoisted declarations
  • emitted compiled functions do not need synthetic names

Stack created with Sapling. Best reviewed with ReviewStack.

Copy link

vercel bot commented Dec 14, 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 16, 2024 6:50pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 14, 2024
@mofeiZ mofeiZ force-pushed the pr31774 branch 2 times, most recently from ad7b4b0 to 2ea7804 Compare December 14, 2024 00:40
@@ -55,7 +55,7 @@ const TestComponent2 = ({ x }) => {
};`,
},
{
name: 'function-scope-beats-module-scope',
name: 'todo-function-scope-does-not-beat-module-scope',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See attached snap fixture -- playground and the babel plugin diverged before this PR

Compiler playground now runs the entire program through `babel-plugin-react-compiler` instead of a custom pipeline which previously duplicated function inference logic from `Program.ts`. In addition, the playground output reflects the tranformed file (instead of a "virtual file" of manually concatenated functions).

This helps with the following:
- Reduce potential discrepencies between playground and babel plugin behavior. See attached fixture output for an example where we previously diverged.
- Let playground users see compiler-inserted imports (e.g. `_c` or `useFire`)

This also helps us repurpose playground into a more general tool for compiler-users instead of just for compiler engineers.
- imports and other functions are preserved.
  We differentiate between imports and globals in many cases (e.g. `inferEffectDeps`), so it may be misleading to omit imports in printed output
- playground now shows other program-changing behavior like position of outlined functions and hoisted declarations
- emitted compiled functions do not need synthetic names
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.

yesss this is so good! The changes to the HMR setting make sense

@@ -1,4 +1,5 @@
function TestComponent(t0) {
import { c as _c } from "react/compiler-runtime";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we now print inserted imports. Other program level changes (e.g. Options.gating, outlining) should work as expected without hardcoding

import { c as _c } from "react/compiler-runtime";
function useFoo(propVal) {
  const $ = _c(2);
  const t0 = (propVal.baz: number);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flow now codegens and prints successfully. This means that Flow users can use playground without needing to edit / manually strip their annotations

  } else {
    t0 = $[0];
  }
  const x = t0 as number;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typescript also codegens successfully 🎉 No type annotation changes needed

@mofeiZ mofeiZ merged commit e30872a into main Dec 16, 2024
19 checks passed
davesnx added a commit to davesnx/react that referenced this pull request Dec 18, 2024
…act into issue-31578-setter-arity-gcc

* 'issue-31578-setter-arity-gcc' of github.com:/davesnx/react:
  [flags] Clean up scheduler flags (facebook#31814)
  Enable debugRenderPhaseSideEffectsForStrictMode in test renderers (facebook#31761)
  Enable disableDefaultPropsExceptForClasses (facebook#31804)
  Turn on useModernStrictMode in test renderers (facebook#31769)
  [compiler][ez] Add shape for global Object.keys (facebook#31583)
  [compiler] Context variables as dependencies (facebook#31582)
  [compiler] Add fire to known React APIs (facebook#31795)
  [compiler] Add option for firing effect functions (facebook#31794)
  [compiler][be] Logger based debug printing in test runner (facebook#31809)
  [compiler][ez] Clean up duplicate code in propagateScopeDeps (facebook#31581)
  [compiler] Repro for aliased captures within inner function expressions (facebook#31770)
  [compiler][be] Playground now compiles entire program (facebook#31774)
  [Flight] Color and badge non-primary environments (facebook#31738)
  [Flight] Emit Deduped Server Components Marker (facebook#31737)
  [Flight] Sort Server Components Track Group ahead of Client Scheduler/Components Tracks (facebook#31736)
  Clean up context access profiling experiment (facebook#31806)
  [Flight] Stack Parallel Components in Separate Tracks (facebook#31735)
  Flag for requestPaint (facebook#31805)
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.

3 participants