Changes between Version 29 and Version 30 of Commentary/Libraries


Ignore:
Timestamp:
Dec 6, 2010 11:14:28 PM (3 years ago)
Author:
ezyang
Comment:

Add note about avoiding references to exception code

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Libraries

    v29 v30  
    133133The `haskell98`, `old-time` and `random` packages are mostly only needed for Haskell 98 support, although `dph` currently uses `random` too. 
    134134 
     135Note that `ghc-prim` and `integer-impl` are below the dependency chain from Exception (in `base`), which means they must not raise generate code to raise an exception (it's not enough that this code will never run). One particularly subtle case of GHC exception-raising code is in the case of (complete!) pattern matches. Consider the unboxed form of Integers, which has the constructor S# or J#. 
    135136 
     137{{{ 
     138f (S# _) (S# _) = ... 
     139f x (S# _) = ... 
     140f (S# _) y = ... 
     141f (J# _ _) (J# _ _) = ... 
     142}}} 
     143 
     144GHC will incorrectly generate core that pattern matches against the second argument twice, the second match being a partial one with (dead) exception raising code. When compiled with optimizations, the dead code is eliminated. However, this breaks with -O0, so the fix was to explicitly spell out the constructor in the second and third line: 
     145 
     146{{{ 
     147f (S# _) (S# _) = ... 
     148f (J# _ _) (S# _) = ... 
     149f (S# _) (J# _ _) = ... 
     150f (J# _ _) (J# _ _) = ... 
     151}}}