Skip to content

feat(compiler): Implement constant string concat propagation #29621

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

Merged
merged 1 commit into from
May 28, 2024

Conversation

nikeee
Copy link
Contributor

@nikeee nikeee commented May 28, 2024

Summary

Resolves #29617

How did you test this change?

I verified the implementation using the test.

Copy link

vercel bot commented May 28, 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 May 28, 2024 8:03pm

@react-sizebot
Copy link

react-sizebot commented May 28, 2024

Comparing: 6f23540...cb4a4e4

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.66 kB 6.66 kB = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 496.04 kB 496.04 kB = 88.77 kB 88.77 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 500.84 kB 500.84 kB = 89.46 kB 89.46 kB
facebook-www/ReactDOM-prod.classic.js = 593.48 kB 593.48 kB = 104.38 kB 104.38 kB
facebook-www/ReactDOM-prod.modern.js = 569.87 kB 569.87 kB = 100.77 kB 100.77 kB
test_utils/ReactAllWarnings.js Deleted 63.82 kB 0.00 kB Deleted 15.95 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 63.82 kB 0.00 kB Deleted 15.95 kB 0.00 kB

Generated by 🚫 dangerJS against cb4a4e4

Copy link
Member

@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.

The changes look good, let's just revert the changes under compiler/crates/

@nikeee nikeee force-pushed the string-concat-propagation branch from 6518372 to ca54a0e Compare May 28, 2024 19:58
@nikeee nikeee force-pushed the string-concat-propagation branch from ca54a0e to cb4a4e4 Compare May 28, 2024 19:59
@nikeee
Copy link
Contributor Author

nikeee commented May 28, 2024

I was wondering about the cases where one of the operands is string and the other is number: "a" + 1 and 1 + "0". Should we also consider this as in-scope? If yes, we could change the propagation to just be

case "+": {
  if ((typeof lhs === "number" || typeof lhs === "string")) && (typeof rhs === "number" ||  typeof rhs === "string")) {
    result = { kind: "Primitive", value: lhs + rhs, loc: value.loc };
  }
  break;
}

@nikeee nikeee marked this pull request as ready for review May 28, 2024 20:06
@josephsavona
Copy link
Member

We'd have to double-check the spec for "+" with string and numbers. Let's start with just number+number and string+string.

@josephsavona josephsavona merged commit a9a0106 into facebook:main May 28, 2024
@zhangenming
Copy link
Contributor

What about string+number or num+string
What about other operations(- * / ...)

@nikeee nikeee deleted the string-concat-propagation branch May 30, 2024 04:54
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.

Compiler String Concat Constant Propagation
5 participants