diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-30 14:02:26 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-30 14:23:46 -0700 |
commit | 7025be9a468419ca6076d78f8da32c6a667fc829 (patch) | |
tree | e6ed17b36b80172d9572c0f40163ece1c07327d1 | |
parent | aec2b940cfa04843efe2eab00272557823fd8dd2 (diff) | |
download | scala-7025be9a468419ca6076d78f8da32c6a667fc829.tar.gz scala-7025be9a468419ca6076d78f8da32c6a667fc829.tar.bz2 scala-7025be9a468419ca6076d78f8da32c6a667fc829.zip |
Bring back AbstractFunction parent
Jason points out we still need it for bytecode efficiency,
due to mixin forwarders.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 6 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Definitions.scala | 1 | ||||
-rw-r--r-- | test/files/run/delambdafy_uncurry_byname_inline.check | 2 | ||||
-rw-r--r-- | test/files/run/delambdafy_uncurry_inline.check | 2 | ||||
-rw-r--r-- | test/files/run/t6028.check | 6 | ||||
-rw-r--r-- | test/files/run/t6555.check | 2 |
6 files changed, 11 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index 227d395036..0786ceb7c2 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -310,9 +310,13 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { newDefDef(methSym, moveToMethod(useMethodParams(fun.body)))(tpt = TypeTree(resTp)) } + // TODO: the rewrite to AbstractFunction is superfluous once we compile FunctionN to a SAM type (aka functional interface) + def functionClassType(fun: Function): Type = + if (isFunctionType(fun.tpe)) abstractFunctionType(fun.vparams.map(_.symbol.tpe), fun.body.tpe.deconst) + else fun.tpe def expandFunction(localTyper: analyzer.Typer)(fun: Function, inConstructorFlag: Long): Tree = { - val parents = addSerializable(fun.tpe) + val parents = addSerializable(functionClassType(fun)) val anonClass = fun.symbol.owner newAnonymousFunctionClass(fun.pos, inConstructorFlag) addAnnotation SerialVersionUIDAnnotation // The original owner is used in the backend for the EnclosingMethod attribute. If fun is diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index e9baa47d82..8074b448fe 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -581,6 +581,7 @@ trait Definitions extends api.StandardDefinitions { /** Creators for TupleN, ProductN, FunctionN. */ def tupleType(elems: List[Type]) = TupleClass.specificType(elems) def functionType(formals: List[Type], restpe: Type) = FunctionClass.specificType(formals, restpe) + def abstractFunctionType(formals: List[Type], restpe: Type) = AbstractFunctionClass.specificType(formals, restpe) def wrapArrayMethodName(elemtp: Type): TermName = elemtp.typeSymbol match { case ByteClass => nme.wrapByteArray diff --git a/test/files/run/delambdafy_uncurry_byname_inline.check b/test/files/run/delambdafy_uncurry_byname_inline.check index e1ee4c29e2..d96a995f44 100644 --- a/test/files/run/delambdafy_uncurry_byname_inline.check +++ b/test/files/run/delambdafy_uncurry_byname_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(x: () => Int): Int = x.apply(); def foo(): Int = Foo.this.bar({ - @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends Object with () => Int with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable { def <init>(): <$anon: () => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/delambdafy_uncurry_inline.check b/test/files/run/delambdafy_uncurry_inline.check index 479e9409fa..5521cc4a2c 100644 --- a/test/files/run/delambdafy_uncurry_inline.check +++ b/test/files/run/delambdafy_uncurry_inline.check @@ -7,7 +7,7 @@ package <empty> { }; def bar(): Unit = { val f: Int => Int = { - @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends Object with Int => Int with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index f21b77fdc7..532d177300 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -24,10 +24,9 @@ package <empty> { (new <$anon: Function0>(T.this, tryyParam, tryyLocal): Function0) } }; - @SerialVersionUID(value = 0) final <synthetic> class $anonfun$foo$1 extends Object with Function0$mcI$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { def <init>($outer: T, methodParam$1: Int, methodLocal$1: Int): <$anon: Function0> = { $anonfun$foo$1.super.<init>(); - $anonfun$foo$1.super./*Function0*/$init$(); () }; final def apply(): Int = $anonfun$foo$1.this.apply$mcI$sp(); @@ -67,10 +66,9 @@ package <empty> { T.this.MethodLocalObject$lzycompute$1(barParam$1, MethodLocalObject$module$1) else MethodLocalObject$module$1.elem.$asInstanceOf[T#MethodLocalObject$2.type](); - @SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends Object with Function0$mcV$sp with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = { $anonfun$tryy$1.super.<init>(); - $anonfun$tryy$1.super./*Function0*/$init$(); () }; final def apply(): Unit = $anonfun$tryy$1.this.apply$mcV$sp(); diff --git a/test/files/run/t6555.check b/test/files/run/t6555.check index fef689a80d..e3b467ce7c 100644 --- a/test/files/run/t6555.check +++ b/test/files/run/t6555.check @@ -6,7 +6,7 @@ package <empty> { () }; private[this] val f: Int => Int = { - @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends Object with Int => Int with Serializable { + @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () |