"Model 2" prototype status

John Altidor jgaltidor at gmail.com
Tue Sep 1 02:04:14 UTC 2015

Hi Brian,

I am new to this mailing list.  My PhD dissertation covered subtyping with
variance and Java wildcards extensively, so the questions you raised in
this thread are very interesting to me.  I was wondering how you are
handling the translational aspects of wildcards and specialized generic

Your earlier post asked how to represent List<any> in bytecode.  Since
List<any> is a supertype of both List<int> and List<double>, for example,
type List<any> should only support operations that can be applied to both
List<int> and List<double>.  One such operation is counting the number of
elements using method List.size().  Which byte representation would support
being able to dispatch List.size() on both an instance of List<int> and an
instance of List<double>?

It seems such a byte representation would need to be independent of fields.
  The number of bytes needed to represent an instance differs among
primitive types (e.g. int and double).  As a result, it seems List<int> and
List< double> may differ in the number of bytes needed for their fields.
In that case, one could not know the number of bytes in the instance of
List<any> returned from the following method:

List<any> func(int input_num) {
  if(input_num is odd)
    return new List<int>();
    return new List<double>();

In addition to type-independent methods such as List.size(), another
operation that is type safe to allow on an instance of List<any> is
wildcard capture.  Consider the generic method, swapFirstTwo, below that
just swaps the order of the first two elements in the input list.  It is
type safe to pass an instance of List<any> to this method (because no
runtime type error would occur).

<any T> void swapFirstTwo(List<T> list) {
  T first = list.getAndRemoveFirst();
  T second = list.getAndRemoveFirst();

Would two calls to method swapFirstTwo, one with a List<int> as input and
the other method call with a List<double> as input, result in two
specialized copies of method swapFirstTwo in byte code?  If that is the
case, what is the byte representation of method swapFirstTwo when the input
is an instance of List<any>?

Thank you,
John Altidor

More information about the valhalla-dev mailing list