[vector] Non capturing lambda

Viswanathan, Sandhya sandhya.viswanathan at intel.com
Thu Feb 28 01:23:32 UTC 2019


Hi Vladimir,

The whole of work suggested by Brian to make Species more as values is dependent on this e.g. moving the fromByteArray, fromArray etc methods from XxxNnnSpecies to XxxVector (Int128Species to IntVector as an example). The methods cannot be moved to XxxNnnVector as the concrete classes are not to be made visible to the user. 

Is this a requirement that the lambda be non capturing? I know you added this check recently. What are the downsides? There must be some way, there always is usually :).

Best Regards,
Sandhya



-----Original Message-----
From: Vladimir Ivanov [mailto:vladimir.x.ivanov at oracle.com] 
Sent: Wednesday, February 27, 2019 5:08 PM
To: Viswanathan, Sandhya <sandhya.viswanathan at intel.com>; panama-dev at openjdk.java.net
Cc: Brian Goetz <brian.goetz at oracle.com>; John Rose <john.r.rose at oracle.com>
Subject: Re: [vector] Non capturing lambda

Hi Sandhya,

> The question I have is why is the following lambda considered a 
> capturing lambda?  The "species" is a parameter so cannot be 
> capturing, am I correct? The rest of the lambda is as before.
> 
>                                       (c, idx) -> species.op(n -> 
> c[idx
> + n])

'species' isn't a lambda parameter. It's a part of context and has to be captured, since it is used in the lambda body.

In order to keep lambdas which represents default implementations non-capturing, only its arguments and static fields are allowed to be used.

I don't see an easy way to fix that without introducing new VectorIntrinsics variants to pass 'species' instance into default implementation.

I suggest to move the implementation back to Species and call it from XxxVector instead.

Best regards,
Vladimir Ivanov


More information about the panama-dev mailing list