[jira] [Assigned] (GROOVY-9320) Support serializable lambda expression

2019-12-04 Thread Paul King (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King reassigned GROOVY-9320:
-

Assignee: Daniel Sun

> Support serializable lambda expression
> --
>
> Key: GROOVY-9320
> URL: https://issues.apache.org/jira/browse/GROOVY-9320
> Project: Groovy
>  Issue Type: Improvement
>Reporter: Daniel Sun
>Assignee: Daniel Sun
>Priority: Major
> Fix For: 3.0.0-rc-2
>
>  Time Spent: 40m
>  Remaining Estimate: 0h
>
> Here is a word count example for Flink.
> As groovy's lambda expression is not serializable, the following code has to 
> be replaced with {{sum(1)}} as workaround, or 
> {{java.io.NotSerializableException: Non-serializable lambda}} will be raised.
> https://github.com/danielsun1106/flink-wordcount/blob/0.1/src/main/groovy/me/sunlan/flinklabs/wordcount/WordCount.groovy#L49
> We need generate a synthetic method {{$deserializeLambda$}} in bytecode like 
> the following:
> {code:java}
>   private static synthetic 
> $deserializeLambda$(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
>L0
> LINENUMBER 3 L0
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodName 
> ()Ljava/lang/String;
> ASTORE 1
> ICONST_M1
> ISTORE 2
> ALOAD 1
> INVOKEVIRTUAL java/lang/String.hashCode ()I
> LOOKUPSWITCH
>   -50212388: L1
>   default: L2
>L1
>FRAME APPEND [java/lang/String I]
> ALOAD 1
> LDC "lambda$main$9f099bdf$1"
> INVOKEVIRTUAL java/lang/String.equals (Ljava/lang/Object;)Z
> IFEQ L2
> ICONST_0
> ISTORE 2
>L2
>FRAME SAME
> ILOAD 2
> LOOKUPSWITCH
>   0: L3
>   default: L4
>L3
>FRAME SAME
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodKind ()I
> BIPUSH 6
> IF_ICMPNE L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceClass 
> ()Ljava/lang/String;
> LDC "java/lang/Runnable"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodName 
> ()Ljava/lang/String;
> LDC "run"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodSignature 
> ()Ljava/lang/String;
> LDC "()V"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplClass 
> ()Ljava/lang/String;
> LDC "Test"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodSignature 
> ()Ljava/lang/String;
> LDC "()V"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> INVOKEDYNAMIC run()Ljava/lang/Runnable; [
>   // handle kind 0x6 : INVOKESTATIC
>   
> java/lang/invoke/LambdaMetafactory.altMetafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
>   // arguments:
>   ()V, 
>   // handle kind 0x6 : INVOKESTATIC
>   Test.lambda$main$9f099bdf$1()V, 
>   ()V, 
>   5, 
>   0
> ]
> ARETURN
>L4
>FRAME CHOP 2
> NEW java/lang/IllegalArgumentException
> DUP
> LDC "Invalid lambda deserialization"
> INVOKESPECIAL java/lang/IllegalArgumentException. 
> (Ljava/lang/String;)V
> ATHROW
> MAXSTACK = 3
> MAXLOCALS = 3
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Resolved] (GROOVY-9320) Support serializable lambda expression

2019-12-04 Thread Paul King (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King resolved GROOVY-9320.
---
Resolution: Fixed

Proposed PR merged.

> Support serializable lambda expression
> --
>
> Key: GROOVY-9320
> URL: https://issues.apache.org/jira/browse/GROOVY-9320
> Project: Groovy
>  Issue Type: Improvement
>Reporter: Daniel Sun
>Priority: Major
> Fix For: 3.0.0-rc-2
>
>  Time Spent: 40m
>  Remaining Estimate: 0h
>
> Here is a word count example for Flink.
> As groovy's lambda expression is not serializable, the following code has to 
> be replaced with {{sum(1)}} as workaround, or 
> {{java.io.NotSerializableException: Non-serializable lambda}} will be raised.
> https://github.com/danielsun1106/flink-wordcount/blob/0.1/src/main/groovy/me/sunlan/flinklabs/wordcount/WordCount.groovy#L49
> We need generate a synthetic method {{$deserializeLambda$}} in bytecode like 
> the following:
> {code:java}
>   private static synthetic 
> $deserializeLambda$(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
>L0
> LINENUMBER 3 L0
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodName 
> ()Ljava/lang/String;
> ASTORE 1
> ICONST_M1
> ISTORE 2
> ALOAD 1
> INVOKEVIRTUAL java/lang/String.hashCode ()I
> LOOKUPSWITCH
>   -50212388: L1
>   default: L2
>L1
>FRAME APPEND [java/lang/String I]
> ALOAD 1
> LDC "lambda$main$9f099bdf$1"
> INVOKEVIRTUAL java/lang/String.equals (Ljava/lang/Object;)Z
> IFEQ L2
> ICONST_0
> ISTORE 2
>L2
>FRAME SAME
> ILOAD 2
> LOOKUPSWITCH
>   0: L3
>   default: L4
>L3
>FRAME SAME
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodKind ()I
> BIPUSH 6
> IF_ICMPNE L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceClass 
> ()Ljava/lang/String;
> LDC "java/lang/Runnable"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodName 
> ()Ljava/lang/String;
> LDC "run"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL 
> java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodSignature 
> ()Ljava/lang/String;
> LDC "()V"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplClass 
> ()Ljava/lang/String;
> LDC "Test"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> ALOAD 0
> INVOKEVIRTUAL java/lang/invoke/SerializedLambda.getImplMethodSignature 
> ()Ljava/lang/String;
> LDC "()V"
> INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z
> IFEQ L4
> INVOKEDYNAMIC run()Ljava/lang/Runnable; [
>   // handle kind 0x6 : INVOKESTATIC
>   
> java/lang/invoke/LambdaMetafactory.altMetafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
>   // arguments:
>   ()V, 
>   // handle kind 0x6 : INVOKESTATIC
>   Test.lambda$main$9f099bdf$1()V, 
>   ()V, 
>   5, 
>   0
> ]
> ARETURN
>L4
>FRAME CHOP 2
> NEW java/lang/IllegalArgumentException
> DUP
> LDC "Invalid lambda deserialization"
> INVOKESPECIAL java/lang/IllegalArgumentException. 
> (Ljava/lang/String;)V
> ATHROW
> MAXSTACK = 3
> MAXLOCALS = 3
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[GitHub] [groovy] paulk-asert commented on issue #1110: GROOVY-9320: Support serializable lambda expression

2019-12-04 Thread GitBox
paulk-asert commented on issue #1110: GROOVY-9320: Support serializable lambda 
expression
URL: https://github.com/apache/groovy/pull/1110#issuecomment-561855679
 
 
   Merged. Thanks!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [groovy] asfgit closed pull request #1110: GROOVY-9320: Support serializable lambda expression

2019-12-04 Thread GitBox
asfgit closed pull request #1110: GROOVY-9320: Support serializable lambda 
expression
URL: https://github.com/apache/groovy/pull/1110
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[jira] [Updated] (GROOVY-9328) Cannot call private method of containing class in @CS

2019-12-04 Thread Daniil Ovchinnikov (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniil Ovchinnikov updated GROOVY-9328:
---
Description: 
{code:java}
class C {

private C() {}
private privateMethod() {}

def anonymousUsage() {
new Runnable() {
@groovy.transform.CompileStatic
@Override
void run() {
privateMethod()
new C()
}
}
}
}{code}
Expected: code is compiled without errors.
 Actual: 2  errors:
{{Cannot call private method C#privateMethod from class C$1}}
{{Cannot call private constructor for C from class C$1}}

Note that Java compiles the same code just fine.

  was:
{code:java}
class C {

private privateMethod() {}

def anonymousUsage() {
new Runnable() {
@groovy.transform.CompileStatic
@Override
void run() {
privateMethod()
}
}
}
} {code}
Expected: code is compiled without errors.
 Actual: {{Cannot call private method C#privateMethod from class C$1}}

Note that Java compiles the same code just fine.


> Cannot call private method of containing class in @CS
> -
>
> Key: GROOVY-9328
> URL: https://issues.apache.org/jira/browse/GROOVY-9328
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.8
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:java}
> class C {
> private C() {}
> private privateMethod() {}
> def anonymousUsage() {
> new Runnable() {
> @groovy.transform.CompileStatic
> @Override
> void run() {
> privateMethod()
> new C()
> }
> }
> }
> }{code}
> Expected: code is compiled without errors.
>  Actual: 2  errors:
> {{Cannot call private method C#privateMethod from class C$1}}
> {{Cannot call private constructor for C from class C$1}}
> Note that Java compiles the same code just fine.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (GROOVY-9328) Cannot call private member of containing class in @CS

2019-12-04 Thread Daniil Ovchinnikov (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniil Ovchinnikov updated GROOVY-9328:
---
Summary: Cannot call private member of containing class in @CS  (was: 
Cannot call private method of containing class in @CS)

> Cannot call private member of containing class in @CS
> -
>
> Key: GROOVY-9328
> URL: https://issues.apache.org/jira/browse/GROOVY-9328
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.8
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:java}
> class C {
> private C() {}
> private privateMethod() {}
> def anonymousUsage() {
> new Runnable() {
> @groovy.transform.CompileStatic
> @Override
> void run() {
> privateMethod()
> new C()
> }
> }
> }
> }{code}
> Expected: code is compiled without errors.
>  Actual: 2  errors:
> {{Cannot call private method C#privateMethod from class C$1}}
> {{Cannot call private constructor for C from class C$1}}
> Note that Java compiles the same code just fine.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (GROOVY-9328) Cannot call private method of containing class in @CS

2019-12-04 Thread Daniil Ovchinnikov (Jira)


 [ 
https://issues.apache.org/jira/browse/GROOVY-9328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniil Ovchinnikov updated GROOVY-9328:
---
Description: 
{code:java}
class C {

private privateMethod() {}

def anonymousUsage() {
new Runnable() {
@groovy.transform.CompileStatic
@Override
void run() {
privateMethod()
}
}
}
} {code}
Expected: code is compiled without errors.
 Actual: {{Cannot call private method C#privateMethod from class C$1}}

Note that Java compiles the same code just fine.

  was:
{code:java}
class C {

private privateMethod() {}

def anonymousUsage() {
new Runnable() {
@groovy.transform.CompileStatic
@Override
void run() {
privateMethod()
}
}
}
} {code}
Expected: code is compiled without errors.
Actual: {{Cannot call private method C#privateMethod from class C$1}}


> Cannot call private method of containing class in @CS
> -
>
> Key: GROOVY-9328
> URL: https://issues.apache.org/jira/browse/GROOVY-9328
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
>Affects Versions: 2.5.8
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code:java}
> class C {
> private privateMethod() {}
> def anonymousUsage() {
> new Runnable() {
> @groovy.transform.CompileStatic
> @Override
> void run() {
> privateMethod()
> }
> }
> }
> } {code}
> Expected: code is compiled without errors.
>  Actual: {{Cannot call private method C#privateMethod from class C$1}}
> Note that Java compiles the same code just fine.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (GROOVY-9328) Cannot call private method of containing class in @CS

2019-12-04 Thread Daniil Ovchinnikov (Jira)
Daniil Ovchinnikov created GROOVY-9328:
--

 Summary: Cannot call private method of containing class in @CS
 Key: GROOVY-9328
 URL: https://issues.apache.org/jira/browse/GROOVY-9328
 Project: Groovy
  Issue Type: Bug
  Components: Static Type Checker
Affects Versions: 2.5.8
Reporter: Daniil Ovchinnikov


{code:java}
class C {

private privateMethod() {}

def anonymousUsage() {
new Runnable() {
@groovy.transform.CompileStatic
@Override
void run() {
privateMethod()
}
}
}
} {code}
Expected: code is compiled without errors.
Actual: {{Cannot call private method C#privateMethod from class C$1}}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (GROOVY-9327) @CompileStatic is not propagated to anonymous class

2019-12-04 Thread Daniil Ovchinnikov (Jira)
Daniil Ovchinnikov created GROOVY-9327:
--

 Summary: @CompileStatic is not propagated to anonymous class
 Key: GROOVY-9327
 URL: https://issues.apache.org/jira/browse/GROOVY-9327
 Project: Groovy
  Issue Type: Bug
  Components: Static compilation, Static Type Checker
Affects Versions: 2.5.8
Reporter: Daniil Ovchinnikov


{code:java}
@groovy.transform.CompileStatic
def method() {
new Runnable() {
@Override
void run() {
foo // invalid reference
}
}
} {code}
Expected: Error:(6, 13) Groovyc: [Static type checking] - The variable [foo] is 
undeclared.
Actual: no error is reported.

Note that annotating {{run}} method works properly, i.e. the error is reported.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (GROOVY-9323) AST for precompiled classes loaded from the classpath does not contain constructor annotation information

2019-12-04 Thread Marcin Erdmann (Jira)


[ 
https://issues.apache.org/jira/browse/GROOVY-9323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16987674#comment-16987674
 ] 

Marcin Erdmann commented on GROOVY-9323:


Of course it's ok. Thanks for fixing this! I had a look at your fix Paul and it 
seems that it didn't require a lot of work which is great.

> AST for precompiled classes loaded from the classpath does not contain 
> constructor annotation information
> -
>
> Key: GROOVY-9323
> URL: https://issues.apache.org/jira/browse/GROOVY-9323
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler
>Affects Versions: 2.4.17, 2.5.8, 3.0.0-rc-1
>Reporter: Marcin Erdmann
>Assignee: Paul King
>Priority: Major
> Fix For: 2.5.9, 3.0.0-rc-2
>
>
> It looks like constructor annotation information is not populated in the AST 
> for classes loaded from the classpath in this block of code in 
> {{org.codehaus.groovy.vmplugin.v5.Java5#configureClassNode}}: 
> https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java#L388.
>  What seems to be missing are calls to {{setAnnotationMetaData()}} like in 
> the block above for methods.
> I found this bug accidentally when using 
> {{@InheritConstructors(constructorAnnotations = true))}} and not seeing the 
> annotations copied onto inherited constructors in some cases which turned out 
> to be when the superclass of the class annotated with 
> {{@InheritConstructors}} is not part of the compiled sources but is loaded 
> from a jar.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)