Struggling with Valhalla conversion of library

Srikanth srikanth.adayapalam at oracle.com
Sun Aug 25 10:31:07 UTC 2019


Hello Philippe,

I have pushed a change set 
http://hg.openjdk.java.net/valhalla/valhalla/rev/e9393b1577db, on behalf of
https://bugs.openjdk.java.net/browse/JDK-8230121 that addresses this 
problem.

Note however that the syntax to be used is:

void doesNotCompile(java.util.Map.Entry<InlineType<? extends K>*?*, ? 
extends V> argument);

Inline types cannot be type arguments as of LW2, only their nullable 
projection types can be. Hence the ?

I do wish to echo Brian's message in another thread:

"The interaction of generic instantiation and the nullable projection 
type are definitely in the corners right now."  and "So while we would 
of course like for these things to work, we're not surprised there are 
pitfalls and interactions"

Thanks for continued testing. I am away all of the coming week on a 
training, but I'll try to provide fixes as soon as possible.

Thanks!
Srikanth



On 17/08/19 8:35 PM, Philippe Marschall wrote:
> Hello Srikanth
>
> I was able to retest with the tip of the lworld branch. I can confirm
> the lambda issue, the first issue, is gone.
>
> As for the second issue I was able to extract this minimal reproducer
>
> interface Sample<K extends Comparable<? super K>, V> {
>
>   void doesCompile(InlineType<? extends K> argument);
>
>   void doesNotCompile(java.util.Map.Entry<InlineType<? extends K>, ?
> extends V> argument);
>
> }
>
> inline class InlineType<E> {
>
>   private E element;
>
>   InlineType(E element) {
>     this.element = element;
>   }
>
> }
>
> The method #doesCompile doe compile but the method #doesNotCompile does
> not compile and instead I get the following error:
>
> error: unexpected type
>   void doesNotCompile(java.util.Map.Entry<InlineType<? extends K>, ?
> extends V> argument);
>                                                     ^
>   required: reference
>   found:    InlineType<? extends K>
>   where K is a type-variable:
>     K extends Comparable<? super K> declared in interface Sample
>
>
> Cheers
> Philippe
>
> On 14.08.19 12:51, Srikanth wrote:
>> Hello Philippe,
>>
>> There has been a further defect fix
>> https://bugs.openjdk.java.net/browse/JDK-8229700 that should also help
>> you. If you are able to test the tip of valhalla repo lworld branch,
>> that is great!
>>
>> If not, I am told this Friday there will a refresh of the EA bits. That
>> should simplify testing for those that don't want to work with source
>> forests.
>>
>> Could you in any case please see if you are able to extract test cases
>> and send them inline in mail ?
>> That would greatly speed up the turn around time for any remaining
>> problems.
>>
>> Appreciate your testing and the defect reports!
>> Srikanth
>>
>> On 14/08/19 2:39 PM, Srikanth wrote:
>>> Hello Philippe,
>>>
>>> With the resolution of
>>> https://bugs.openjdk.java.net/browse/JDK-8229537 via the push
>>> http://hg.openjdk.java.net/valhalla/valhalla/rev/7ec951ef532d at least
>>> the first of your
>>> problems should have been fixed and the explicit lambda version viz:
>>>
>>> public static AdjacencyTester<U96?> adjacencyTester() {
>>>     return (U96? low, U96? high) -> {
>>>       // lambda body
>>>     };
>>>   }
>>>
>>> should compile.
>>>
>>> Can you check with the lworld branch tip of valhalla ?
>>>
>>> I am happy to verify this fix and also investigate a fix for the other
>>> problems you reported.
>>> But it would help if I have test cases extracted and attached to mail
>>> - is that possible ?
>>> I am not familiar with github and having a bit of a bother getting
>>> what I need from the
>>> pointers.
>>>
>>> TIA
>>> Srikanth
>>>
>>> On 05/08/19 3:14 AM, Philippe Marschall wrote:
>>>> Hi
>>>>
>>>> As you published the LW2 prototype I thought I tried to convert one of
>>>> my libraries [1] to Valhalla and see how it goes. Right now I'm
>>>> struggling with generics.
>>>>
>>>> Some context about the library. The library implements a range tree 
>>>> that
>>>> allows to map a range of keys to a single value. Eg. {[100,199] -> 
>>>> "1",
>>>> [200,299] -> "2"}. The library should support both inline and 
>>>> reference
>>>> types as keys and values.
>>>> The potential for inline classes is limited as the tree nodes are
>>>> mutable and recursive. There are however two good candidates, the 
>>>> range
>>>> class and an unsigned 96bit integer class (called U96) that is 
>>>> provided
>>>> for convenience.
>>>>
>>>> The unsigned 96bit integer class  was easy to convert. I had to change
>>>> it to implements Comparable<U96?>. I am not yet sure how I want to 
>>>> treat
>>>> null / 0.
>>>> But there are two cases where I struggled.
>>>>
>>>> First, I have an interface
>>>>
>>>> public interface AdjacencyTester<T> {
>>>>
>>>>   boolean areAdjacent(T low, T high);
>>>>
>>>> }
>>>>
>>>> I want to implement this for the unsigned 96bit integer class (called
>>>> U96). Right know in Java 8 this is implemented as
>>>>
>>>>   public static AdjacencyTester<U96> adjacencyTester() {
>>>>     return (low, high) -> {
>>>>       // lambda body
>>>>     };
>>>>   }
>>>>
>>>> Simply converting this to
>>>>
>>>>   public static AdjacencyTester<U96?> adjacencyTester() {
>>>>     return (low, high) -> {
>>>>       // lambda body
>>>>     };
>>>>   }
>>>>
>>>> did not work, I got
>>>>
>>>> com/github/marschall/rangetree/key/U96.java:[51,12] incompatible 
>>>> types:
>>>> incompatible parameter types in lambda expression
>>>>
>>>> Converting it to an anonymous inner class worked
>>>>
>>>>   public static AdjacencyTester<U96?> adjacencyTester() {
>>>>     return new AdjacencyTester<U96?>() {
>>>>       public boolean areAdjacent(U96? low, U96? high) {
>>>>         // method body
>>>>       }
>>>>     };
>>>>
>>>>   }
>>>>
>>>> Using U96? as types for the lambda arguments did not compile
>>>>
>>>>   public static AdjacencyTester<U96?> adjacencyTester() {
>>>>     return (U96? low, U96? high) -> {
>>>>       // lambda body
>>>>     };
>>>>   }
>>>>
>>>> Compilation failure:
>>>> /src/main/java/com/github/marschall/rangetree/key/U96.java:[51,16] ')'
>>>> expected
>>>> src/main/java/com/github/marschall/rangetree/key/U96.java:[51,21] :
>>>> expected
>>>> src/main/java/com/github/marschall/rangetree/key/U96.java:[51,32] ';'
>>>> expected
>>>>
>>>> Second I have a simple Range class which is supposed to hold both
>>>> reference and inline types. That was easy to convert but integrating
>>>> into my existing interfaces failed.
>>>>
>>>> public inline class Range<E> {
>>>>
>>>>   private E low;
>>>>   private E high;
>>>>
>>>> In my RangeMap interface I have #computeIfAbsent similar to the one 
>>>> from
>>>> Map.
>>>>
>>>> V computeIfAbsent(K key, Function<? super K, Entry<Range<? extends 
>>>> K>, ?
>>>> extends V>> mappingFunction)
>>>>
>>>> src/main/java/com/github/marschall/rangetree/RangeMap.java:[52,59]
>>>> unexpected type
>>>> [ERROR]   required: reference
>>>> [ERROR]   found: com.github.marschall.rangetree.Range<? extends K>
>>>>
>>>> I tried to switch to
>>>> Range<? extends K?>
>>>>
>>>> but that did not help.
>>>>
>>>> You can find the code and building instructions here [2]
>>>>
>>>>  [1] https://github.com/marschall/range-tree
>>>>  [2] https://github.com/marschall/range-tree/tree/valhalla
>>>>
>>>> Cheers
>>>> Philippe
>>>
>>
>>



More information about the valhalla-dev mailing list