Null type in Truffle
Chris Seaton
chris at chrisseaton.com
Sun Aug 4 10:55:09 PDT 2013
>
> Here is what I have tried for SQL unknown. In SQL you can have
> expressions like "42 + null" where the null doesn't really have a type, but
> the full expression is numeric type with a null value. To make this
> construct work, I created a class Unknown with no implementations.
Most of the languages have a special unknown or null or whatever object as
you describe. In Ruby I have a full Ruby object NilClass, and a tiny little
placeholder NilPlaceholder that I can statically reference, and turn into a
full Ruby object that is properly integrated into the object graph when I
want.
One thing I do in RubyTruffle that has made life a lot easier, is that the
Java value null never appears where a Ruby value might - never ever. nulls
appear in the wrong places all the time, and you don't want to have to
second guess if that is a language null, or some value that's crept in by
mistake. That's why I have my NilPlaceholder, and I actually have an assert
on all method calls that they don't return null, to check they aren't
creeping in.
When someone does something like 1 + nil in RubyTruffle it's going to use
slow path stuff - I haven't considered how to specialise an AST to handle
Fixnum + NilClass. Is that something you really need on the fast path? I'm
sure for some systems you may do, but do think about it first. If you
don't, then don't worry about it :)
Your type checks and specialisations look reasonable. I don't have a
solution for the order problem, I'm afraid, and as I said above I would
stop using null and do:
@TypeCheck
public boolean isUnknown(Object value)
{
return value instanceof MyNullPlaceholder || value instanceof
MyNull;
}
Regards,
Chris
More information about the graal-dev
mailing list