local refs

Stephen Weeks MLton@sourcelight.com
Thu, 6 Dec 2001 17:55:16 -0800


> > Localization rule:
> > You can localize a global ref if all uses are within a single
> > function and the start label of the function is not multi-used.
> 
> This works, but fails to localize global refs in a function that is only
> called once, but has local loop including start; e.g., this would happen
> in introduceLoops when it introduced a loop in a function with no
> arguments.  So, we would also want a multi-used on functions, where
> multi-used(f) ==> multi-used(start(f))
> but not the converse.

Agreed.

> > Ref-flattening rule:
> > You can flatten a local ref (x = Ref_ref y) if every use is of the
> > form Ref_assign (x, z) or Ref_deref x and all uses of x in a block
> > with a multi-threaded label are Ref_assigns or all are Ref_derefs.
> 
> I don't buy this at all.
> 
> L_A ()
>   y = Ref_deref x
>   case x of true => L_A | false => L_C
> L_B ()
>   Ref_assign(x, true)
>   L_B ()
> 
> Assume all lables are are multi-threaded.  This satisfies your criteria,
> but if one thread executes L_A and another thread executes L_B, then we
> won't get the desired semantics (i.e., L_A busy-waits until L_B releases
> it).

This does not satisfy my criteria as I intended them.  There are both
Ref_derefs and a Ref_assigns in multi-threaded labels.  To be clear,
the last bit of my condition is

either forall uses u in block with label l of x, 
            if l is multi-threaded, then u is Ref_assign
or forall uses u in block with label l of x, 
            if l is multi-threaded, then u is Ref_deref

I hope this is clear.

> And, on the other hand,
> 
> L_A ()
>   x = Ref_ref 10
>   Ref_assign (x, 20)
>   y = Ref_deref x
>   L_C ()
> 
> is flattenable (if stupid), even if L_A is multi-threaded.

Agreed that my condition doesn't get this.


Sorry, I've gotta take off, but I'll get to the rest of your mail
later.