#2325: Compile-time computations
--------------------------------------+-------------------------------------
 Reporter:  ajd                       |          Owner:             
     Type:  run-time performance bug  |         Status:  new        
 Priority:  normal                    |      Milestone:  6.10 branch
Component:  Compiler                  |        Version:  6.8.2      
 Severity:  normal                    |     Resolution:             
 Keywords:  constant folding          |     Difficulty:  Unknown    
 Testcase:                            |   Architecture:  Unknown    
       Os:  Unknown                   |  
--------------------------------------+-------------------------------------
Comment (by simonpj):

 I don't think so.  Here's the `Num` instance for `Integer`:
 {{{
 instance Num Integer where
   fromInteger x = x
 }}}
 The argument to `fromInteger` is, well, an `Integer`.  So the desugarer
 converts `3` to `smallInteger 3#`, where `3# :: Int#`.  For bigger
 integers (and the desugarer must make a conservative (wrt word size)
 estimate of what "big" is), it converts `779988998` into
 {{{
   (smallInteger 7799# `timesInteger` smallInteger 100000#)
      `plusInteger` smallInteger 88998
 }}}
 or whatever.  The function `smallInteger` comes from library `GHC.Integer`
 in packages `integer`.

 Hmm.   I suppose that we could use the `BuiltInRule` method thus
 {{{
    smallInteger a `plusInteger` smallInteger b = smallInteger (a + #b)
        if (a +# b) is not "big"
 }}}
 using the same conservative estimate for "big" that the desugarer does.
 (A `BuiltInRule` can have a side condition such as the one above.)

 To do that we'd have to ensure that `smallInteger` wasn't inlined too
 early...and we'd sadly miss any opportunities that arose after it was
 inlined.

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2325#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to