Skip to content

Improve constant folding logic #12080

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 2 commits into from
Apr 15, 2021
Merged

Improve constant folding logic #12080

merged 2 commits into from
Apr 15, 2021

Conversation

nicolasstucki
Copy link
Contributor

  • Better handling of inlined expression
  • Constant fold String.!=
  • Handle null in == and !=

Fixes #12072

@nicolasstucki nicolasstucki force-pushed the fix-#12072 branch 3 times, most recently from b28e5b2 to ca46f64 Compare April 13, 2021 16:00
* Better handling of inlined expression
* Constant fold `String.!=`
* Handle `null` in `==` and `!=`

Fixes scala#12072
@nicolasstucki nicolasstucki requested a review from odersky April 14, 2021 10:00
@nicolasstucki nicolasstucki marked this pull request as ready for review April 14, 2021 10:01
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@@ -59,6 +59,16 @@ object ConstFold:
tree.withFoldedType(Constant(targ.tpe))
case _ => tree

private def treeConstant(tree: Tree)(using Context): Option[Constant] =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be more elegant if ConstantTree was an extractor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to ConstantTree extractor

@odersky odersky assigned nicolasstucki and unassigned odersky Apr 14, 2021
@soronpo
Copy link
Contributor

soronpo commented Apr 14, 2021

I'm not sure if it's relevant here, but is it possible to have constant folding in string interpolation (meaning that if all arguments are constant then the interpolation result will be constant as well)?

@nicolasstucki
Copy link
Contributor Author

Constant folding on string interpolators is a separate and more complex issue (see #10315).

@odersky odersky merged commit dd6fc82 into scala:master Apr 15, 2021
@odersky odersky deleted the fix-#12072 branch April 15, 2021 11:07
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inline if over an inline def doesn't work when overriding a method
4 participants