deduplicating lambda methods
Vicente Romero
vicente.romero at oracle.com
Fri Mar 16 19:21:13 UTC 2018
hum, that one lost the format, reformatting:
Hi Liam,
Thanks for the updates to the patch. I also agree with Maurizio about
using TreeScanner. Additional comment: TreeHasher should skip
parenthesis of expressions, to obtain the same hash for, for example:
return (i + j); and return i + j;
Also, as a bonus, consider constant expressions, we probably want:
return 5; and return 2 + 3; to be equal.
I think that these two use cases will need a "normalization" step to be
applied to the tree and store in the map, set, only a normalized version
of the tree. I understand that at least considering constants could be
out of the scope of this patch, so I can see it as a follow up development.
Thanks,
Vicente
On 03/16/2018 03:17 PM, Vicente Romero wrote:
> Hi Liam, Thanks for the updates to the patch. I also agree with
> Maurizio about using TreeScanner. Additional comment: TreeHasher
> should skip parenthesis of expressions, to obtain the same hash for,
> for example: return (i + j); and return i + j; Also, as a bonus,
> consider constant expressions, we probably want: return 5; and return
> 2 + 3; to be equal. I think that these two use cases will need a
> "normalization" step to be applied to the tree and store in the map,
> set, only a normalized version of the tree. I understand that at least
> considering constants could be out of the scope of this patch, so I
> can see it as a follow up development. Thanks, Vicente
>
>
>
> On 03/16/2018 02:46 PM, Maurizio Cimadamore wrote:
>>
>>
>> On 16/03/18 00:36, Liam Miller-Cushon wrote:
>>> Thanks, I'll investigate that. My initial impression is that using
>>> fields
>>> to replace the return value and the second parameter of the visit
>>> methods
>>> in TreeVisitor will complicate control flow somewhat.
>>>
>>> Have you considered adding a TreeVisitor-like API that for JCTrees
>>> to javac?
>> Having a tree scanner accepting a visitor parameter would be good -
>> although can be done outside the scope of this patch.
>>
>> Note that, in the meantime, it's rather easy to mimic the visitor
>> parameter idiom - just define a 'scan' method like this:
>>
>> ```
>> Object parameter; //visitor field
>>
>> scan(JCTree tree, Object parameter) {
>> Object prev = this.parameter;
>> try {
>> this.parameter = parameter;
>> super.scan(tree);
>> } finally {
>> this.parameter = prev;
>> }
>> }
>> ```
>>
>> And then your code should not be altered much (I hope! :-)).
>>
>> Maurizio
>>
>
More information about the amber-dev
mailing list