[Haskell-cafe] Preventing sharing

David Turner dct25-561bs at mythic-beasts.com
Fri Dec 18 18:43:10 UTC 2015


Well at least I hadn't overlooked something obvious!

Some combination of dummy arguments, NOINLINE and -fno-full-laziness did
indeed prevent it from sharing but this definitely seemed unsatisfactory.
Particularly that -fno-full-laziness applies to the whole module which
feels a bit heavyweight.

How feasible would it be to add another pragma like NOINLINE that prevented
exactly this? Is it actually important? This is a toy example of course and
I've not come across this kind of problem in any real code - has anyone



On 18 December 2015 at 14:36, Joachim Breitner <mail at joachim-breitner.de>

> Hi,
> Am Freitag, den 18.12.2015, 09:40 +0000 schrieb David Turner:
> > Now I'm a bit stuck: how do you prevent this from happening?
> > Obviously here we could just implement fibs differently, but as a
> > more general question, how would you prevent unwanted sharing from
> > taking place?
> floating out (and, relatedly, CSE) is tricky to get a good grip on, and
> I wish there were good and easy solutions. This also comes up with
> things like "zip xs [0..]" and gets in the way of applying rules.
> Note that in your example, depending on the use case, maybe the
> programmer did want to share the fibs list. So it is not clear that the
> compiler can always do the right thing.
> You can pass -fno-full-laziness to GHC (and you can do that with a per-
> module pragma), this might work in your case, but you better check.
> Another trick is to add an argument to fibs, e.g. the initial starting
> values
> fib n = fibs 0 1 !! n
>   where
>    fibs a b = go where go = a : b : zipWith (+) go (tail go)
>    {-# NOINLINE fibs #-}
> The noinline pragma might be required as otherwise GHC will simplify
> the code again to your origin form, and then share the go with a and be
> specialized to 0 and 1. Again, check the core if it indeed does what
> you want.
> Both approaches are unsatisfying.
> Greetings,
> Joachim
> --
> Joachim “nomeata” Breitner
>   mail at joachim-breitner.dehttp://www.joachim-breitner.de/
>   Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
>   Debian Developer: nomeata at debian.org
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151218/ec25e459/attachment.html>

More information about the Haskell-Cafe mailing list