[M3devel] small objects

Rodney M. Bates rodney.m.bates at cox.net
Mon Apr 6 03:45:15 CEST 2009


I spent quite a bit of time playing with a more general system where
there is a set of "tagged" types, with (an implementation-defined
subrange of) INTEGER and a reference type both being a subtype of a
tagged type.  It might have been tolerable, if it weren't for the
interaction with object subtypes and opaque types, which quickly
gets deep into a deep linguistic tar pit.

Tony's approach is much simpler and would serve what I see as the
need.  It does sacrifice any static checking of what reference type
is being tagged, and will also require an extra runtime ISTYPE/TYPECASE.

Would INTEGER and REFANY be assignable to TAGGED, or would there
also need to be an explicit conversion in that direction too, say
VAL(x, TAGGED)?  I think I favor the explicit conversion here.  It
is a bit inconsistent with the usual Modula-3 assignability philosophy,
but not requiring the explicit conversion already gets your toes into tar.

We would have to have something more like ISTYPE, though, which will
tell which type the value belongs to without risking a runtime error,
which VAL would do.

An intermediate approach might be to have a set of tagged types
constructed by, say, TAGGED T, where I is a reference type, but
with no subtype relations on them at all, thus still requiring
the explicit conversions and checks.

I do want to say, I _really_ want this capability somehow.  I have
an ADT module whose internal data structure, for full generality,
needs to have two heap objects (the second because it has nonstatic
size) and 11 total words counting the orginal pointer, in the case of
values that would fit directly  into the "pointer" word.  Moreover,
these small cases are in the great majority.

Besides the 11-to-one increase in actual occupied space, there
is extra time for allocation, periodic tracing, and collection, space
loss due to heap fragmentation, and time/space tradeoff loss due to
reduced locality of reference.  So sometimes, it would be a big
performance gain if we could do it.


Tony Hosking wrote:
> It is a much more pervasive hack than I would be comfortable with
> since it touches on the compiler (for all the type operations) as well
> as the run-time system in ways that are pretty gross.  I would much
> rather have a new TAGGED builtin.  ISTYPE would not work on it since
> that only works on references.  The only thing you need is a way to
> extract the value -- we could overload VAL(x, T) where x can be a
> TAGGED and T can be REFANY or INTEGER.
> 
>



More information about the M3devel mailing list