[foreign] RFR 8210264: cleanup semantics of function pointer conversion
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Sep 14 16:45:30 UTC 2018
FTR, I've just pushed this. I've taken into account the review comments,
and did two things:
* Util.findCallback will now collect all candidates and throw if
|candidates| != 1
* I've added another variant of Scope::allocateCallback which takes an
explicit carrier witness, and amended the javadoc so that it's clear
that the no-carrier version is built on top of the carrier-ful one, with
some inference logic spruced up in the middle.
Thanks
Maurizio
On 01/09/18 04:46, John Rose wrote:
> On Aug 31, 2018, at 9:04 AM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>>
>> http://cr.openjdk.java.net/~mcimadamore/panama/8210264/
>> <http://cr.openjdk.java.net/%7Emcimadamore/panama/8210264/>
>
> This is a good cleanup.
>
> An object is allowed to implement two functional interfaces, and even
> two interfaces which annotated as native callbacks. So it is possible
> that allocateCallback will be presented with an ambiguous input.
> I suggest that Util.findCallback throw an exception in that case,
> instead of returning the first marked FI that that it finds.
>
> This won't harm correct code but will let us exclude some corner
> cases.
>
> Another way to slice this is to require a runtime witness as follows:
>
> <T> Callback<T> allocateCallback(Class<T> funcInt, T funcIntfInstance);
> default <T> Callback<T> allocateCallback(T funcIntfInstance) {
> return
> allocateCallback(Utils.findCallback(funcIntfInstance.getClass()),
> funcIntfInstance);
> }
>
> I.e., allow explicit specification of which FI we care about but specify
> a sensible default. The explicit specification has two effects: First,
> it allows cast-free passing of a lambda, and second it allows the
> approach to scale to non-native FI types (assuming the scope
> has rules for dealing with type conversion).
>
> — John
More information about the panama-dev
mailing list