cvs commit: fptools/ghc/compiler/coreSyn CoreUtils.lhs

Simon Peyton Jones simonpj@glass.cse.ogi.edu
Mon, 5 Mar 2001 07:37:25 -0800


simonpj     2001/03/05 07:37:25 PST

  Modified files:
    ghc/compiler/coreSyn CoreUtils.lhs 
  Log:
  	Exploit the 1-shot lambda HACK in etaExpandArity
  
  We often find code like
  
  	f :: Int -> IO ()
  	f = \ x -> case ... of
  			p1 -> \s -> ...rhs1...
  			p2 -> \s -> ...rhs2...
  
  where the \s is a state transformer lambda.  Almost invariably
  these \s things are one-shot; that is, we virtually never say
  
  	let
  	   h = f 3
  	in
  	h >> h >> h
  
  In this case we'd be much better off eta-expanding f, to
  
  	f :: Int -> IO ()
  	f = \ x \ s -> case ... of
  			   p1 -> ...rhs1...
  			   p2 -> ...rhs2...
  
  GHC already has a MAJOR HACK in
  
  	Id.isOneShotLambda
  
  which declares that any \s::State# T is a one-shot lambda.  It's
  almost always true, and it makes a big difference.
  
  This commit simply makes use of isOneShotLambda to improve the
  results of CoreUtils.etaExpandArity.  Which has the desired effect.
  
  There isn't a flag to control the MAJOR HACK yet.  Maybe there should be.
  
  Anyway, some of Manuel's array code should improve a lot.
  
  Revision  Changes    Path
  1.68      +44 -15    fptools/ghc/compiler/coreSyn/CoreUtils.lhs