Updated State of the Specialization
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Sat Dec 20 18:04:54 UTC 2014
What is instantiated type var for T in List<int>? Integer or int
On Sat, Dec 20, 2014 at 3:54 PM, Timo Kinnunen <timo.kinnunen at gmail.com>
wrote:
> Here an anyfied List version and a demo:
>
> interface List<any T> {
> public void remove(int position);
> public void remove(T element);
>
> static void test(List<int> list) {
>
> // calls remove(int position);
> list.remove((int) 3);
>
> // calls remove(T element);
> list.remove(3);
> }
> }
>
> The choice of which method to prefer with the plain, cast-less version is
> somewhat arbitrary. My rationale for preferring it like this rather than
> the other way around is that the specialized type is more interesting. Thus
> the compiler should make calling methods taking one as easy as possible.
>
> --
> Have a nice day,
> Timo.
>
> Sent from Windows Mail
>
> *From:* Ali Ebrahimi <ali.ebrahimi1781 at gmail.com>
> *Sent:* Saturday, December 20, 2014 0:53
> *To:* Timo Kinnunen <timo.kinnunen at gmail.com>
> *Cc:* Brian Goetz <brian.goetz at oracle.com>, valhalla-dev at openjdk.java.net
>
> As long as I know, we currently have List<E> and We try to specialize (or
> any-fy) that.
> How your solution handle List<int> case?
>
>
> On Sat, Dec 20, 2014 at 2:15 AM, Timo Kinnunen <timo.kinnunen at gmail.com>
> wrote:
>>
>> Hi,
>>
>>
>> I’m not sure Peeling is necessary. The reason is that the problem it’s
>> trying to solve already exists in the current Java and it has workarounds
>> too. Here’s a demonstration with three ListLike<T> adaptations and the
>> workarounds:
>>
>>
>> interface SmallList<T> {
>>
>> public void remove(short position);
>>
>> public void remove(T element);
>>
>> }
>>
>> interface MediumList<T> {
>>
>> public void remove(int position);
>>
>> public void remove(T element);
>>
>> }
>>
>> interface BigList<T> {
>>
>> public void remove(BigInteger position);
>>
>> public void remove(T element);
>>
>> }
>>
>>
>> public class Workaround {
>>
>> @SuppressWarnings({ "rawtypes", "unchecked" })
>>
>> static void method(SmallList<Short> smallList, MediumList<Integer>
>> mediumList, BigList<BigInteger> bigList) {
>>
>>
>> smallList.remove((short) 3);
>>
>> smallList.remove((Short) (short) 3);
>>
>>
>> mediumList.remove(3);
>>
>> mediumList.remove((Integer) 3);
>>
>>
>> ((BigList<?>) bigList).remove(BigInteger.valueOf(3));
>>
>> ((BigList) bigList).remove((Object) BigInteger.valueOf(3));
>>
>> }
>>
>> }
>>
>>
>> For the record, none of the workarounds feel “correct” to me, although
>> the int/Integer pair gets close.
>>
>>
>> Rather than Peeling, what I think is needed is to streamline overload
>> selection so that the specialized methods are selected whenever possible
>> and the non-specialized methods can be manually selected with extra casts,
>> like this:
>>
>>
>>
>> smallList.remove((short) 3);
>>
>> smallList.remove(3);
>>
>>
>>
>>
>> mediumList.remove((int) 3);
>>
>> mediumList.remove(3);
>>
>>
>>
>>
>> bigList.remove((BigInteger) BigInteger.valueOf(3));
>>
>> bigList.remove(BigInteger.valueOf(3));
>>
>>
>>
>>
>> --
>> Have a nice day,
>> Timo.
>>
>> Sent from Windows Mail
>>
>>
>>
>>
>>
>> From: Brian Goetz
>> Sent: Friday, December 19, 2014 22:31
>> To: valhalla-dev at openjdk.java.net
>>
>>
>>
>>
>>
>> I've updated the State of the Specialization here:
>> http://cr.openjdk.java.net/~briangoetz/valhalla/specialization.html
>>
>> The old version is here:
>> http://cr.openjdk.java.net/~briangoetz/valhalla/specialization-1.html
>>
>
More information about the valhalla-dev
mailing list