Hyphenated Keywords and Unsigned Primitive Types

Jacob Glickman jhg023 at bucknell.edu
Mon Jan 14 21:44:58 UTC 2019


I appreciate the feedback!

It sounds like implementing those types as library classes will be much
less work than having to modify the JVM to add new bytecodes (not counting
all of the work that has gone towards Valhalla thus far).

The next logical step that comes to mind would be to provide a mechanism to
define operators for these library classes (unless they'll be handled
under-the-hood like they currently are for the primitive wrapper classes).

- Jacob Glickman

On Mon, Jan 14, 2019 at 11:17 AM Brian Goetz <brian.goetz at oracle.com> wrote:

> Yes, many people would be thrilled to see the addition of unsigned
> primitives.  (And the ML community would be thrilled to see half-floats,
> and the vector folks would love to see 128/256/512-bit "superlongs").
>
> Unfortunately, it is not the lack of a surface syntax that is the
> primary impediment to adding new primitives; it's the JVM type system
> itself.  The JVM provides the same eight primitive types as the Java
> language, as well as reference types.  So, what would we translate them
> to?  If we erase them to int, we have a problem; you couldn't overload
>
>      m(int x) { }
>      m(unsigned int x) { }
>
> because they'd have the same VM type signature.  "Language fictions"
> like this are sometimes a good move, but I suspect that this would only
> make people happy in the short term, and lead to confusion and
> complexity the day after that.  And if we translate them to references,
> we have the performance problem that everything is boxed.
>
> If you look at the bytecode set:
>
>      https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings
>
> You'll see that many bytecodes are dedicated to primitive type
> operations (iadd, iload, dmul, dload, etc).  And there's not room to add
> the bytecodes we'd need for all the new primitive types.
>
> This problem is one of the motivations for doing Valhalla -- to allow
> new types to be written that have the runtime behavior of primitives,
> but the user-definability of classes.  Valhalla is a very deep cut --
> all the way down to the metal -- but by the time we're done, we'll be
> able to write unsigned int (and others) as library classes (with a
> sprinkling of intrinsification for arithmetic.)
>
>
> On 1/13/2019 8:27 PM, Jacob Glickman wrote:
> > Just throwing in my two cents on Brian's recent proposal regarding
> > hyphenated keywords.
> >
> > I think their addition to the language would be a great idea, and I'd
> like
> > to use this opportunity to revive discussion regarding unsigned primitive
> > types in Java, as I think hyphenated keywords would suit them perfectly:
> >
> > `unsigned-int`, `unsigned-long`, etc.
> >
> > I'm curious if anything else has changed since the last time unsigned
> > primitive types were discussed that would warrant their addition to the
> > language.
> >
> > - Jacob Glickman
>
>


More information about the amber-dev mailing list