summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-10-29 16:49:22 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-01-29 16:16:16 +1000
commitdf0d105f90816960b711c35a3289ff460295d1cc (patch)
treea478b92f5ae83d308a97f7f7ccd60c5e38b339ac /src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
parent8a761a313bfe3d79afefed1622b69a850636d732 (diff)
downloadscala-df0d105f90816960b711c35a3289ff460295d1cc.tar.gz
scala-df0d105f90816960b711c35a3289ff460295d1cc.tar.bz2
scala-df0d105f90816960b711c35a3289ff460295d1cc.zip
Use invokedynamic for structural calls, symbol literals, lamba ser.
The previous encodings created static fields in the enclosing class to host caches. However, this isn't an option once emit code in default methods of interfaces, as Java interfaces don't allow private static fields. We could continue to emit fields, and make them public when added to traits. Or, as chosen in this commit, we can emulate a call-site specific static field by using invokedynamic: when the call site is linked, our bootstrap methid can perform one-time computation, and we can capture the result in the CallSite. To implement this, I've allowed encoding of arbitrary invokedynamic calls in ApplyDynamic. The encoding is: ApplyDynamic( NoSymbol.newTermSymbol(TermName("methodName")).setInfo(invokedType) Literal(Constant(bootstrapMethodSymbol)) :: ( Literal(Constant(staticArg0)) :: Literal(Constant(staticArgN)) :: Nil ) ::: (dynArg0 :: dynArgN :: Nil) ) So far, static args may be `MethodType`, numeric or string literals, or method symbols, all of which can be converted to constant pool entries. `MethodTypes` are transformed to the erased JVM type and are converted to descriptors as String constants. I've taken advantage of this for symbol literal caching and for the structural call site cache. I've also included a test case that shows how a macro could target this (albeit using private APIs) to cache compiled regexes. I haven't managed to use this for LambdaMetafactory yet, not sure if the facility is general enough.
Diffstat (limited to 'src/reflect/scala/reflect/runtime/JavaUniverseForce.scala')
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index d6b611a3f4..ba85630dbc 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -282,6 +282,9 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.MethodClass
definitions.EmptyMethodCacheClass
definitions.MethodCacheClass
+ definitions.StructuralCallSite
+ definitions.StructuralCallSite_dummy
+ definitions.SymbolLiteral
definitions.ScalaXmlTopScope
definitions.ScalaXmlPackage
definitions.ReflectPackage