That seems similar to my proposal, only you're doing it in GenJsAST.
You'll still need to the makeLambda() trick to allow it to work as a
regular obejct as well, with hashCode()/equals()/getClass()
properties, as well as castMap installed. But if you use static method
delegation, the size won't be as ideal if the static method doesn't
inline.

You want something like x -> 42 + capture to compile to
makeLambda(function(x) { return 42 + capture }, castMap, classLit),
not function(x) { return Class.foo(capture, x); } do you not?


On Mon, Apr 18, 2016 at 9:49 AM, 'Roberto Lublinerman' via GWT
Contributors <google-web-toolkit-contributors@googlegroups.com> wrote:
> The scheme I had in mind does not modify much the Java AST representation
> but is more in the lowering to the JsAST, basically it boils down the the
> following:.
> 1. You create the lambda body as a static method of the class where it
> appears. This static method has all captures as parameters (thiis is very
> similar as we are doing today).
> 2. Synthesize an anonymous inner class that implement the JsFunciton (also
> same as we are doing now). The compiler in the java phase sees this as an
> innerclass.
> 3. Emit the following code for new JsFuncitonimplementation(capture1,
> capture2) as function(par1, par2, parn) ->
> {Class.lambdaFunctionImplementation(capture1, capture2, par1, par2, parn) }.
> 4. Do not emit any code for the anonymous inner class.
>
> This function will behave as if it was a native function passed from JS, and
> object methods will work in the same way. Of course the devil is in the
> details.
>
>
> On Mon, Apr 18, 2016 at 9:34 AM, 'Ray Cromwell' via GWT Contributors
> <google-web-toolkit-contributors@googlegroups.com> wrote:
>>
>> Seems to me this'll be tricky to pull off. The GWT compiler has no
>> notion of captured scope. If you want to create a class type that
>> represents a lambda, but which doesn't actually get output as a class,
>> you'd have to change many many parts of the compiler.
>>
>> I think perhaps the best thing you could do would be a kind of
>> 'peephole' optimization pass. After all Java optimization passes have
>> run, and after JS has been generated, go through using pattern
>> matching to find "new generatedlambda(captured variables)" and replace
>> it with "makeLambda(classtype, castMap, classLiteral, function(...) {
>> body of single abstract method })". Then hope the JS dead code pruning
>> removes the unused inner class.
>>
>> I think if you try to model this in the Java AST it would impact too much
>> stuff.
>>
>>
>> On Mon, Apr 18, 2016 at 9:04 AM, 'Roberto Lublinerman' via GWT
>> Contributors <google-web-toolkit-contributors@googlegroups.com> wrote:
>> > We accept patches :)
>> >
>> > On Sun, Apr 17, 2016 at 8:40 PM, Paul Stockley <pstockl...@gmail.com>
>> > wrote:
>> >>
>> >> Given that it will be realistically a couple of years before most large
>> >> projects could migrate to J2CL, it would be really nice to have a more
>> >> optimal code generation for lambda's, especially for JsFunction. When
>> >> 2.8
>> >> gets released, I think people will really start taking advantage of
>> >> existing
>> >> JS libraries that really heavily use functions.
>> >>
>> >>
>> >> On Friday, April 15, 2016 at 12:03:12 PM UTC-4, Roberto Lublinerman
>> >> wrote:
>> >>>
>> >>> It should not be hard to make JsFunction lambdas more terse, but there
>> >>> are no plans for GWT 2.x.
>> >>>
>> >>>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "GWT Contributors" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/google-web-toolkit-contributors/d75d8079-463a-4334-8c3c-75f11cc9ab20%40googlegroups.com.
>> >>
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "GWT Contributors" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAC7T7g%3DkH9YQjA_P02ibv-Fg4u-gRW6s4Ojm6S2KgTK0KDOYmQ%40mail.gmail.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "GWT Contributors" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAPVRV7csJ3vykGQ1rt%2BSTZtYL0cwjMH8zzY0zgiHszfETPg4Dw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAC7T7gngwS13pEuSHWSMZAtcScTPwuH8tKRNGT7fQMBxa_S2jQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAPVRV7f5mmKx9pYCM_Z7sHvvZU21ztgisNf_xps_YXn95CGWFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to