patch applied (ghc): Improve the treatment of 'seq' (Trac #2273)
Isaac Dupree
isaacdupree at charter.net
Fri May 16 20:11:11 EDT 2008
Is there any particular reason to use let vs. case e.g.
case e of !x -> ... x ...
? As far as I can tell, the main difference is the layout rule affecting
following code...
the point being that you don't want those thunks floating around being
used, and strict-binding makes it obvious to the compiler that you have
no reason to duplicate that computation no matter how simple it is? Oh,
actually the point *is* that we *must not* duplicate it. And the
compiler never does, for the let! form, for some reason?
can the idiom work with deeper seq'ing (seqList, deepSeq and such) --
can those functions be written robustly too?
-Isaac
Don Stewart wrote:
> So would you say this affects our standard idiom for strictifying things.
> The
>
> let !x = e in ... x ...
>
> form should be used now, for robustness reasons.
>
> -- Don
>
> simonpj:
>> Yes that's right. I've realised that to be fully robust you should really say
>>
>> let !x2 = x in ...x2...
>>
>> rather than
>>
>> x `seq` ...x....
>>
>> With the latter, if you have
>> let x = e
>> enclosing, then substituting e for x can defeat the seq. And what humans can do, compilers may too!
>>
>> The former doesn't let you do this.
>> Simon
>>
>> | -----Original Message-----
>> | From: Don Stewart [mailto:dons at galois.com]
>> | Sent: 16 May 2008 16:49
>> | To: Simon Peyton-Jones
>> | Cc: cvs-ghc at haskell.org
>> | Subject: Re: patch applied (ghc): Improve the treatment of 'seq' (Trac #2273)
>> |
>> | simonpj:
>> | > Fri May 16 01:51:49 PDT 2008 simonpj at microsoft.com
>> | > * Improve the treatment of 'seq' (Trac #2273)
>> | >
>> | > Trac #2273 showed a case in which 'seq' didn't cure the space leak
>> | > it was supposed to. This patch does two things to help
>> | >
>> | > a) It removes a now-redundant special case in Simplify, which
>> | > switched off the case-binder-swap in the early stages. This
>> | > isn't necessary any more because FloatOut has improved since
>> | > the Simplify code was written. And switching off the binder-swap
>> | > is harmful for seq.
>> | >
>> | > However fix (a) is a bit fragile, so I did (b) too:
>> | >
>> | > b) Desugar 'seq' specially. See Note [Desugaring seq (2)] in DsUtils
>> | > This isn't very robust either, since it's defeated by abstraction,
>> | > but that's not something GHC can fix; the programmer should use
>> | > a let! instead.
>> | >
>> | >
>> |
>> | By let! do you mean
>> |
>> | let !x = ...
>> |
>> | ?
>> |
>> | -- Don
>>
>
> _______________________________________________
> Cvs-ghc mailing list
> Cvs-ghc at haskell.org
> http://www.haskell.org/mailman/listinfo/cvs-ghc
>
More information about the Cvs-ghc
mailing list