[Haskell-cafe] GHC optimisations

Stefan O'Rear stefanor at cox.net
Mon Aug 13 14:44:21 EDT 2007

On Mon, Aug 13, 2007 at 07:35:31PM +0100, Andrew Coppin wrote:
> Not related to optimisation, but... is there some switch to warn you if 
> something gets removed? (Presumably this means you forgot to export 
> something, or you haven't coded the bit that calls it yet or something.)

-fwarn-unused-binds (included in -Wall)

> (I once compiled a program that used the GHC API. The final binary was 
> several times larger than ghc.exe...)

GHC is a particularly bad case because what it does is determined by the
settings of a bunch of switches in the configuration data.  Of course,
GHC isn't smart enough to perform inter-module control flow analysis, so
even with -split-objs you'd probably still link most of GHC.

>>> I read somewhere that if one funtion returns a tuple, and the caller 
>>> immediately extracts the values from the tuple, GHC tries to optimise 
>>> away the tuple - so it's as if the function can just return multiple 
>>> values at once. Is this true? Does it apply only to tuples, or to all 
>>> types?
>> This is called the Constructed Product Return (CPR) analysis, and it
>> applies to all types with one constructor (in archaic jargon, product
>> types).
> Right. So it doesn't have to have strict fields or anything? Just has to 
> have exactly one constructor?

Yep, CPR is completely independent of strictness, however the returned
product must be *new*, since returning an old object by value risks
losing sharing (and thus creating large memory leaks).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070813/4946077a/attachment.bin

More information about the Haskell-Cafe mailing list