[External] : Re: Consolidating the user model

Brian Goetz brian.goetz at oracle.com
Wed Nov 3 18:34:52 UTC 2021


There's lots of great stuff on subtyping in chapters 15 and 16 of TAPL 
(esp 15.6, "Coercion semantics"), which might be helpful.  But as a 
tl;dr, I would suggest treating subtyping strictly as an is-a relation 
within our nominal type system.  By this interpretation, int <! long, 
and int <! Object; these are both _conversions_.

Subtyping is a very strong condition, because it is transitive. 
Conversions allows finer-grained, more ad-hoc conversions.  So we view 
int to long as a "primitive widening conversion" (JLS 5) and int to 
Object today as a boxing conversion.

Note too that the JVM and language have different type systems; ideally 
the two form an embedding-projection pair, so that we can do our type 
checking in the rich type system and erase it down to the more limited 
type system of the VM without loss of correctness.



On 11/3/2021 2:07 PM, John Rose wrote:
> On Nov 3, 2021, at 10:23 AM, Kevin Bourrillion <kevinb at google.com> wrote:
>>
>> I think this fits neatly with the current design: `Point` has no 
>> supertypes*, not even `Object`, but `Point.ref` does.
>>
>> (*I mean "supertype" in the polymorphic sense, not the "has a 
>> conversion" sense or the "can inherit" sense. I don't know what the 
>> word is really supposed to mean. :-))
>
> Slippery terms.  “Type” is hopelessly broad as is “super type”.
>
> For types as value sets, a super type is a value super set.
> Again, int <: long in this view, and even in the JLS.
>
> For types as in an object hierarchy, a super type is a parent+
> type, an upper limit in the hierarchy lattice.  That view
> centers on object polymorphism and virtual methods,
> and is suspiciously bound up with pointer polymorphism.
> So String <: Object in this view.
>
> To heal the rift we are groping towards int <: Object, but
> we don’t fully know which kind of “<:” that is, and how
> it breaks down into a value set super, an object hierarchy
> super, or perhaps something further.  The best view we
> have so far, IMO, is that int <: Object breaks apart into
> int <: int.ref (value set) and int.ref <: Object (hierarchy).
> In that view, the last link of int <: int.ref requires a
> story of how methods “inherit” across value sets,
> without the benefit of a pointer-polymorphic hierarchy
> to inherit within.  It’s doable, but we are running
> into the sub-problems of this task.
>


More information about the valhalla-spec-observers mailing list