This page is no longer maintained — Please continue to the home page at www.scala-lang.org

scalac generating annotations

3 replies
Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
Hi,
There was a thread on the users ml about scalac not currently being able to generate runtime (or retained?) annotation classes. One of the sticking points raised was the lack of support for emitting the bytecode for annotations. I've had a quick dive into scalac, and it looks like it uses fjbg for bytecode generation. I've written bytecode generators before, including one that dealt with annotations. However, before I started getting to know fjbg I wanted to check some things.
1. Is fjbg the library that's currently used by scalac for bytecode generation? It certainly seems that way from following things through from the nsc scala source.
2. I've made a cursory search through fjbg and can't find any support whatsoever for representing annotations. I may be being blind. If fjbg is being used this confuses me as last I checked, you could annotate scala code with annotations that where then available to the JVM at run-time. I've had a dig through for occurrences of ACC_ANNOTATION and 0x2000 but not found anything that looks like annotation-writing code. What am I missing?
3. Are there any intentions of moving to one of the 3rd party, off-the-shelf libraries that already have all this stuff implemented and working?
4. Is there a plan to use a bytecode generator implemented in Scala rather than Java? If so, will fjbg be retired?

I'm looking at svn revision 25081, which should be the newest trunk I think.
Thanks,
Matthew
--
Matthew Pocockmailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.ukirc.freenode.net: drdozer (0191) 2566550
Alex Cruise
Joined: 2008-12-17,
User offline. Last seen 2 years 26 weeks ago.
Re: scalac generating annotations
nsc will correctly compile *Scala files* that use *Java annotations* in such a way that Java reflection will see them in the idiomatic way.
However, there's currently no way to *write, in Scala*, a Java-reflection-compatible *annotation class*.  Nor, to my knowledge, is there any way to test, at runtime, for the presence of a Scala-defined annotation.
What are all these .java files doing in my Scala codebase?  Annotations and enums. That's pretty much it.
-0xe1a

On Mon, Jun 13, 2011 at 3:08 AM, Matthew Pocock <turingatemyhamster@gmail.com> wrote:
Hi,
There was a thread on the users ml about scalac not currently being able to generate runtime (or retained?) annotation classes. One of the sticking points raised was the lack of support for emitting the bytecode for annotations. I've had a quick dive into scalac, and it looks like it uses fjbg for bytecode generation. I've written bytecode generators before, including one that dealt with annotations. However, before I started getting to know fjbg I wanted to check some things.
1. Is fjbg the library that's currently used by scalac for bytecode generation? It certainly seems that way from following things through from the nsc scala source.
2. I've made a cursory search through fjbg and can't find any support whatsoever for representing annotations. I may be being blind. If fjbg is being used this confuses me as last I checked, you could annotate scala code with annotations that where then available to the JVM at run-time. I've had a dig through for occurrences of ACC_ANNOTATION and 0x2000 but not found anything that looks like annotation-writing code. What am I missing?
3. Are there any intentions of moving to one of the 3rd party, off-the-shelf libraries that already have all this stuff implemented and working?
4. Is there a plan to use a bytecode generator implemented in Scala rather than Java? If so, will fjbg be retired?

I'm looking at svn revision 25081, which should be the newest trunk I think.
Thanks,
Matthew
--
Matthew Pocockmailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.ukirc.freenode.net: drdozer (0191) 2566550

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: scalac generating annotations
Hi Matthew,
On Mon, Jun 13, 2011 at 12:08, Matthew Pocock <turingatemyhamster@gmail.com> wrote:
Hi,
There was a thread on the users ml about scalac not currently being able to generate runtime (or retained?) annotation classes. One of the sticking points raised was the lack of support for emitting the bytecode for annotations. I've had a quick dive into scalac, and it looks like it uses fjbg for bytecode generation. I've written bytecode generators before, including one that dealt with annotations. However, before I started getting to know fjbg I wanted to check some things.
1. Is fjbg the library that's currently used by scalac for bytecode generation?

yes. 
It certainly seems that way from following things through from the nsc scala source.
2. I've made a cursory search through fjbg and can't find any support whatsoever for representing annotations. I may be being blind. If fjbg is being used this confuses me as last I checked, you could annotate scala code with annotations that where then available to the JVM at run-time. I've had a dig through for occurrences of ACC_ANNOTATION and 0x2000 but not found anything that looks like annotation-writing code. What am I missing?

Annotations are serialized in classfiles as "attributes", there doesn't need to be any support for themin the bytecode writing library. see the spec http://download.oracle.com/otndocs/jcp/jcfsu-1.0-fr-eval-oth-JSpec/  

3. Are there any intentions of moving to one of the 3rd party, off-the-shelf libraries that already have all this stuff implemented and working?

no. 

4. Is there a plan to use a bytecode generator implemented in Scala rather than Java? If so, will fjbg be retired?

there was some discussion some time ago to rewrite fjbg in Scala. http://scala-programming-language.1934581.n4.nabble.com/scala-FJBG-port-to-Scala-td1998476.html http://www.drmaciver.com/repos/fjbg/ 

I'm looking at svn revision 25081, which should be the newest trunk I think.
Thanks,
Matthew
--
Matthew Pocockmailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.ukirc.freenode.net: drdozer (0191) 2566550

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: scalac generating annotations

On 6/14/11 12:12 AM, Lukas Rytz wrote:
> there was some discussion some time ago to rewrite fjbg in Scala.
> http://scala-programming-language.1934581.n4.nabble.com/scala-FJBG-port-...
> http://www.drmaciver.com/repos/fjbg/

I did rewrite it in scala way back in 2008 but it was clear it would
never be as fast unless I wrote java-in-scala, which lacked appeal.

https://github.com/paulp-etc/ssbg

I finished it, and had trunk fully bootstrapped with it: but I don't
think I left it in a particularly working state.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland