local refs
Stephen Weeks
MLton@sourcelight.com
Thu, 6 Dec 2001 15:12:50 -0800
> > I believe looking for any Thread_ primitive is a bit much, and all you
> > need to look for is Thread_switchTo or Thread_switchToCont. If those
> > are not present, then there isn't any control-flow that's not in the
> > graph. Since there is no longer anything special about
> > Thread_switchToCont, I propose to eliminate it, replacing it with
> > Thread_switchTo, and to make both (1) and (2) above only look for
> > Thread_switchTo.
>
> I think I agree with this.
I have checked this in, as you saw.
> > But (2) seems like it's OK to do no matter what. So, I guess I'm
> > saying that local-ref shouldn't turn off all optimization when it
> > determines that a program has threads/conts. It should just turn off
> > (1). Does that make sense?
>
> No, unless you're reading a lot more into (2) than I am. What makes a ref
> non-localizable is that it escapes. The current model, in a single
> threaded world, of "escape" is a ref that is used in any tuple/constructor
> construction, control transfer, or primitive that is not a Ref_deref or
> Ref_assign. In a multi-threaded world, a ref can also "escape" to the
> stack when it is copied, at a Thread_copy.
Makes sense. Actually, with my new changes, it is only
Thread_copyCurrent that can cause escapes. Hmmm ... I'm not so sure
... have a look at the only remaining use of Thread.current, which is
in thread.sml. Maybe it's OK here because the thread really is just
being paused -- there is no implicit control flow.
> Take a look at callcc3.sml. The reference rr_0 looks like it is
> localizable, but it is live accross the call to Thread_copyShrink.
> If you try to localize it, then the program doesn't terminate. So,
> if you really wanted to do (2) in a context where Thread primitives
> existed, you need to do liveness analysis of the potentially
> localizable refs, and forbid localization of any live across a block
> with a thread copy. (Note, this probably wouldn't be too bad; there
> are generally only a few localizable refs, so doing the propagation
> isn't too bad.)
Makes sense. Again, to be clear, in the new world I just checked in,
only liveness across Thread_copyCurrent matters.
I'm currently writing a note describing how I think about localRef,
multiple threads, and once-ness. I'll send it soon.