Clarifications on SoV documents
Brian Goetz
brian.goetz at oracle.com
Thu Apr 23 20:37:16 UTC 2020
[ Sending to right EG list this time ]
Srikanth asked me to make a few clarifications on the SoV documents.
I'll summarize them here and then later work them into the docs.
1. Array subtyping. Historically, array covariance worked like this:
if T <: U, then T[] <: U[]
In Valhalla, this is refined to be:
if T.ref <: U, then T[] <: U[]
Because T.ref == T for reference types, this rule generalizes the
previous rule.
There is no inline widening/narrowing conversion between array types;
array types are reference types.
Example:
V[] va = ...
V.ref[] vb = ...
vb = va // allowed by ordinary subtyping
va = vb // not allowed
va = (V[]) vb // allowed, may CCE
2. Bounds checking. If we have a bound:
class Foo<T extends U> { }
then this was historically satisfied if T <: U. In Valhalla, this is
amended in the same way as (1):
X is within bound `T extends U` if X.ref <: U
If `U` is an inline type, the bounds `T extends U` does not make sense,
so is rejected.
3. This story isn't written yet, but where we're aiming (everyone but
Srikanth, please hold questions on "how would that work" until I write
this up) is that inline types can be used as type parameters for erased
generics _without_ having to say `Foo<V.ref>`. This represents a shift
from where we were before, where we didn't allow inlines as type arguments.
More information about the valhalla-spec-observers
mailing list