Unexpected boxing in generated code
ndmitchell at gmail.com
Tue Aug 7 13:36:14 EDT 2007
> OK this is an interesting one. Here's the smallest program that demonstrates the problem.
> foreign import ccall unsafe "stdio.h getchar" getchar :: IO CInt
> f56 :: State# RealWorld -> Int -> Int
> f56 s v2 = case (unIO getchar s) of
> (# s' , v6 #) ->
> case v2 of I# _ -> f56 s' v2
> GHC says this is lazy in v2, which it obviously isn't. Why? Because there's a special
> hack (introduced after an earlier bug report) in the strictness analyser to account for the
> fact that a ccall might exit the program. Suppose instead of calling 'getchar' we called
> 'exit'! Then f56 is not strict in v2 any more.
> One could imagine an analysis for "definitely does not exit". But it only really
> makes sense for IO-ish things.
Why not demand that all unsafe foreign imports do not exit the
program? If your foreign call does exit the program, then its unlikely
to be performance critical. All unsafe FFI functions can then have
their strictness analysed as before.
More information about the Glasgow-haskell-users