Optimizations for mutable structures?

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Dec 7 12:36:09 EST 2005


[previously sent by mistake to Simon only - new para at end]

"Simon Marlow" <simonmar at microsoft.com> writes:

> Now, take the original program, but change the creation of m2 to
> "newMVar ()", i.e. m2 starts off full.  Is the transformation valid now?
> Well maybe, because in some interleavings acts does not block, and we
> can prove that at compilation time.

I don't think it is valid for a compiler to say that "one possible
execution path permits me to remove some code, therefore I will remove
that code on all possible execution paths".

The example I had in mind was a GUI where the action
          writeIORef r e >> acts >> readIORef r
is intended to capture a situation where first we record some global
configuration data for the application, then permit some arbitrary GUI
actions to occur, and then we retrieve the configuration data again.

My expectation is that the config data /will/ have been changed by
some other GUI thread.  Surely it cannot be OK for the compiler to
silently deliver the original unchanged data here - it goes against
the programmer's intention.

Surely, if a Haskell programmer is going to write code that explicitly
reads from a reference after writing to it, that sequence must 9/10
be intentional: otherwise wouldn't she have just used a let-binding?

Regards,
    Malcolm


More information about the Glasgow-haskell-users mailing list