-
Notifications
You must be signed in to change notification settings - Fork 21
Array[Double](1) not optimized by compiler #12201
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
Comments
("good first issue" is speculative. a newcomer could investigate, and it's plausible that an easy solution exists, given that the other forms get optimized as expected) |
Hello @SethTisue , what knowledge need to solve this problem? Where is the related code ? |
As I commented on the other ticket you asked about, my “You Are a Scala Contributor” video and/or slides are good for getting oriented, as are the README and CONTRIBUTING files in scala/scala. You should already be very comfortable coding in Scala. And you should only attempt this bug if you want to learn something about Scala compiler internals, starting with https://docs.scala-lang.org/overviews/reflection/symbols-trees-types.html . This is a "good first issue" (we suspect, we hope) for those who have that desire. (Having studied other compilers isn't a prerequisite.) The optimization in question is implemented at https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/transform/CleanUp.scala#L595-L609 A few recent PRs closely related to this: scala/scala#9356, scala/scala#9461 |
Originally posted by @texasbruce in #6247 (comment)
Recently I have hit an issue in a real application - I was surprised to see Double boxing in it. Reduced to the bare minimum the following code produces an array construction which is not optimized:
var el = Array[Double](1)
var el = Array[Double](1.0)
Both produce the following byte code:
A slightly different variants are optimized as expected:
var el = Array(1.0)
var el: Array[Double] = Array(1)
See also https://stackoverflow.com/q/64482385/16673
I see the issue in both Scala 2.12.12 and 2.13.3. I do not see the issue in Dotty 0.27
The text was updated successfully, but these errors were encountered: