Hi all,

there are some thoughts about GEP-27 I want to share.

First of all, compiling lambdas without going through a Closure is a good thing. And I think that should always happen, in static and dynamic code. I do not think that is the implementation in current Groovy 6. What do we actually do if defaults are used for the lambda parameters? I ahve the feeling we may handle this wrong right now.

Closures are more difficult because of the mutable state they carry and because they are initially planed as inner class construct.

PackedClosure as in https://github.com/apache/groovy/pull/2692

Loss of GeneratedClosure.
This is not a marker interface for that we have a Closure generated by the compiler as primary goal. The primary goal is to use this information, that this is a controlled class without possible shenanigans from the user to allow optimizations. Those are lost now. I already commented on the huge amount of basically reflective code in there. There is an abstraction we have for this and that would be MethodHandles. I think It should get a MethodHandle as parameter, with the handle beeing a constant in the hosting class and invoke it. And again here I have to ask how defaults are handled? From the code I see, not at all. The default variant is simply ignored. Of course a single handle would then also not work. I am putting it here because I think the default arguments problem must be discussed.

Then there is a lot of talk in the GEP and the PR about @DelegatesTo indicating a delegation usage. Well, yes, CS can use that, but it really is not enforcing. @DelegatesTo -> setDelegate most likely used, No @DelegateTo -> setDelegate might still be used.


Which leads me to another point. MethodClosure.
In theory MethodClosure is in a similar situation. You cannot effectively set the delegate. ClosureStrategy does not really work. But we have a break in style here. MethodClosure is silently ignoring. PackedClosure not. In theory MethodClosure and PackedClosure are the same beasts, only that in case of PackedClosure we actually know the target method(s) even in dynamic mode fully.

Just to make this clear. I think MethodClosure also needs a rework. But then we should consider aligning PackedClosure and MethodClosure.

What do you think?

bye Jochen

Reply via email to