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

Ensure function arity is preserved after build #31808

Merged
merged 8 commits into from
Dec 18, 2024

Conversation

davesnx
Copy link
Contributor

@davesnx davesnx commented Dec 16, 2024

Closes #31578
Closes #31598


Problem

The google closure compiler has a feature for optimizing function calls. It identifies opportunities to replace the original argument arrays with a more compact representation, such as array or replace constant arguments with their literal values.

In the case of functions that use arguments it added an extra parameter and caused the arity (fn.length) to differ (which became different from development to prod due to DEV).

This became an issue for reason-react (and maybe other binding systems as well), since we need to bind to the interface and statically how many parameters are expected. reason-react carries the OCaml-way of being a curried language where there's no difference between let fn = (a, b) => ... and let fn = (a) => (b) => .... The compiler to JavaScript (Melange) has a small runtime that calls the function with the right number of parameters. This is the related issue: reasonml/reason-react#860.

Solution

At first, I made it work with the // @nocollapse annotation (https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nocollapse), but I found out that just adding a reference is more clear on the intention of the gcc to not optimze this bit, rather than using a no-obvious annotation that seems to do the job.

Thanks @eps1lon for the help

Copy link

vercel bot commented Dec 16, 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 18, 2024 11:34am

@eps1lon eps1lon changed the title [I#31578] Fix for different arity based on development Ensure function arity is preserved after build Dec 17, 2024
Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Great find!

scripts/rollup/validate/eslintrc.fb.js Outdated Show resolved Hide resolved
@react-sizebot
Copy link

react-sizebot commented Dec 17, 2024

Comparing: 6a4b46c...7a76dc1

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 510.71 kB 510.71 kB = 91.29 kB 91.29 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 516.86 kB 516.86 kB = 92.24 kB 92.24 kB
facebook-www/ReactDOM-prod.classic.js = 592.42 kB 592.42 kB = 104.37 kB 104.37 kB
facebook-www/ReactDOM-prod.modern.js = 582.68 kB 582.68 kB = 102.82 kB 102.82 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-react-native/scheduler/cjs/Scheduler-profiling.js +1.25% 10.74 kB 10.87 kB +1.99% 2.62 kB 2.67 kB
facebook-react-native/scheduler/cjs/Scheduler-prod.js = 10.44 kB 10.30 kB = 2.57 kB 2.52 kB

Generated by 🚫 dangerJS against 86ec758

…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)
Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Thank you!

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.

[React 19] useState's setter function becomes arity 2
4 participants