-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Milestone
Description
Implement constant folding. Miguel's impl: https://github.com/lrytz/scala/blob/opt/rebaseWip/src/compiler/scala/tools/nsc/backend/bcode/ConstantFolder.java
Existing partest tests: jvm/constant-optimization
, t7006
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
lrytz commentedon Nov 6, 2015
Also look at the 2.11 optimizer: https://github.com/scala/scala/blob/2.11.x/src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala
DarkDimius commentedon Nov 6, 2015
Is the goal of constant folding is to reduce bytecode size? If not, is there some smart constant optimization planned that is not performed by JVM?
See also https://bugs.openjdk.java.net/browse/JDK-8058164 and related tickets.
lrytz commentedon Nov 6, 2015
I'm not actually planning to work on this in the near future. As you say, it would only make sense if there was something that we can do considerably better than the JVM.
lrytz commentedon Nov 9, 2015
one existing test (currently in pending): https://github.com/scala/scala/tree/93fa559f62637fc3a49d7b961a1d07cf843b0e6b/test/pending/jvm/constant-optimization
retronym commentedon Feb 12, 2016
I think the motivation of this one would be to enable further optimizations, e.g. to prove that some branches are dead, which might in turn enable box/unbox elim etc.
da-tubi commentedon Jan 7, 2021
@lrytz @retronym Why ConstantOptimization is removed in Scala 2.13? Would it be helpful if someone port it to Scala 2.13.x?
da-tubi commentedon Jan 7, 2021
@lrytz
I'm interested in improving the Scalac Optimizer.
If I write a ConstantOptimizer, is it correct to create a PR under https://github.com/scala/scala/tree/2.13.x/src/compiler/scala/tools/nsc/backend/jvm/opt ?
And also provide a option under
-opt:
and the essential unit tests.lrytz commentedon Jan 7, 2021
Hi @da-tubi, nice to see you interested!
This is the right place for contributions, yes. See https://github.com/scala/scala/tree/2.13.x/test/junit/scala/tools/nsc/backend/jvm/opt for tests.
But first I'd like to learn why you are interested in contributing a constant folder. What is your motivation, do you have a specific project where you know it would help?
In my view, implemention constant folding "for its own sake" is not worth it, as the JVM is doing that already. It would only be worth the effort if constant folding unlocks more optimizations that the Scala optimzier can perform. Or maybe if we can treat certain Scala constructs as "constants" that are not actually constants at the bytecode level, but we know they can be treated as such given Scala's semantics? I don't have anything particular in mind though.
da-tubi commentedon Jan 8, 2021
No specific project. Just for fun and performance!
da-tubi commentedon Jan 11, 2021
I'm trying the tuning my Spark ETL code using the scala compiler flags. For CPU bound tasks, it works as expected. That's the motivation (for
Performance
). Just fixed scala/bug#11247 and I'd like to contribute more on the Scala optimizer (forFun
).da-tubi commentedon Jan 11, 2021
I found a ConstantFolder (
scala.tools.nsc.typechecker.ConstantFolder
) in the typechecker.That's why I'm asking if
src/compiler/scala/tools/nsc/backend/jvm/opt
is the right place (a somewhat silly question).There are many compiler phases. If we expect that constant folding unlocks more optimization, should we implement Constant Folder in earlier phase?
6 remaining items