Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one compile scala with bigger tuples?

Tags:

scala

I want to compile Scala distribution with bigger limit for number of tuple arguments - for example, 50 instead of 22. (and function/case class/etc limits upped as well)

I assumed that those TupleN, FunctionN and the like are generated at compile-time. But in sources directory, I found all those Tuple1 to Tuple22, with comment that they are generated.

Also, I found src/build/genprod.scala file, which seems to be the needed file. But what is the right way to run it?

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

And is it possible to use the resulting scala distribution with sbt? Or are there some fundamental problems with that?

NOTE: I completely understand that it is not very good to try to work around tuple problems this way, but in this case it's more of an educational project.

EDIT: Well, it gets interesting. Since scala compiler is bootstraped, I can't compile it with bigger tuples, since old compiler enforces 22 limit. So it seems that first I need to create a compiler with that limit increased, and only after that compile in more tuples. How can I do it?

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

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

The ant replacelocker seems to fail because starr compiler is used, and it still does not allow more than 22 arguments.

I tried to replace starr:

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

but this failed with scala.Function23 not found. Seems to be a deadlock - I need to change that MaxFunctionArity and generate classes, but I can't do that simultaneously, and if I try to separate those actions I get a failure.

Is there some way to resolve that?

EDIT4: I forgot to mention that in this experiment I'm torturing Scala 2.9.2, as it is the last stable version.

EDIT5: Since I actually managed to build quick compiler with big tuples using locker compiler, I expected that there was some problem with starr layer.

So I tried to do the following (without altering 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 that's strange, why it can't build itself?

like image 473
Rogach Avatar asked Sep 26 '12 10:09

Rogach


1 Answers

I took a look at 2.10, where there is max arity for Product, Tuple and Function.

I modified genprod to make the change in three steps:

  1. ProductN, and caseless TupleN. Bump max for product and tuple.
  2. Add case to Tuple (which needs ProductN). This works because the code that emits the companion module cuts you some slack by truncating params to MaxFunctionArity. I think Namers should check MaxProductArity, and companions should stop extending Function at MaxFunctionArity. Also gen and compile FunctionN, without the tupled and uncurried, which would require applying N args. (isFunctionType is still false for FunctionN.)
  3. Finally bump MaxFunctionArity and gen full Function support.

The formatting of this REPL session is mangled by x windows wrapping on Function26, 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+z 
    f: (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
like image 106
som-snytt Avatar answered Oct 05 '22 22:10

som-snytt