diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-10-29 16:49:22 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-01-29 16:16:16 +1000 |
commit | df0d105f90816960b711c35a3289ff460295d1cc (patch) | |
tree | a478b92f5ae83d308a97f7f7ccd60c5e38b339ac /test/checker-tests/fail7.scala | |
parent | 8a761a313bfe3d79afefed1622b69a850636d732 (diff) | |
download | scala-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 'test/checker-tests/fail7.scala')
0 files changed, 0 insertions, 0 deletions