[scala] LocalVariableTable attribute generated by scalac

View: New views
3 Messages — Rating Filter:   Alert me  

[scala] LocalVariableTable attribute generated by scalac

by Guillaume Bort-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I'm trying to enable Scala as a supported language for the Play
framework (http://www.playframework.org) and I have a problem with
the way scalac generates the debug informations to the
LocalVariableTable attribute.

for this method :

def index() {
    val a = 10
    println(a)
}

scalac will generate bytecode like :

0 ldc <10>
2 istore_1
3 ...

and then set the start_pc attribute for the 'a' variable to 0.

For the same code, a Java compiler (at least the eclipse and sun ones)
will set the start_pc attribute to 3.

I just took a look at the class file specification, and it does not
exactly define the value that the start_pc attribute
must contain. It just say that it must be a valid index into the code
array of this Code attribute and must be the index of the opcode of an
instruction.

So I think that the scala generated attribute is perfectly valid.
However I think that it is better to set the start_pc attribute to 3,
because
it is only from this instruction that you can access to this local variable.

What do you think ?

Thank !

Guillaume.

Re: [scala] LocalVariableTable attribute generated by scalac

by Iulian Dragos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You are of course right, it would be much better. There are other
cases where the range of a local variable is not as precise as it
should be. Some of them are because scalac used to keep only the
starting position of a statement, therefore couldn't determine exactly
the scope of a block. Now that's changed and we will emit more precise
scoping for locals in a next release.

In this particular case, it was simply a bug, and it's fixed in trunk.

iulian


On Thu, May 28, 2009 at 3:31 PM, Guillaume Bort
<guillaume.bort@...> wrote:

> Hi all,
>
> I'm trying to enable Scala as a supported language for the Play
> framework (http://www.playframework.org) and I have a problem with
> the way scalac generates the debug informations to the
> LocalVariableTable attribute.
>
> for this method :
>
> def index() {
>    val a = 10
>    println(a)
> }
>
> scalac will generate bytecode like :
>
> 0 ldc <10>
> 2 istore_1
> 3 ...
>
> and then set the start_pc attribute for the 'a' variable to 0.
>
> For the same code, a Java compiler (at least the eclipse and sun ones)
> will set the start_pc attribute to 3.
>
> I just took a look at the class file specification, and it does not
> exactly define the value that the start_pc attribute
> must contain. It just say that it must be a valid index into the code
> array of this Code attribute and must be the index of the opcode of an
> instruction.
>
> So I think that the scala generated attribute is perfectly valid.
> However I think that it is better to set the start_pc attribute to 3,
> because
> it is only from this instruction that you can access to this local variable.
>
> What do you think ?
>
> Thank !
>
> Guillaume.
>



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

Re: [scala] LocalVariableTable attribute generated by scalac

by Guillaume Bort-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

So I just switched to scala 2.7.6 (and tried the 2.7.7 RC2 as well)
and it seems that this bug has reappeared.
Should I still consider this as a bug, or it is expected ?

Thank you!

Guillaume.

On Thu, May 28, 2009 at 3:28 PM, Iulian Dragos <jaguarul@...> wrote:

> You are of course right, it would be much better. There are other
> cases where the range of a local variable is not as precise as it
> should be. Some of them are because scalac used to keep only the
> starting position of a statement, therefore couldn't determine exactly
> the scope of a block. Now that's changed and we will emit more precise
> scoping for locals in a next release.
>
> In this particular case, it was simply a bug, and it's fixed in trunk.
>
> iulian
>
>
> On Thu, May 28, 2009 at 3:31 PM, Guillaume Bort
> <guillaume.bort@...> wrote:
>> Hi all,
>>
>> I'm trying to enable Scala as a supported language for the Play
>> framework (http://www.playframework.org) and I have a problem with
>> the way scalac generates the debug informations to the
>> LocalVariableTable attribute.
>>
>> for this method :
>>
>> def index() {
>>    val a = 10
>>    println(a)
>> }
>>
>> scalac will generate bytecode like :
>>
>> 0 ldc <10>
>> 2 istore_1
>> 3 ...
>>
>> and then set the start_pc attribute for the 'a' variable to 0.
>>
>> For the same code, a Java compiler (at least the eclipse and sun ones)
>> will set the start_pc attribute to 3.
>>
>> I just took a look at the class file specification, and it does not
>> exactly define the value that the start_pc attribute
>> must contain. It just say that it must be a valid index into the code
>> array of this Code attribute and must be the index of the opcode of an
>> instruction.
>>
>> So I think that the scala generated attribute is perfectly valid.
>> However I think that it is better to set the start_pc attribute to 3,
>> because
>> it is only from this instruction that you can access to this local variable.
>>
>> What do you think ?
>>
>> Thank !
>>
>> Guillaume.
>>
>
>
>
> --
> « Je déteste la montagne, ça cache le paysage »
> Alphonse Allais
>