Skip to content

Commit 226c7cb

Browse files
committed
Fix #1385: Temporarily lift 22 limit for functions
1 parent 11f06fe commit 226c7cb

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import collection.mutable
1212
import scala.reflect.api.{ Universe => ApiUniverse }
1313

1414
object Definitions {
15-
val MaxFunctionArity, MaxTupleArity = 22
15+
val MaxTupleArity, MaxAbstractFunctionArity = 22
16+
val MaxFunctionArity = 24
17+
// Awaiting a definite solution that drops the limit altogether, 44 gives a safety
18+
// margin over the previous 22, so that treecopiers in miniphases are allowed to
19+
// temporarily create larger closures. This is needed in lambda lift where large closures
20+
// are first formed by treecopiers before they are split apart into parameters and
21+
// environment in the lambdalift transform itself.
1622
}
1723

1824
/** A class defining symbols and types of standard definitions
@@ -587,7 +593,7 @@ class Definitions {
587593

588594
// ----- Symbol sets ---------------------------------------------------
589595

590-
lazy val AbstractFunctionType = mkArityArray("scala.runtime.AbstractFunction", MaxFunctionArity, 0)
596+
lazy val AbstractFunctionType = mkArityArray("scala.runtime.AbstractFunction", MaxAbstractFunctionArity, 0)
591597
val AbstractFunctionClassPerRun = new PerRun[Array[Symbol]](implicit ctx => AbstractFunctionType.map(_.symbol.asClass))
592598
def AbstractFunctionClass(n: Int)(implicit ctx: Context) = AbstractFunctionClassPerRun()(ctx)(n)
593599
lazy val FunctionType = mkArityArray("scala.Function", MaxFunctionArity, 0)

src/scala/Function23.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* __ *\
2+
** ________ ___ / / ___ Scala API **
3+
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
4+
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5+
** /____/\___/_/ |_/____/_/ | | **
6+
** |/ **
7+
\* */
8+
package scala
9+
10+
11+
/** A function of 23 parameters. Used as a temporary fix until arity limit is dropped.
12+
*
13+
*/
14+
trait Function23[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, -T23, +R] extends AnyRef { self =>
15+
/** Apply the body of this function to the arguments.
16+
* @return the result of function application.
17+
*/
18+
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13, v14: T14, v15: T15, v16: T16, v17: T17, v18: T18, v19: T19, v20: T20, v21: T21, v22: T22, v23: T23): R
19+
20+
override def toString() = "<function23>"
21+
}

src/scala/Function24.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* __ *\
2+
** ________ ___ / / ___ Scala API **
3+
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
4+
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5+
** /____/\___/_/ |_/____/_/ | | **
6+
** |/ **
7+
\* */
8+
package scala
9+
10+
11+
/** A function of 24 parameters. Used as a temporary fix until arity limit is dropped.
12+
*
13+
*/
14+
trait Function24[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, -T23, -T24, +R] extends AnyRef { self =>
15+
/** Apply the body of this function to the arguments.
16+
* @return the result of function application.
17+
*/
18+
def apply(v1: T1, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, v7: T7, v8: T8, v9: T9, v10: T10, v11: T11, v12: T12, v13: T13, v14: T14, v15: T15, v16: T16, v17: T17, v18: T18, v19: T19, v20: T20, v21: T21, v22: T22, v23: T23, v24: T24): R
19+
20+
override def toString() = "<function24>"
21+
}

tests/pos/i1385.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def foo22[T](c1:T, c2:T, c3:T, c4:T, c5:T, c6:T, c7:T, c8:T, c9:T, c10:T, c11:T, c12:T, c13:T, c14:T, c15:T, c16:T, c17:T, c18:T, c19:T, c20:T, c21:T, c22:T): Int => T = {
3+
(a: Int) => { // This labda ends with 23 parameters (c1 to c22 and a)
4+
c22; c21; c20; c19; c18; c17; c16; c15; c14; c13; c12; c11; c10; c9; c8; c7; c6; c5; c4; c3; c2; c1
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)