Skip to content

Fix #1385: Temporarily lift 22 limit for functions #1413

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

Merged
merged 2 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import collection.mutable
import scala.reflect.api.{ Universe => ApiUniverse }

object Definitions {
val MaxFunctionArity, MaxTupleArity = 22
val MaxTupleArity, MaxAbstractFunctionArity = 22
val MaxFunctionArity = 24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxFunctionArity should be 44 as documented below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is the doc that is off.

// Awaiting a definite solution that drops the limit altogether, 24 gives a safety
// margin over the previous 22, so that treecopiers in miniphases are allowed to
// temporarily create larger closures. This is needed in lambda lift where large closures
// are first formed by treecopiers before they are split apart into parameters and
// environment in the lambdalift transform itself.
}

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

// ----- Symbol sets ---------------------------------------------------

lazy val AbstractFunctionType = mkArityArray("scala.runtime.AbstractFunction", MaxFunctionArity, 0)
lazy val AbstractFunctionType = mkArityArray("scala.runtime.AbstractFunction", MaxAbstractFunctionArity, 0)
val AbstractFunctionClassPerRun = new PerRun[Array[Symbol]](implicit ctx => AbstractFunctionType.map(_.symbol.asClass))
def AbstractFunctionClass(n: Int)(implicit ctx: Context) = AbstractFunctionClassPerRun()(ctx)(n)
lazy val FunctionType = mkArityArray("scala.Function", MaxFunctionArity, 0)
Expand Down
21 changes: 21 additions & 0 deletions src/scala/Function23.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala


/** A function of 23 parameters. Used as a temporary fix until arity limit is dropped.
*
*/
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 =>
/** Apply the body of this function to the arguments.
* @return the result of function application.
*/
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

override def toString() = "<function23>"
}
21 changes: 21 additions & 0 deletions src/scala/Function24.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala


/** A function of 24 parameters. Used as a temporary fix until arity limit is dropped.
*
*/
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 =>
/** Apply the body of this function to the arguments.
* @return the result of function application.
*/
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

override def toString() = "<function24>"
}
7 changes: 7 additions & 0 deletions tests/pos/i1385.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
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 = {
(a: Int) => { // This lambda ends with 23 parameters (c1 to c22 and a)
c22; c21; c20; c19; c18; c17; c16; c15; c14; c13; c12; c11; c10; c9; c8; c7; c6; c5; c4; c3; c2; c1
}
}
}