On 03/06/2015 23:19, Marvin Humphrey wrote:
*   MAYBE types are typedef'd to `size_t`.  (This can encode enough bits to
     hold pointers and primitive types narrower than a pointer.  MAYBE types
     for wider primitives will need to be implemented as structs.)
*   The low bit is set to 1 to indicate success and 0 for failure.
*   Access to the MAYBE type is funneled through subroutines.

Unlike the previous proof-of-concept code which inspects the class pointer,
using the low bit as a type tag allows us to differentiate between an error
condition and a deliberate Err* return value.

I like the idea of using tagged pointers but I'd still prefer a union for "MAYBE" types to improve type safety. If every "MAYBE" type is a size_t (or uintptr_t), they can be used interchangeably and the compiler won't complain about assigning a MAYBEHash to a MAYBEVector, for example.

The reason this approach is incompatible with the MRI Ruby runtime is that
MRI's conservative GC scans the C stack looking for Ruby object pointers, and
setting the low bit would hide them from it.  However, if we only manipulate
MAYBE types through subroutines, they could be two-slot structs under some
hosts (such as Ruby) and integers under others.

But we don't set the low bit on the Ruby object pointer (VALUE). Pointers to Clownfish objects will probably end up in the `data` field of struct RData. Ruby shouldn't care about the contents of this field.

Nick

Reply via email to