[Haskell-cafe] Re: idea for avoiding temporaries

Simon Marlow simonmarhaskell at gmail.com
Fri Mar 9 05:24:14 EST 2007

John Meacham wrote:
> it seems we can almost do this now without adding any new API calls,
> just have 'thawArray' and 'freezeArray' perform the check, and behave
> like 'unsafeThawArray' or 'unsafeFreezeArray' when they are the only
> reference. 
> The compiler may even be able to statically replace some
> calls to thawArray or freezeArray with the unsafe versions with an
> extension of the rules syntax
> {-# RULES forall a | unique a . freezeArray a = unsafeFreezeArray a #-}
> this syntax actually came up in a previous discussion about wanting to
> fire rules only when the argument is a constant literal (though, you don't
> care about the particular constant value it is)
> I imagine infering the uniqueness of values shouldn't be that hard as a
> form of it is already done for avoiding thunk-updates.

GHC doesn't have any kind of uniqueness analysis right now.  It's pretty hard to 
do in general: imagine a function that takes an array as an argument and 
delivers an array as a result.  It'll probably need two versions: one when the 
argument is unique, one for when it's not.  If you can see all the call sites 
you might be able to throw away one of these versions, but with separate 
compilation that's the uncommon case.

BTW, we don't do any update-avoidance at the moment.  The old update analyser 
was slow and didn't give any significant benefit, so we dropped it.

I think the right way forward is array fusion, which is what the NDP folks are 
working on.


More information about the Haskell-Cafe mailing list