Valhalla basic concepts / terminology
daniel.smith at oracle.com
Tue Jun 9 21:18:21 UTC 2020
I think there remain some finer details of the usage of these terms to be nailed down. Here's an overview of how I think about it. (Please note that I'm talking about the language model here. Exactly how this translates into the JVM model is a separate problem.)
- The *values* of the Java Programming Language are *reference values*—references to objects—and *inline values*—the objects themselves. An *object* is either a *class instance* or an *array*. (See JLS 4.3.1.) All objects can be manipulated via a reference value. Only some objects can also be manipulated directly as inline values.
- A *class* describes the structure of a class instance. A *concrete class* can be *instantiated* (typically via a class instance creation expression). An *inline class* is a concrete class whose instances can be treated as inline values. An *identity class* is a concrete class whose instances support identity-sensitive behaviors, and so must always be handled via references.
- A *type* describes a set of values. An *inline type* consists of inline values, the instances of a particular inline class. A *reference type* consists of references to objects with a particular property, or the null reference. Inline types are disjoint. Reference types have subsetting relationships, captured by the *subtype* relation.
- A *type expression* is the syntax used to refer to a particular type. A class name is one example of a type expression, with a variety of rules used to map this name to specific type. The type expression 'ClassName' often denotes a reference type, but for some inline classes denotes its inline type. The type expression 'ClassName.ref' denotes the reference type of an inline class, and the type expression 'ClassName.val' denotes the inline type of an inline class. (Whether these decorations are allowed redundantly is TBD.)
Where did the primitives go? Primitive values are inline values—specifically, instances of certain inline classes (hopefully the class java.lang.Integer, etc., if we can make the migration work). Primitive types are inline types (e.g., 'int' is shorthand for 'java.lang.Integer.val').
A few things that still make me a bit uneasy, maybe could use more noodling:
- "Inline value" vs. "reference value" makes sense. Then re-using "inline" for "inline class" vs. "identity class" is potentially confusing. In this context, we're using "inline" as shorthand for "inline-capable" and "identity-free". It would sort of be nice if we could flip the world and make 'identity' the class declaration keyword (although we'd still need a term for the absence of that keyword).
- The syntax ".val" used to denote an "inline type" is a bit of a mismatch. Maybe we want a new syntax. Or maybe we want to rework the word "value" into the story so that "inline type" becomes "value type".
- The term "class type" now has multiple possible interpretations. I guess, unless it's qualified further, it ought to refer to all types "derived from" a particular class, including reference types, inline types, parameterized types, raw types, ... The taxonomy of types, including appropriate terms, needs to be sorted out.
- I'm ignoring generic inline classes. We're all ignoring generic inline classes. :-) Generics in the inline type world are, I think, a somewhat different beast than generics in the reference type world, because inline types are disjoint. More work to be done here.
More information about the valhalla-spec-observers