How to compile scala with large tuples?

I want to compile a Scala distribution with a large limit for the number of tuple arguments - for example, 50 instead of 22. (and also the extension of the function class / case / etc)

I assumed those are TupleN, FunctionN, etc. generated at compile time. But in the sources directory I found all those Tuple1 for Tuple22 with comments that they were generated.

In addition, I found the src / build / genprod.scala file, which seems to be a necessary file. But how to run it right?

I changed MAX_ARITY in genprod and changed MaxFunctionArity in Definitions.scala , what else do I need to change to make it work?

And is it possible to use Scala's resulting distribution with sbt? Or are there some fundamental issues with this?

NOTE: I fully understand that trying to get around tuple problems this way is not very good, but in this case it is more of an educational project.

EDIT: Well, this is getting interesting. Since the Scala compiler loads, I cannot compile it with large tuples, since the old compiler uses 22 limits. Therefore, it seems to me that first I need to create a compiler with this limit, and only after that compile it into several tuples. How can i do this?

EDIT2: Now I have a problem - I tried to increase MaxFunctionArity and run ant replacestarr-opt , but then it does not work with scala.Function23 not found . If I try to add scala.Function23 and the like, it will not compile at all. Is there any way to fix this?

EDIT3: I tried to execute the commands in the following order:

 ant build # increase MaxFunctionArity ant build ant replacelocker # generate TupleN classes ant build # this fails ant replacelocker 

It seems that ant replacelocker not working because the starr compiler is used and it still does not allow more than 22 arguments.

I tried replacing starr:

 ant build # increase MaxFunctionArity ant build ant replacelocker ant replacestarr # failed 

but this failed with scala.Function23 not found . It seems to be a dead end - I need to change this to MaxFunctionArity and generate classes, but I cannot do it at the same time, and if I try to separate these actions, I get a failure.

Is there any way to resolve this?

EDIT4: I forgot to mention that in this experiment I am trying Scala 2.9.2, as this is the latest stable version.

EDIT5: Since I was able to build a quick compiler with large tuples using the locker compiler, I expected a problem with the starr layer.

So, I tried to do the following (without changing anything):

 ant build ant replacelocker ant replacestarr 

And the last command failed with

 Unable to find jar:file:/home/platon/Input/sources/scala-tupled/lib/scala-compiler.jar!/scala/tools/ant/sabbus/antlib.xml 

Now, what is strange, why can't he build himself?

+6
source share
1 answer

I looked at 2.10, where there is a maximum for Product, Tuple and Function.

I modified genprod to make changes in three steps:

  • ProductN and Free TupleN. Bump max for product and tuple.
  • Add case to Tuple (which requires ProductN). This works because the code that the companion module emits reduces you while reducing the parameter shortening to MaxFunctionArity. I think that Namers should check out MaxProductArity, and companions should stop expanding the function in MaxFunctionArity. Also gen and compile FunctionN, without replenishment and disassembly, which will require the use of N args. (isFunctionType is still false for FunctionN.)
  • Finally, Bump MaxFunctionArity and full feature support.

The formatting of this REPL session is distorted by the x wrapper on function 26, but you get the idea:

  scala> val f: Function26 = null console>:7: error: trait Function26 takes type parameters scala> val f: Function26 = y:Int,z:Int) => a+zf: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) => Int = <function26> scala> f(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2) res0: Int = 3 
+2
source

Source: https://habr.com/ru/post/926302/


All Articles