Null type in Truffle
Christian Humer
christian.humer at gmail.com
Sun Aug 4 11:08:53 PDT 2013
Hi Dain,
The DSL implementation has to order specializations somehow if they cannot
be ordered by the type order of the type system. It should be sufficient to
order just the ambiguous specializations. Sadly the Eclipse-Java-Compiler
(ECJ) is preventing me from using the declaration order. I hope I am able
to remove that annoying attribute soon. (It is also really annoying for us,
please vote for the eclipse bug [1] )
In our current languages we tried to avoid using null as a value. Instead
we use singleton values which do not make a difference performance-wise.
This enabled us to use null otherwise, for instance to represent holes in
sparse arrays.
@TypeCheck public boolean isUnknown(Object value) {
return value == Unknown.instance;
}
Your specialization unknownAndUnknown in this order is unreachable (which
is actually a bug that it does not tell you so). It would be reachable if
it would be ordered first. This can be used as a general rule. More
specific specializations should be ordered first. This is what the DSL
tries to do if the order is not defined manually.
[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408
- Christian Humer
- Christian Humer
On Sat, Aug 3, 2013 at 11:26 PM, Dain Sundstrom <dain at iq80.com> wrote:
> Another long question :)
>
> How do I add a null type into the type system (e.g., Ruby nil, Python
> none, or SQL unknown)?
>
> 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. I added
> Unknown as the first element in @TypeSystem. Then I was forced to add a
> @TypeCheck:
>
> @TypeCheck
> public boolean isUnknown(Object value)
> {
> return value == null;
> }
>
> Then added this method to my base ExpressionNode:
>
>
> public Unknown executeUnknown(VirtualFrame frame)
> throws UnexpectedResultException
> {
> return SqlTypesGen.SQLTYPES.expectUnknown(execute(frame));
> }
>
> I added a UnknownLiteral node:
>
> public static class UnknownLiteral
> extends LiteralNode
> {
> public Unknown execute(VirtualFrame frame)
> {
> return null;
> }
> }
>
> And finally I added these methods to my BinaryNode:
>
> @Specialization(order = 100)
> public Unknown unknownAndAnything(Unknown left, Object right)
> {
> return null;
> }
>
> @Specialization(order = 101)
> public Unknown anythingAndUnknown(Object left, Unknown right)
> {
> return null;
> }
>
> @Specialization(order = 102)
> public Unknown unknownAndUnknown(Unknown left, Unknown right)
> {
> return null;
> }
>
> The order parameter is there because the DSL is now forcing met to add
> order to all of my methods like this in my Add node:
>
> @Specialization(order = 1, rewriteOn = ArithmeticException.class)
> public long addLong(long left, long right)
> {
> return ExactMath.addExact(left, right);
> }
>
> In general, the isUnknown() type check method doesn't seem right, and the
> order declaration is really annoying. Is there an easier way?
>
> -dain
>
>
>
>
More information about the graal-dev
mailing list