[bitc-dev] Reference struccture and union types

Jonathan S. Shapiro shap at eros-os.org
Wed Jul 26 17:49:02 EDT 2006


On Wed, 2006-07-26 at 17:35 -0400, Swaroop Sridhar wrote:
> If we have a structure or union of reference type,
> 
> ex: (defunion (list 'a) nil (cons car:'a cdr:(list 'a))
> 
> does this mean that:
> i) We have a union list of reference type that can never be unboxed 
> (like vectors, which can never be unboxed).  or,

I am not sure which question you are asking.

The reference type *can* be unboxed in the context of an expression.
That is, the following is legal:

  (let ((ll nil:(list char)))
    (dup (deref ll)))

However, there is no type constructor for constructing the corresponding
value type. This means that you cannot declare a field, variable, or
parameter to be of type "unboxed list".

As I write this, it occurs to me that there is a problem with this,
because it is possible to write something like:

  (lambda (x:'a)
    (let ((ll nil:(list char)))
      (dup (deref ll):'a)))

so I think we screwed up here.

The intention of DEREF was caching of locations. For example, if 'v' is
a variable of some value type, it is perfectly sensible to write

	(deref (dup v))

and even to write

   (let ((heap-v-copy (deref (dup v))))
     ...)

I have not looked at the language reference to determine what
restrictions apply to DEREF. At the moment, I'm not convinced that DEREF
is correctly specified.

> ii) The reference type can be unboxed and the above definition is a 
> shorthand for:
> 
> (defunion (list 'a):val nil (cons car:'a cdr:(ref (list 'a)))
> along with the understanding that the constructor will implicitly `dup' 
> the constructed value?

I'm not sure. I need to think about this.

> (i) is similar to ML version of records and variants, and this case is 
> easy to handle.
> 
> If we mean (ii), what we are actually saying is that there is a 
> (automatically defined) value type corresponding to every reference type.

At the level of back-end code emission this is certainly true, but as I
said above, I need to think about what was intended here.

> The decision of whether we pick choice (i) or (ii) above also affects 
> whether reference structure /union types can be used in places expecting 
> a (ref 'a) type.

Yes, I see the problem.


shap



More information about the bitc-dev mailing list