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

marking methods as synthetic in generated bytecode

3 replies
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.

I just noticed that the menagerie of methods synthesized by scalac
generates isn't marked as synthetic in the bytecode.

I couldn't google up prior discussions on this matter. Is this done
deliberately, or by default?

As motivation, the debugger in IntelliJ or Eclipse can be configured
to skip synthetic methods in the "Step Into" action.

-jason

scala> class A { 1 match { case x if x > 0 => x } }
defined class A

scala> classOf[A].getDeclaredMethods
res10: Array[java.lang.reflect.Method] = Array(private final boolean
A.gd1$1(int))

scala> classOf[A].getDeclaredMethods.last.isSynthetic
res11: Boolean = false

scala> class A { def foo(a: Int = 0) = 0 }
defined class A

scala> classOf[A].getDeclaredMethods
res12: Array[java.lang.reflect.Method] = Array(public int A.foo(int),
public int A.foo$default$1())

scala> classOf[A].getDeclaredMethods.last.isSynthetic
res13: Boolean = false

scala> case class A(a: Int)
defined class A

scala> classOf[A].getDeclaredMethods.find(_.getName == "copy").get.isSynthetic
res16: Boolean = false

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: marking methods as synthetic in generated bytecode

On 7/31/11 3:34 AM, Jason Zaugg wrote:
> I just noticed that the menagerie of methods synthesized by scalac
> generates isn't marked as synthetic in the bytecode.
>
> I couldn't google up prior discussions on this matter. Is this done
> deliberately, or by default?

The reasons are here:

https://issues.scala-lang.org/browse/SI-1128

The problem is java interop.

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: marking methods as synthetic in generated bytecode

On Sun, Jul 31, 2011 at 6:57 PM, Paul Phillips wrote:
> On 7/31/11 3:34 AM, Jason Zaugg wrote:
>>
>> I just noticed that the menagerie of methods synthesized by scalac
>> generates isn't marked as synthetic in the bytecode.
>>
>> I couldn't google up prior discussions on this matter. Is this done
>> deliberately, or by default?
>
> The reasons are here:
>
> https://issues.scala-lang.org/browse/SI-1128
>
> The problem is java interop.

Thanks. I'd stumbled over some related tickets on Groovy which stemmed
from the linked thread on jvm-lang.

Perhaps the IDE can be coaxed into using heuristics based on the
method names, instead.

-jason

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: marking methods as synthetic in generated bytecode


On Sun, Jul 31, 2011 at 12:34 PM, Jason Zaugg <jzaugg@gmail.com> wrote:
I just noticed that the menagerie of methods synthesized by scalac
generates isn't marked as synthetic in the bytecode.

I couldn't google up prior discussions on this matter. Is this done
deliberately, or by default?

It's deliberate. I think we experimented very early on with making some of these methods synthetic, but there were some bad interactions with the JVM. Details elude me now, I am afraid. One could try to make some more methods synthetic, but one would have to be very careful.

Cheers

 -- Martin

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